Fix inputHeight edge cases

This commit is contained in:
Peter 2019-10-03 13:41:15 +04:00
parent 772f461352
commit ba3d2a2430
3 changed files with 38 additions and 7 deletions

View File

@ -306,7 +306,11 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
var updatedStatusBarStyle = self.statusBarStyle
if let top = self.state.top {
self.applyLayout(layout: layout, to: top, isMaster: true, transition: transition)
var updatedLayout = layout
if let topTransition = self.state.transition {
updatedLayout = updatedLayout.withUpdatedInputHeight(nil)
}
self.applyLayout(layout: updatedLayout, to: top, isMaster: true, transition: transition)
updatedStatusBarStyle = top.value.statusBar.statusBarStyle
} else {
updatedStatusBarStyle = .Ignore
@ -364,6 +368,10 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
guard let strongSelf = self, let topTransition = topTransition, strongSelf.state.transition === topTransition else {
return
}
if viewTreeContainsFirstResponder(view: topTransition.previous.value.view) {
strongSelf.ignoreInputHeight = true
}
strongSelf.keyboardViewManager?.dismissEditingWithoutAnimation(view: topTransition.previous.value.view)
strongSelf.state.transition = nil
@ -376,6 +384,8 @@ final class NavigationContainer: ASDisplayNode, UIGestureRecognizerDelegate {
strongSelf.applyLayout(layout: layout, to: toValue, isMaster: true, transition: .immediate)
toValue.value.viewDidAppear(true)
}
strongSelf.ignoreInputHeight = false
})
} else {
if let fromValue = fromValue {

View File

@ -129,6 +129,7 @@ open class NavigationController: UINavigationController, ContainableController,
private var validStatusBarStyle: NavigationStatusBarStyle?
private var validStatusBarHidden: Bool = false
private var ignoreInputHeight: Bool = false
private var currentStatusBarExternalHidden: Bool = false
private var scheduledLayoutTransitionRequestId: Int = 0
@ -257,6 +258,14 @@ open class NavigationController: UINavigationController, ContainableController,
private func updateContainers(layout rawLayout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
var layout = rawLayout
if self.ignoreInputHeight {
if layout.inputHeight == nil {
self.ignoreInputHeight = false
} else {
layout = layout.withUpdatedInputHeight(nil)
}
}
if let globalScrollToTopNode = self.globalScrollToTopNode {
globalScrollToTopNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -1.0), size: CGSize(width: layout.size.width, height: 1.0))
}
@ -317,14 +326,16 @@ open class NavigationController: UINavigationController, ContainableController,
strongSelf.updateContainers(layout: layout, transition: transition)
}
}
modalContainer.interactivelyDismissed = { [weak self, weak modalContainer] in
modalContainer.interactivelyDismissed = { [weak self, weak modalContainer] hadInputFocus in
guard let strongSelf = self, let modalContainer = modalContainer else {
return
}
let controllers = strongSelf._viewControllers.filter { controller in
return !modalContainer.container.controllers.contains(where: { $0 === controller })
}
strongSelf.ignoreInputHeight = hadInputFocus
strongSelf.setViewControllers(controllers, animated: false)
strongSelf.ignoreInputHeight = false
}
}
modalContainers.append(modalContainer)
@ -332,7 +343,12 @@ open class NavigationController: UINavigationController, ContainableController,
for container in self.modalContainers {
if !modalContainers.contains(where: { $0 === container }) {
transition = container.dismiss(transition: transition, completion: { [weak container] in
if viewTreeContainsFirstResponder(view: container.view) {
self.ignoreInputHeight = true
container.view.endEditing(true)
}
transition = container.dismiss(transition: transition, completion: { [weak self, weak container] in
container?.removeFromSupernode()
})
}
@ -825,7 +841,11 @@ open class NavigationController: UINavigationController, ContainableController,
public func filterController(_ controller: ViewController, animated: Bool) {
let controllers = self.viewControllers.filter({ $0 !== controller })
if controllers.count != self.viewControllers.count {
if controller.isViewLoaded && viewTreeContainsFirstResponder(view: controller.view) {
self.ignoreInputHeight = true
}
self.setViewControllers(controllers, animated: animated)
self.ignoreInputHeight = false
}
}

View File

@ -16,7 +16,7 @@ final class NavigationModalContainer: ASDisplayNode, UIScrollViewDelegate, UIGes
private(set) var dismissProgress: CGFloat = 0.0
var isReadyUpdated: (() -> Void)?
var updateDismissProgress: ((CGFloat, ContainedViewLayoutTransition) -> Void)?
var interactivelyDismissed: (() -> Void)?
var interactivelyDismissed: ((Bool) -> Void)?
private var ignoreScrolling = false
private var isDismissed = false
@ -152,8 +152,9 @@ final class NavigationModalContainer: ASDisplayNode, UIScrollViewDelegate, UIGes
guard let strongSelf = self else {
return
}
let hadInputFocus = viewTreeContainsFirstResponder(view: strongSelf.view)
strongSelf.keyboardViewManager?.dismissEditingWithoutAnimation(view: strongSelf.view)
strongSelf.interactivelyDismissed?()
strongSelf.interactivelyDismissed?(hadInputFocus)
})
} else {
self.horizontalDismissOffset = nil
@ -194,7 +195,7 @@ final class NavigationModalContainer: ASDisplayNode, UIScrollViewDelegate, UIGes
return
}
if targetOffset == 0.0 {
strongSelf.interactivelyDismissed?()
strongSelf.interactivelyDismissed?(false)
}
})
self.ignoreScrolling = false
@ -255,7 +256,7 @@ final class NavigationModalContainer: ASDisplayNode, UIScrollViewDelegate, UIGes
return
}
if targetOffset == 0.0 {
strongSelf.interactivelyDismissed?()
strongSelf.interactivelyDismissed?(false)
}
})
self.ignoreScrolling = false