Skip to content

Commit

Permalink
control omnibar padding from the swipe controller
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Feb 1, 2024
1 parent a83f693 commit a94198c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
18 changes: 4 additions & 14 deletions DuckDuckGo/OmniBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class OmniBar: UIView {

weak var omniDelegate: OmniBarDelegate?
fileprivate var state: OmniBarState = SmallOmniBarState.HomeNonEditingState()
private var safeAreaInsetsObservation: NSKeyValueObservation?

private var privacyIconAndTrackersAnimator = PrivacyIconAndTrackersAnimator()
private var notificationAnimator = OmniBarNotificationAnimator()
Expand Down Expand Up @@ -100,7 +99,6 @@ class OmniBar: UIView {
configureEditingMenu()
refreshState(state)
enableInteractionsWithPointer()
observeSafeAreaInsets()

privacyInfoContainer.isHidden = true
}
Expand Down Expand Up @@ -140,13 +138,7 @@ class OmniBar: UIView {
name: .speechRecognizerDidChangeAvailability,
object: nil)
}

private func observeSafeAreaInsets() {
safeAreaInsetsObservation = self.observe(\.safeAreaInsets, options: .new) { [weak self] (_, _) in
self?.updateOmniBarPadding()
}
}


private func enableInteractionsWithPointer() {
backButton.isPointerInteractionEnabled = true
forwardButton.isPointerInteractionEnabled = true
Expand Down Expand Up @@ -346,18 +338,16 @@ class OmniBar: UIView {
if state.showVoiceSearch && state.showClear {
searchStackContainer.setCustomSpacing(13, after: voiceSearchButton)
}

updateOmniBarPadding()

UIView.animate(withDuration: 0.0) {
self.layoutIfNeeded()
}

}

private func updateOmniBarPadding() {
omniBarLeadingConstraint.constant = (state.hasLargeWidth ? 24 : 8) + safeAreaInsets.left
omniBarTrailingConstraint.constant = (state.hasLargeWidth ? 24 : 14) + safeAreaInsets.right
func updateOmniBarPadding(left: CGFloat, right: CGFloat) {
omniBarLeadingConstraint.constant = (state.hasLargeWidth ? 24 : 8) + left
omniBarTrailingConstraint.constant = (state.hasLargeWidth ? 24 : 14) + right
}

/*
Expand Down
17 changes: 3 additions & 14 deletions DuckDuckGo/SwipeTabsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,40 +348,29 @@ extension SwipeTabsCoordinator: UICollectionViewDataSource {

class OmniBarCell: UICollectionViewCell {

weak var leadingConstraint: NSLayoutConstraint?
weak var trailingConstraint: NSLayoutConstraint?

weak var omniBar: OmniBar? {
didSet {
subviews.forEach { $0.removeFromSuperview() }
if let omniBar {
addSubview(omniBar)

let leadingConstraint = constrainView(omniBar, by: .leadingMargin)
let trailingConstraint = constrainView(omniBar, by: .trailingMargin)

NSLayoutConstraint.activate([
leadingConstraint,
trailingConstraint,
constrainView(omniBar, by: .leadingMargin),
constrainView(omniBar, by: .trailingMargin),
constrainView(omniBar, by: .top),
constrainView(omniBar, by: .bottom),
])

self.leadingConstraint = leadingConstraint
self.trailingConstraint = trailingConstraint
}
}
}

override func updateConstraints() {
super.updateConstraints()
print("***", #function)

let left = superview?.safeAreaInsets.left ?? 0
let right = superview?.safeAreaInsets.right ?? 0

leadingConstraint?.constant = -left
trailingConstraint?.constant = right
omniBar?.updateOmniBarPadding(left: left, right: right)
}

}
Expand Down

0 comments on commit a94198c

Please sign in to comment.