Improve layout

This commit is contained in:
Peter 2019-07-09 19:41:12 +04:00
parent a16fbaebfc
commit 07be3d7426
6 changed files with 53 additions and 17 deletions

View File

@ -751,7 +751,7 @@ open class NavigationController: UINavigationController, ContainableController,
} }
if let navigationTransitionCoordinator = self.navigationTransitionCoordinator { if let navigationTransitionCoordinator = self.navigationTransitionCoordinator {
navigationTransitionCoordinator.updateProgress() navigationTransitionCoordinator.updateProgress(transition: transition)
} }
} }
@ -840,14 +840,14 @@ open class NavigationController: UINavigationController, ContainableController,
bottomController.displayNode.recursivelyEnsureDisplaySynchronously(true) bottomController.displayNode.recursivelyEnsureDisplaySynchronously(true)
} }
let navigationTransitionCoordinator = NavigationTransitionCoordinator(transition: .Pop, container: self.controllerView.containerView, topView: topView, topNavigationBar: (topController as? ViewController)?.navigationBar, bottomView: bottomView, bottomNavigationBar: (bottomController as? ViewController)?.navigationBar, didUpdateProgress: { [weak self] progress in let navigationTransitionCoordinator = NavigationTransitionCoordinator(transition: .Pop, container: self.controllerView.containerView, topView: topView, topNavigationBar: (topController as? ViewController)?.navigationBar, bottomView: bottomView, bottomNavigationBar: (bottomController as? ViewController)?.navigationBar, didUpdateProgress: { [weak self] progress, transition in
if let strongSelf = self { if let strongSelf = self {
for i in 0 ..< strongSelf._viewControllers.count { for i in 0 ..< strongSelf._viewControllers.count {
if let controller = strongSelf._viewControllers[i].controller as? ViewController { if let controller = strongSelf._viewControllers[i].controller as? ViewController {
if i < strongSelf._viewControllers.count - 1 { if i < strongSelf._viewControllers.count - 1 {
controller.updateNavigationCustomData((strongSelf.viewControllers[i + 1] as? ViewController)?.customData, progress: 1.0 - progress, transition: .immediate) controller.updateNavigationCustomData((strongSelf.viewControllers[i + 1] as? ViewController)?.customData, progress: 1.0 - progress, transition: transition)
} else { } else {
controller.updateNavigationCustomData(nil, progress: 1.0 - progress, transition: .immediate) controller.updateNavigationCustomData(nil, progress: 1.0 - progress, transition: transition)
} }
} }
} }

View File

@ -21,7 +21,7 @@ class NavigationTransitionCoordinator {
} }
set(value) { set(value) {
self._progress = value self._progress = value
self.updateProgress() self.updateProgress(transition: .immediate)
} }
} }
@ -39,8 +39,9 @@ class NavigationTransitionCoordinator {
private(set) var animatingCompletion = false private(set) var animatingCompletion = false
private var currentCompletion: (() -> Void)? private var currentCompletion: (() -> Void)?
private var didUpdateProgress:((CGFloat)->Void)? private var didUpdateProgress: ((CGFloat, ContainedViewLayoutTransition) -> Void)?
init(transition: NavigationTransition, container: UIView, topView: UIView, topNavigationBar: NavigationBar?, bottomView: UIView, bottomNavigationBar: NavigationBar?, didUpdateProgress: ((CGFloat) -> Void)? = nil) {
init(transition: NavigationTransition, container: UIView, topView: UIView, topNavigationBar: NavigationBar?, bottomView: UIView, bottomNavigationBar: NavigationBar?, didUpdateProgress: ((CGFloat, ContainedViewLayoutTransition) -> Void)? = nil) {
self.transition = transition self.transition = transition
self.container = container self.container = container
self.didUpdateProgress = didUpdateProgress self.didUpdateProgress = didUpdateProgress
@ -79,14 +80,14 @@ class NavigationTransitionCoordinator {
self.viewSuperview?.insertSubview(self.shadowView, belowSubview: dimView) self.viewSuperview?.insertSubview(self.shadowView, belowSubview: dimView)
self.maybeCreateNavigationBarTransition() self.maybeCreateNavigationBarTransition()
self.updateProgress() self.updateProgress(transition: .immediate)
} }
required init(coder aDecoder: NSCoder) { required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
func updateProgress() { func updateProgress(transition: ContainedViewLayoutTransition) {
let position: CGFloat let position: CGFloat
switch self.transition { switch self.transition {
case .Push: case .Push:
@ -111,7 +112,7 @@ class NavigationTransitionCoordinator {
self.updateNavigationBarTransition() self.updateNavigationBarTransition()
self.didUpdateProgress?(self.progress) self.didUpdateProgress?(self.progress, transition)
} }
func updateNavigationBarTransition() { func updateNavigationBarTransition() {

View File

@ -14,7 +14,7 @@ public enum PresentationContextType {
case window(PresentationSurfaceLevel) case window(PresentationSurfaceLevel)
} }
final class PresentationContext { public final class PresentationContext {
private var _view: UIView? private var _view: UIView?
var view: UIView? { var view: UIView? {
get { get {

View File

@ -176,7 +176,23 @@ open class TabBarController: ViewController {
} }
} }
if let validLayout = strongSelf.validLayout { if let validLayout = strongSelf.validLayout {
strongSelf.controllers[index].containerLayoutUpdated(validLayout.addedInsets(insets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 49.0, right: 0.0)), transition: .immediate) var updatedLayout = validLayout
var tabBarHeight: CGFloat
var options: ContainerViewLayoutInsetOptions = []
if validLayout.metrics.widthClass == .regular {
options.insert(.input)
}
let bottomInset: CGFloat = validLayout.insets(options: options).bottom
if !validLayout.safeInsets.left.isZero {
tabBarHeight = 34.0 + bottomInset
} else {
tabBarHeight = 49.0 + bottomInset
}
updatedLayout.intrinsicInsets.bottom = tabBarHeight
strongSelf.controllers[index].containerLayoutUpdated(updatedLayout, transition: .immediate)
} }
let startTime = CFAbsoluteTimeGetCurrent() let startTime = CFAbsoluteTimeGetCurrent()
strongSelf.pendingControllerDisposable.set((strongSelf.controllers[index].ready.get() strongSelf.pendingControllerDisposable.set((strongSelf.controllers[index].ready.get()
@ -271,7 +287,23 @@ open class TabBarController: ViewController {
if let currentController = self.currentController { if let currentController = self.currentController {
currentController.view.frame = CGRect(origin: CGPoint(), size: layout.size) currentController.view.frame = CGRect(origin: CGPoint(), size: layout.size)
currentController.containerLayoutUpdated(layout.addedInsets(insets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 49.0, right: 0.0)), transition: transition) var updatedLayout = layout
var tabBarHeight: CGFloat
var options: ContainerViewLayoutInsetOptions = []
if updatedLayout.metrics.widthClass == .regular {
options.insert(.input)
}
let bottomInset: CGFloat = updatedLayout.insets(options: options).bottom
if !updatedLayout.safeInsets.left.isZero {
tabBarHeight = 34.0 + bottomInset
} else {
tabBarHeight = 49.0 + bottomInset
}
updatedLayout.intrinsicInsets.bottom = tabBarHeight
currentController.containerLayoutUpdated(updatedLayout, transition: transition)
} }
} }

View File

@ -65,7 +65,7 @@ open class ViewControllerPresentationArguments {
return self.validLayout return self.validLayout
} }
private let presentationContext: PresentationContext public let presentationContext: PresentationContext
public final var supportedOrientations: ViewControllerSupportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .allButUpsideDown) public final var supportedOrientations: ViewControllerSupportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .allButUpsideDown)
public final var lockedOrientation: UIInterfaceOrientationMask? public final var lockedOrientation: UIInterfaceOrientationMask?
@ -81,6 +81,7 @@ open class ViewControllerPresentationArguments {
public final var isOpaqueWhenInOverlay: Bool = false public final var isOpaqueWhenInOverlay: Bool = false
public final var blocksBackgroundWhenInOverlay: Bool = false public final var blocksBackgroundWhenInOverlay: Bool = false
public final var automaticallyControlPresentationContextLayout: Bool = true
public func combinedSupportedOrientations(currentOrientationToLock: UIInterfaceOrientationMask) -> ViewControllerSupportedOrientations { public func combinedSupportedOrientations(currentOrientationToLock: UIInterfaceOrientationMask) -> ViewControllerSupportedOrientations {
return self.supportedOrientations return self.supportedOrientations
@ -332,7 +333,9 @@ open class ViewControllerPresentationArguments {
self.updateNavigationBarLayout(layout, transition: transition) self.updateNavigationBarLayout(layout, transition: transition)
self.presentationContext.containerLayoutUpdated(layout, transition: transition) if self.automaticallyControlPresentationContextLayout {
self.presentationContext.containerLayoutUpdated(layout, transition: transition)
}
if let scrollToTopView = self.scrollToTopView { if let scrollToTopView = self.scrollToTopView {
scrollToTopView.frame = CGRect(x: 0.0, y: 0.0, width: layout.size.width, height: 10.0) scrollToTopView.frame = CGRect(x: 0.0, y: 0.0, width: layout.size.width, height: 10.0)

View File

@ -4541,8 +4541,8 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget,
} }
} }
}, recognizedQRCode: { [weak self] code in }, recognizedQRCode: { [weak self] code in
if let strongSelf = self, let (host, port, username, password, secret, secretHost) = parseProxyUrl(code) { if let strongSelf = self, let (host, port, username, password, secret) = parseProxyUrl(code) {
strongSelf.openResolved(ResolvedUrl.proxy(host: host, port: port, username: username, password: password, secret: secret, secretHost: secretHost)) strongSelf.openResolved(ResolvedUrl.proxy(host: host, port: port, username: username, password: password, secret: secret))
} }
}) })
} }