Skip to content

Commit a862fa0

Browse files
committed
Support for GlassEffect
1 parent f0b00e2 commit a862fa0

4 files changed

Lines changed: 84 additions & 50 deletions

File tree

Example/Sources/InputBar Examples/GlassInputBar.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,34 @@ final class GlassInputBar: InputBarAccessoryView {
2424
backgroundColor = nil
2525
separatorLine.isHidden = true
2626
if #available(iOS 26.0, *) {
27-
backgroundView.effect = UIGlassContainerEffect()
27+
let container = UIGlassContainerEffect()
28+
container.spacing = 8
29+
containerContentView.effect = container
2830
backgroundView.backgroundColor = nil
2931

32+
middleContentViewPadding.left = 8
33+
middleContentViewPadding.right = 8
34+
3035
let effect = UIGlassEffect(style: .regular)
3136
effect.isInteractive = true
32-
contentView.cornerConfiguration = .capsule()
33-
contentView.effect = effect
37+
middleContentViewWrapper.cornerConfiguration = .capsule(maximumRadius: 20)
38+
middleContentViewWrapper.effect = effect
39+
40+
leftContentView.cornerConfiguration = .capsule(maximumRadius: 20)
41+
leftContentView.effect = effect
42+
43+
rightContentView.cornerConfiguration = .capsule(maximumRadius: 20)
44+
rightContentView.effect = effect
3445
}
3546

36-
47+
let button = InputBarButtonItem()
48+
button.setSize(CGSize(width: 36, height: 36), animated: false)
49+
button.setImage(#imageLiteral(resourceName: "ic_plus").withRenderingMode(.alwaysTemplate), for: .normal)
50+
button.imageView?.contentMode = .scaleAspectFit
51+
button.tintColor = .systemBlue
52+
53+
setLeftStackViewWidthConstant(to: 36, animated: false)
54+
setStackViewItems([button], forStack: .left, animated: false)
3755
}
3856
}
3957

Example/Sources/InputBar Examples/iMessageInputBar.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ final class iMessageInputBar: InputBarAccessoryView {
2121
}
2222

2323
func configure() {
24+
backgroundColor = nil
25+
backgroundView.backgroundColor = nil
2426
inputTextView.textContainerInset = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 36)
2527
inputTextView.placeholderLabelInsets = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 36)
2628
if #available(iOS 13, *) {
@@ -43,7 +45,7 @@ final class iMessageInputBar: InputBarAccessoryView {
4345
sendButton.backgroundColor = .clear
4446
middleContentViewPadding.right = -38
4547
separatorLine.isHidden = true
46-
backgroundView.effect = UIBlurEffect(style: .systemMaterial)
48+
containerContentView.effect = UIBlurEffect(style: .systemUltraThinMaterial)
4749
}
4850

4951
}

