Skip to content

Commit

Permalink
force omnibar to never animate its components on state change
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Oct 13, 2023
1 parent de6bf60 commit 3a469ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
25 changes: 14 additions & 11 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ class MainViewController: UIViewController {
let keyboardFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
return
}
let duration: TimeInterval = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
let animationCurveRawNSN = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber
let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIView.AnimationOptions.curveEaseInOut.rawValue
let animationCurve = UIView.AnimationOptions(rawValue: animationCurveRaw)

var height = keyboardFrame.size.height

Expand All @@ -381,21 +385,20 @@ class MainViewController: UIViewController {
}
}

let navBarOffset = min(0, toolbarHeight - intersection.height)
self.viewCoordinator.constraints.omniBarBottom.constant = appSettings.currentAddressBarPosition == .bottom ? navBarOffset : 0
self.animateForKeyboard(userInfo: userInfo, y: self.view.frame.height - height)
}

private func animateForKeyboard(userInfo: [AnyHashable: Any], y: CGFloat) {
let duration: TimeInterval = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
let animationCurveRawNSN = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber
let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIView.AnimationOptions.curveEaseInOut.rawValue
let animationCurve = UIView.AnimationOptions(rawValue: animationCurveRaw)

let y = self.view.frame.height - height
let frame = self.findInPageView.frame
UIView.animate(withDuration: duration, delay: 0, options: animationCurve, animations: {
self.findInPageView.frame = CGRect(x: 0, y: y - frame.height, width: frame.width, height: frame.height)
}, completion: nil)

if self.appSettings.currentAddressBarPosition.isBottom {
let navBarOffset = min(0, self.toolbarHeight - intersection.height)
self.viewCoordinator.constraints.omniBarBottom.constant = navBarOffset
UIView.animate(withDuration: duration, delay: 0, options: animationCurve) {
self.viewCoordinator.navigationBarContainer.superview?.layoutIfNeeded()
}
}

}

private func initTabButton() {
Expand Down
5 changes: 5 additions & 0 deletions DuckDuckGo/OmniBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ class OmniBar: UIView {
}

updateOmniBarPadding()

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

}

private func updateOmniBarPadding() {
Expand Down

0 comments on commit 3a469ae

Please sign in to comment.