diff --git a/Display/ContainableController.swift b/Display/ContainableController.swift index ec51a25542..fb77d8e463 100644 --- a/Display/ContainableController.swift +++ b/Display/ContainableController.swift @@ -14,6 +14,7 @@ public protocol ContainableController: class { var deferScreenEdgeGestures: UIRectEdge { get } func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) + func updateToInterfaceOrientation(_ orientation: UIInterfaceOrientation) func viewWillAppear(_ animated: Bool) func viewWillDisappear(_ animated: Bool) diff --git a/Display/ContextMenuContainerNode.swift b/Display/ContextMenuContainerNode.swift index 3ba11b0d10..52951a9317 100644 --- a/Display/ContextMenuContainerNode.swift +++ b/Display/ContextMenuContainerNode.swift @@ -13,15 +13,15 @@ private final class ContextMenuContainerMaskView: UIView { } } -final class ContextMenuContainerNode: ASDisplayNode { +public final class ContextMenuContainerNode: ASDisplayNode { private var cachedMaskParams: CachedMaskParams? private let maskView = ContextMenuContainerMaskView() - var relativeArrowPosition: (CGFloat, Bool)? + public var relativeArrowPosition: (CGFloat, Bool)? //private let effectView: UIVisualEffectView - override init() { + override public init() { //self.effectView = UIVisualEffectView(effect: UIBlurEffect(style: .light)) super.init() @@ -32,19 +32,19 @@ final class ContextMenuContainerNode: ASDisplayNode { self.view.mask = self.maskView } - override func didLoad() { + override public func didLoad() { super.didLoad() self.layer.allowsGroupOpacity = true } - override func layout() { + override public func layout() { super.layout() self.updateLayout(transition: .immediate) } - func updateLayout(transition: ContainedViewLayoutTransition) { + public func updateLayout(transition: ContainedViewLayoutTransition) { //self.effectView.frame = self.bounds let maskParams = CachedMaskParams(size: self.bounds.size, relativeArrowPosition: self.relativeArrowPosition?.0 ?? self.bounds.size.width / 2.0, arrowOnBottom: self.relativeArrowPosition?.1 ?? true) @@ -58,23 +58,23 @@ final class ContextMenuContainerNode: ASDisplayNode { let arrowOnBottom = maskParams.arrowOnBottom path.move(to: CGPoint(x: 0.0, y: verticalInset + cornerRadius)) - path.addArc(withCenter: CGPoint(x: cornerRadius, y: verticalInset + cornerRadius), radius: cornerRadius, startAngle: CGFloat.pi, endAngle: CGFloat(3 * M_PI / 2), clockwise: true) + path.addArc(withCenter: CGPoint(x: cornerRadius, y: verticalInset + cornerRadius), radius: cornerRadius, startAngle: CGFloat.pi, endAngle: CGFloat(3.0 * CGFloat.pi / 2.0), clockwise: true) if !arrowOnBottom { path.addLine(to: CGPoint(x: arrowPosition - arrowWidth / 2.0, y: verticalInset)) path.addLine(to: CGPoint(x: arrowPosition, y: 0.0)) path.addLine(to: CGPoint(x: arrowPosition + arrowWidth / 2.0, y: verticalInset)) } path.addLine(to: CGPoint(x: maskParams.size.width - cornerRadius, y: verticalInset)) - path.addArc(withCenter: CGPoint(x: maskParams.size.width - cornerRadius, y: verticalInset + cornerRadius), radius: cornerRadius, startAngle: CGFloat(3 * M_PI / 2), endAngle: 0.0, clockwise: true) + path.addArc(withCenter: CGPoint(x: maskParams.size.width - cornerRadius, y: verticalInset + cornerRadius), radius: cornerRadius, startAngle: CGFloat(3.0 * CGFloat.pi / 2.0), endAngle: 0.0, clockwise: true) path.addLine(to: CGPoint(x: maskParams.size.width, y: maskParams.size.height - cornerRadius - verticalInset)) - path.addArc(withCenter: CGPoint(x: maskParams.size.width - cornerRadius, y: maskParams.size.height - cornerRadius - verticalInset), radius: cornerRadius, startAngle: 0.0, endAngle: CGFloat(M_PI / 2.0), clockwise: true) + path.addArc(withCenter: CGPoint(x: maskParams.size.width - cornerRadius, y: maskParams.size.height - cornerRadius - verticalInset), radius: cornerRadius, startAngle: 0.0, endAngle: CGFloat(CGFloat.pi / 2.0), clockwise: true) if arrowOnBottom { path.addLine(to: CGPoint(x: arrowPosition + arrowWidth / 2.0, y: maskParams.size.height - verticalInset)) path.addLine(to: CGPoint(x: arrowPosition, y: maskParams.size.height)) path.addLine(to: CGPoint(x: arrowPosition - arrowWidth / 2.0, y: maskParams.size.height - verticalInset)) } path.addLine(to: CGPoint(x: cornerRadius, y: maskParams.size.height - verticalInset)) - path.addArc(withCenter: CGPoint(x: cornerRadius, y: maskParams.size.height - cornerRadius - verticalInset), radius: cornerRadius, startAngle: CGFloat(M_PI / 2.0), endAngle: CGFloat(M_PI), clockwise: true) + path.addArc(withCenter: CGPoint(x: cornerRadius, y: maskParams.size.height - cornerRadius - verticalInset), radius: cornerRadius, startAngle: CGFloat(CGFloat.pi / 2.0), endAngle: CGFloat(M_PI), clockwise: true) path.close() self.cachedMaskParams = maskParams diff --git a/Display/GlobalOverlayPresentationContext.swift b/Display/GlobalOverlayPresentationContext.swift index c033cccae8..30f36ee169 100644 --- a/Display/GlobalOverlayPresentationContext.swift +++ b/Display/GlobalOverlayPresentationContext.swift @@ -158,6 +158,14 @@ final class GlobalOverlayPresentationContext { return nil } + func updateToInterfaceOrientation(_ orientation: UIInterfaceOrientation) { + if self.ready { + for controller in self.controllers { + controller.updateToInterfaceOrientation(orientation) + } + } + } + func combinedSupportedOrientations(currentOrientationToLock: UIInterfaceOrientationMask) -> ViewControllerSupportedOrientations { var mask = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .all) diff --git a/Display/NativeWindowHostView.swift b/Display/NativeWindowHostView.swift index ca119323ac..359f637568 100644 --- a/Display/NativeWindowHostView.swift +++ b/Display/NativeWindowHostView.swift @@ -169,7 +169,7 @@ private final class NativeWindow: UIWindow, WindowHost { var updateSize: ((CGSize) -> Void)? var layoutSubviewsEvent: (() -> Void)? var updateIsUpdatingOrientationLayout: ((Bool) -> Void)? - var updateToInterfaceOrientation: (() -> Void)? + var updateToInterfaceOrientation: ((UIInterfaceOrientation) -> Void)? var presentController: ((ContainableController, PresentationSurfaceLevel, Bool, @escaping () -> Void) -> Void)? var presentControllerInGlobalOverlay: ((_ controller: ContainableController) -> Void)? var hitTestImpl: ((CGPoint, UIEvent?) -> UIView?)? @@ -246,7 +246,8 @@ private final class NativeWindow: UIWindow, WindowHost { super._update(toInterfaceOrientation: arg1, duration: arg2, force: arg3) self.updateIsUpdatingOrientationLayout?(false) - self.updateToInterfaceOrientation?() + let orientation = UIInterfaceOrientation(rawValue: Int(arg1)) ?? .unknown + self.updateToInterfaceOrientation?(orientation) } func present(_ controller: ContainableController, on level: PresentationSurfaceLevel, blockInteraction: Bool, completion: @escaping () -> Void) { @@ -316,8 +317,8 @@ public func nativeWindowHostView() -> (UIWindow & WindowHost, WindowHostView) { hostView?.isUpdatingOrientationLayout = value } - window.updateToInterfaceOrientation = { [weak hostView] in - hostView?.updateToInterfaceOrientation?() + window.updateToInterfaceOrientation = { [weak hostView] orientation in + hostView?.updateToInterfaceOrientation?(orientation) } window.presentController = { [weak hostView] controller, level, blockInteraction, completion in diff --git a/Display/NavigationController.swift b/Display/NavigationController.swift index 97be54cde0..6b7828d385 100644 --- a/Display/NavigationController.swift +++ b/Display/NavigationController.swift @@ -599,6 +599,14 @@ open class NavigationController: UINavigationController, ContainableController, } } + public func updateToInterfaceOrientation(_ orientation: UIInterfaceOrientation) { + for record in self._viewControllers { + if let controller = record.controller as? ContainableController { + controller.updateToInterfaceOrientation(orientation) + } + } + } + open override func loadView() { self._displayNode = ASDisplayNode(viewBlock: { return NavigationControllerView() diff --git a/Display/PresentationContext.swift b/Display/PresentationContext.swift index 766f6974de..bbfb45dc09 100644 --- a/Display/PresentationContext.swift +++ b/Display/PresentationContext.swift @@ -286,6 +286,14 @@ final class PresentationContext { return nil } + func updateToInterfaceOrientation(_ orientation: UIInterfaceOrientation) { + if self.ready { + for (controller, _) in self.controllers { + controller.updateToInterfaceOrientation(orientation) + } + } + } + func combinedSupportedOrientations(currentOrientationToLock: UIInterfaceOrientationMask) -> ViewControllerSupportedOrientations { var mask = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .all) diff --git a/Display/TooltipController.swift b/Display/TooltipController.swift index f396a03dab..33fc6a5792 100644 --- a/Display/TooltipController.swift +++ b/Display/TooltipController.swift @@ -74,16 +74,18 @@ public final class TooltipController: ViewController { private let timeout: Double private let dismissByTapOutside: Bool + private let dismissImmediatelyOnLayoutUpdate: Bool private var timeoutTimer: SwiftSignalKit.Timer? private var layout: ContainerViewLayout? public var dismissed: (() -> Void)? - public init(content: TooltipControllerContent, timeout: Double = 2.0, dismissByTapOutside: Bool = false) { + public init(content: TooltipControllerContent, timeout: Double = 2.0, dismissByTapOutside: Bool = false, dismissImmediatelyOnLayoutUpdate: Bool = false) { self.content = content self.timeout = timeout self.dismissByTapOutside = dismissByTapOutside + self.dismissImmediatelyOnLayoutUpdate = dismissImmediatelyOnLayoutUpdate super.init(navigationBarPresentationData: nil) } @@ -114,9 +116,10 @@ public final class TooltipController: ViewController { super.containerLayoutUpdated(layout, transition: transition) if self.layout != nil && self.layout! != layout { - self.dismissed?() - self.controllerNode.animateOut { [weak self] in - self?.presentingViewController?.dismiss(animated: false) + if self.dismissImmediatelyOnLayoutUpdate { + self.dismissImmediately() + } else { + self.dismiss() } } else { self.layout = layout @@ -160,4 +163,9 @@ public final class TooltipController: ViewController { completion?() } } + + public func dismissImmediately() { + self.dismissed?() + self.presentingViewController?.dismiss(animated: false) + } } diff --git a/Display/ViewController.swift b/Display/ViewController.swift index cddb0e2eda..275de0ce6f 100644 --- a/Display/ViewController.swift +++ b/Display/ViewController.swift @@ -327,6 +327,10 @@ open class ViewControllerPresentationArguments { } } + open func updateToInterfaceOrientation(_ orientation: UIInterfaceOrientation) { + + } + public func setDisplayNavigationBar(_ displayNavigationBar: Bool, transition: ContainedViewLayoutTransition = .immediate) { if displayNavigationBar != self.displayNavigationBar { self.displayNavigationBar = displayNavigationBar diff --git a/Display/WindowContent.swift b/Display/WindowContent.swift index bc674b2c5f..bcf1bdc838 100644 --- a/Display/WindowContent.swift +++ b/Display/WindowContent.swift @@ -220,7 +220,7 @@ public final class WindowHostView { var presentNative: ((UIViewController) -> Void)? var updateSize: ((CGSize, Double) -> Void)? var layoutSubviews: (() -> Void)? - var updateToInterfaceOrientation: (() -> Void)? + var updateToInterfaceOrientation: ((UIInterfaceOrientation) -> Void)? var isUpdatingOrientationLayout = false var hitTest: ((CGPoint, UIEvent?) -> UIView?)? var invalidateDeferScreenEdgeGesture: (() -> Void)? @@ -398,8 +398,8 @@ public class Window1 { self?.layoutSubviews() } - self.hostView.updateToInterfaceOrientation = { [weak self] in - self?.updateToInterfaceOrientation() + self.hostView.updateToInterfaceOrientation = { [weak self] orientation in + self?.updateToInterfaceOrientation(orientation) } self.hostView.hitTest = { [weak self] point, event in @@ -844,12 +844,19 @@ public class Window1 { var postUpdateToInterfaceOrientationBlocks: [() -> Void] = [] - private func updateToInterfaceOrientation() { + private func updateToInterfaceOrientation(_ orientation: UIInterfaceOrientation) { let blocks = self.postUpdateToInterfaceOrientationBlocks self.postUpdateToInterfaceOrientationBlocks = [] for f in blocks { f() } + self._rootController?.updateToInterfaceOrientation(orientation) + self.presentationContext.updateToInterfaceOrientation(orientation) + self.overlayPresentationContext.updateToInterfaceOrientation(orientation) + + for controller in self.topLevelOverlayControllers { + controller.updateToInterfaceOrientation(orientation) + } } public func addPostUpdateToInterfaceOrientationBlock(f: @escaping () -> Void) {