Implemented find on page UI
This commit is contained in:
@@ -13,6 +13,10 @@ class BrowserView: UIView
|
||||
{
|
||||
let titlebarView = TitlebarView()
|
||||
|
||||
var findOnPageView: FindOnPageView? {
|
||||
didSet { addSubview(findOnPageView!) }
|
||||
}
|
||||
|
||||
var toolbarView: ToolbarView? {
|
||||
didSet { addSubview(toolbarView!) }
|
||||
}
|
||||
@@ -38,6 +42,18 @@ class BrowserView: UIView
|
||||
}
|
||||
}
|
||||
|
||||
var findOnPageVisible: Bool = false {
|
||||
didSet { layoutSubviews() }
|
||||
}
|
||||
|
||||
func setFindOnPageVisible(_ visible: Bool, animated: Bool) {
|
||||
if animated {
|
||||
UIView.animate(withDuration: 0.33, animations: { self.findOnPageVisible = visible })
|
||||
} else {
|
||||
findOnPageVisible = visible
|
||||
}
|
||||
}
|
||||
|
||||
var keyboardWillShowObserver: AnyCancellable?
|
||||
var keyboardWillHideObserver: AnyCancellable?
|
||||
var keyboardLayoutOffset: CGFloat = 0 { didSet { setNeedsLayout() } }
|
||||
@@ -101,6 +117,11 @@ class BrowserView: UIView
|
||||
toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize)
|
||||
toolbarView.center = CGPoint(x: bounds.center.x, y: bounds.maxY - (toolbarView.bounds.height / 2) - bottomOffset)
|
||||
webViewContentInset.bottom += toolbarView.frame.height
|
||||
|
||||
if findOnPageVisible {
|
||||
// Hide off the bottom
|
||||
toolbarView.center = CGPoint(x: toolbarView.center.x, y: toolbarView.center.y + toolbarView.frame.height)
|
||||
}
|
||||
} else {
|
||||
// Regular: toolbar is at the top
|
||||
toolbarView.frame = CGRect(origin: CGPoint(x: 0.0, y: titlebarView.frame.maxY), size: toolbarSize)
|
||||
@@ -139,5 +160,25 @@ class BrowserView: UIView
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find on page view
|
||||
if let findOnPageView = findOnPageView {
|
||||
var bottomOffset: CGFloat = 0.0
|
||||
var findOnPageSize = CGSize(width: bounds.width, height: 54.0)
|
||||
if keyboardLayoutOffset == 0 {
|
||||
findOnPageSize.height += safeAreaInsets.bottom
|
||||
} else if findOnPageView.textField.isFirstResponder {
|
||||
bottomOffset = keyboardLayoutOffset
|
||||
}
|
||||
|
||||
findOnPageView.bounds = CGRect(origin: .zero, size: findOnPageSize)
|
||||
findOnPageView.center = CGPoint(x: bounds.center.x, y: bounds.maxY - (findOnPageView.bounds.height / 2) - bottomOffset)
|
||||
bringSubviewToFront(findOnPageView)
|
||||
|
||||
if !findOnPageVisible {
|
||||
// Hide off the bottom
|
||||
findOnPageView.center = CGPoint(x: findOnPageView.center.x, y: findOnPageView.center.y + findOnPageView.frame.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user