Sources/InputBarAccessoryView.swift

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ open class InputBarAccessoryView: UIView {
3737

3838
/// The background UIView anchored to the bottom, left, and right of the InputBarAccessoryView
3939
/// with a top anchor equal to the bottom of the top InputStackView
40-
open var backgroundView: UIVisualEffectView = {
41-
let view = UIVisualEffectView()
40+
open var backgroundView: UIView = {
41+
let view = UIView()
4242
view.translatesAutoresizingMaskIntoConstraints = false
4343
view.backgroundColor = InputBarAccessoryView.defaultBackgroundColor
4444
return view
4545
}()
4646

47+
open var containerContentView: UIVisualEffectView = {
48+
let view = UIVisualEffectView()
49+
view.translatesAutoresizingMaskIntoConstraints = false
50+
return view
51+
}()
52+
4753
/// A content UIView that holds the left/right/bottom InputStackViews
4854
/// and the middleContentView. Anchored to the bottom of the
4955
/// topStackView and inset by the padding UIEdgeInsets
@@ -76,6 +82,11 @@ open class InputBarAccessoryView: UIView {
7682
1. It's axis is initially set to .horizontal
7783
*/
7884
public let leftStackView = InputStackView(axis: .horizontal, spacing: 0)
85+
public let leftContentView: UIVisualEffectView = {
86+
let view = UIVisualEffectView()
87+
view.translatesAutoresizingMaskIntoConstraints = false
88+
return view
89+
}()
7990

8091
/**
8192
The InputStackView at the InputStackView.right position
@@ -84,6 +95,11 @@ open class InputBarAccessoryView: UIView {
8495
1. It's axis is initially set to .horizontal
8596
*/
8697
public let rightStackView = InputStackView(axis: .horizontal, spacing: 0)
98+
public let rightContentView: UIVisualEffectView = {
99+
let view = UIVisualEffectView()
100+
view.translatesAutoresizingMaskIntoConstraints = false
101+
return view
102+
}()
87103

88104
/**
89105
The InputStackView at the InputStackView.bottom position
@@ -107,8 +123,8 @@ open class InputBarAccessoryView: UIView {
107123
public private(set) weak var middleContentView: UIView?
108124

109125
/// A view to wrap the `middleContentView` inside
110-
private let middleContentViewWrapper: UIView = {
111-
let view = UIView()
126+
public let middleContentViewWrapper: UIVisualEffectView = {
127+
let view = UIVisualEffectView()
112128
view.translatesAutoresizingMaskIntoConstraints = false
113129
return view
114130
}()
@@ -403,13 +419,16 @@ open class InputBarAccessoryView: UIView {
403419

404420
addSubview(backgroundView)
405421
addSubview(topStackView)
406-
addSubview(contentView)
422+
addSubview(containerContentView)
423+
containerContentView.contentView.addSubview(contentView)
407424
addSubview(separatorLine)
408-
contentView.addSubview(middleContentViewWrapper)
409-
contentView.addSubview(leftStackView)
410-
contentView.addSubview(rightStackView)
411-
contentView.addSubview(bottomStackView)
412-
middleContentViewWrapper.addSubview(inputTextView)
425+
contentView.contentView.addSubview(middleContentViewWrapper)
426+
contentView.contentView.addSubview(leftContentView)
427+
leftContentView.contentView.addSubview(leftStackView)
428+
contentView.contentView.addSubview(rightContentView)
429+
rightContentView.contentView.addSubview(rightStackView)
430+
contentView.contentView.addSubview(bottomStackView)
431+
middleContentViewWrapper.contentView.addSubview(inputTextView)
413432
middleContentView = inputTextView
414433
setStackViewItems([sendButton], forStack: .right, animated: false)
415434
}
@@ -429,49 +448,52 @@ open class InputBarAccessoryView: UIView {
429448

430449
topStackViewLayoutSet = NSLayoutConstraintSet(
431450
top: topStackView.topAnchor.constraint(equalTo: topAnchor, constant: topStackViewPadding.top),
432-
bottom: topStackView.bottomAnchor.constraint(equalTo: contentView.topAnchor, constant: -padding.top),
451+
bottom: topStackView.bottomAnchor.constraint(equalTo: containerContentView.topAnchor, constant: -padding.top),
433452
left: topStackView.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor, constant: topStackViewPadding.left + frameInsets.left),
434453
right: topStackView.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor, constant: -(topStackViewPadding.right + frameInsets.right))
435454
)
436455

456+
contentView.fillSuperview()
437457
contentViewLayoutSet = NSLayoutConstraintSet(
438-
top: contentView.topAnchor.constraint(equalTo: topStackView.bottomAnchor, constant: padding.top),
439-
bottom: contentView.bottomAnchor.constraint(lessThanOrEqualTo: safeAreaLayoutGuide.bottomAnchor, constant: -padding.bottom),
440-
left: contentView.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor, constant: padding.left + frameInsets.left),
441-
right: contentView.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor, constant: -(padding.right + frameInsets.right))
458+
top: containerContentView.topAnchor.constraint(equalTo: topStackView.bottomAnchor, constant: padding.top),
459+
bottom: containerContentView.bottomAnchor.constraint(lessThanOrEqualTo: safeAreaLayoutGuide.bottomAnchor, constant: -padding.bottom),
460+
left: containerContentView.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor, constant: padding.left + frameInsets.left),
461+
right: containerContentView.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor, constant: -(padding.right + frameInsets.right))
442462
)
443463

444464
// Constraints Within the contentView
445465
middleContentViewLayoutSet = NSLayoutConstraintSet(
446-
top: middleContentViewWrapper.topAnchor.constraint(equalTo: contentView.topAnchor, constant: middleContentViewPadding.top),
466+
top: middleContentViewWrapper.topAnchor.constraint(equalTo: containerContentView.topAnchor, constant: middleContentViewPadding.top),
447467
bottom: middleContentViewWrapper.bottomAnchor.constraint(equalTo: bottomStackView.topAnchor, constant: -middleContentViewPadding.bottom),
448-
left: middleContentViewWrapper.leftAnchor.constraint(equalTo: leftStackView.rightAnchor, constant: middleContentViewPadding.left),
449-
right: middleContentViewWrapper.rightAnchor.constraint(equalTo: rightStackView.leftAnchor, constant: -middleContentViewPadding.right)
468+
left: middleContentViewWrapper.leftAnchor.constraint(equalTo: leftContentView.rightAnchor, constant: middleContentViewPadding.left),
469+
right: middleContentViewWrapper.rightAnchor.constraint(equalTo: rightContentView.leftAnchor, constant: -middleContentViewPadding.right)
450470
)
451471

452472
inputTextView.fillSuperview()
453473
maxTextViewHeight = calculateMaxTextViewHeight()
454474
textViewHeightAnchor = inputTextView.heightAnchor.constraint(equalToConstant: maxTextViewHeight)
455475

476+
leftStackView.fillSuperview()
456477
leftStackViewLayoutSet = NSLayoutConstraintSet(
457-
top: leftStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0),
458-
bottom: leftStackView.bottomAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: 0),
459-
left: leftStackView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0),
460-
width: leftStackView.widthAnchor.constraint(equalToConstant: leftStackViewWidthConstant)
478+
top: leftContentView.topAnchor.constraint(greaterThanOrEqualTo: containerContentView.topAnchor, constant: 0),
479+
bottom: leftContentView.bottomAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: 0),
480+
left: leftContentView.leftAnchor.constraint(equalTo: containerContentView.leftAnchor, constant: 0),
481+
width: leftContentView.widthAnchor.constraint(equalToConstant: leftStackViewWidthConstant)
461482
)
462483

484+
rightStackView.fillSuperview()
463485
rightStackViewLayoutSet = NSLayoutConstraintSet(
464-
top: rightStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 0),
465-
bottom: rightStackView.bottomAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: 0),
466-
right: rightStackView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: 0),
467-
width: rightStackView.widthAnchor.constraint(equalToConstant: rightStackViewWidthConstant)
486+
top: rightContentView.topAnchor.constraint(greaterThanOrEqualTo: containerContentView.topAnchor, constant: 0),
487+
bottom: rightContentView.bottomAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: 0),
488+
right: rightContentView.rightAnchor.constraint(equalTo: containerContentView.rightAnchor, constant: 0),
489+
width: rightContentView.widthAnchor.constraint(equalToConstant: rightStackViewWidthConstant)
468490
)
469491

470492
bottomStackViewLayoutSet = NSLayoutConstraintSet(
471493
top: bottomStackView.topAnchor.constraint(equalTo: middleContentViewWrapper.bottomAnchor, constant: middleContentViewPadding.bottom),
472-
bottom: bottomStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: 0),
473-
left: bottomStackView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0),
474-
right: bottomStackView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: 0)
494+
bottom: bottomStackView.bottomAnchor.constraint(equalTo: containerContentView.bottomAnchor, constant: 0),
495+
left: bottomStackView.leftAnchor.constraint(equalTo: containerContentView.leftAnchor, constant: 0),
496+
right: bottomStackView.rightAnchor.constraint(equalTo: containerContentView.rightAnchor, constant: 0)
475497
)
476498
}
477499

@@ -482,7 +504,7 @@ open class InputBarAccessoryView: UIView {
482504
private func setupConstraints(to window: UIWindow?) {
483505
guard let window = window, window.safeAreaInsets.bottom > 0 else { return }
484506
windowAnchor?.isActive = false
485-
windowAnchor = contentView.bottomAnchor.constraint(lessThanOrEqualToSystemSpacingBelow: window.safeAreaLayoutGuide.bottomAnchor, multiplier: 1)
507+
windowAnchor = containerContentView.bottomAnchor.constraint(lessThanOrEqualToSystemSpacingBelow: window.safeAreaLayoutGuide.bottomAnchor, multiplier: 1)
486508
windowAnchor?.constant = -padding.bottom
487509
windowAnchor?.priority = UILayoutPriority(rawValue: 750)
488510
windowAnchor?.isActive = true
@@ -604,11 +626,11 @@ open class InputBarAccessoryView: UIView {
604626
for position in positions {
605627
switch position {
606628
case .left:
607-
leftStackView.setNeedsLayout()
608-
leftStackView.layoutIfNeeded()
629+
leftContentView.setNeedsLayout()
630+
leftContentView.layoutIfNeeded()
609631
case .right:
610-
rightStackView.setNeedsLayout()
611-
rightStackView.layoutIfNeeded()
632+
rightContentView.setNeedsLayout()
633+
rightContentView.layoutIfNeeded()
612634
case .bottom:
613635
bottomStackView.setNeedsLayout()
614636
bottomStackView.layoutIfNeeded()
@@ -671,7 +693,7 @@ open class InputBarAccessoryView: UIView {
671693
middleContentView?.removeFromSuperview()
672694
middleContentView = view
673695
guard let view = view else { return }
674-
middleContentViewWrapper.addSubview(view)
696+
middleContentViewWrapper.contentView.addSubview(view)
675697
view.fillSuperview()
676698

677699
performLayout(animated) { [weak self] in
@@ -710,7 +732,7 @@ open class InputBarAccessoryView: UIView {
710732
}
711733
}
712734
guard superview != nil else { return }
713-
leftStackView.layoutIfNeeded()
735+
leftContentView.layoutIfNeeded()
714736
case .right:
715737
rightStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
716738
rightStackViewItems = items
@@ -722,7 +744,7 @@ open class InputBarAccessoryView: UIView {
722744
}
723745
}
724746
guard superview != nil else { return }
725-
rightStackView.layoutIfNeeded()
747+
rightContentView.layoutIfNeeded()
726748
case .bottom:
727749
bottomStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
728750
bottomStackViewItems = items

Sources/Views/InputStackViewContainer.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)