mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 14:02:48 +00:00
Pass interface orientation updates to view controller
This commit is contained in:
parent
ca80cc40dc
commit
26d26bb3a5
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user