From c890c13fd4e78b600ff17cab1169c4bcff940d82 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 29 Oct 2019 23:26:48 +0400 Subject: [PATCH] Temp --- .../Details/_ASDisplayViewAccessiblity.mm | 6 +- .../Sources/ContactsControllerNode.swift | 2 + .../Display/Display/PresentationContext.swift | 2 - .../Display/Display/WindowContent.swift | 137 ++++-------------- .../ImageBlur/Sources/ApplyScreenshotEffect.m | 3 +- .../MediaResources/Sources/MapResources.swift | 30 +++- .../Sources/OverlayStatusController.swift | 3 +- .../Sources/PasscodeEntryController.swift | 4 + .../Sources/GroupsInCommonController.swift | 2 + .../Sources/PhotoResources.swift | 4 +- submodules/SSignalKit/SSignalKit/SSignalKit.h | 8 - .../Sources/SettingsController.swift | 2 + .../Themes/ThemeSettingsController.swift | 2 + 13 files changed, 70 insertions(+), 135 deletions(-) diff --git a/submodules/AsyncDisplayKit/Source/Details/_ASDisplayViewAccessiblity.mm b/submodules/AsyncDisplayKit/Source/Details/_ASDisplayViewAccessiblity.mm index f43e96c3ee..9e91056aaf 100644 --- a/submodules/AsyncDisplayKit/Source/Details/_ASDisplayViewAccessiblity.mm +++ b/submodules/AsyncDisplayKit/Source/Details/_ASDisplayViewAccessiblity.mm @@ -209,14 +209,14 @@ static void CollectAccessibilityElementsForView(UIView *view, NSMutableArray *el ASDisplayNode *node = view.asyncdisplaykit_node; - static Class telegramListViewClass = nil; + static Class displayListViewClass = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - telegramListViewClass = NSClassFromString(@"Display.ListView"); + displayListViewClass = NSClassFromString(@"Display.ListView"); }); BOOL anySubNodeIsCollection = (nil != ASDisplayNodeFindFirstNode(node, ^BOOL(ASDisplayNode *nodeToCheck) { - if (telegramListViewClass != nil && [nodeToCheck isKindOfClass:telegramListViewClass]) { + if (displayListViewClass != nil && [nodeToCheck isKindOfClass:displayListViewClass]) { return true; } return false; diff --git a/submodules/ContactListUI/Sources/ContactsControllerNode.swift b/submodules/ContactListUI/Sources/ContactsControllerNode.swift index 0399801ae6..bc34980964 100644 --- a/submodules/ContactListUI/Sources/ContactsControllerNode.swift +++ b/submodules/ContactListUI/Sources/ContactsControllerNode.swift @@ -31,6 +31,8 @@ private final class ContextControllerContentSourceImpl: ContextControllerContent let controller: ViewController weak var sourceNode: ASDisplayNode? + let navigationController: NavigationController? = nil + init(controller: ViewController, sourceNode: ASDisplayNode?) { self.controller = controller self.sourceNode = sourceNode diff --git a/submodules/Display/Display/PresentationContext.swift b/submodules/Display/Display/PresentationContext.swift index 7e7aeb403b..78bc9b5d68 100644 --- a/submodules/Display/Display/PresentationContext.swift +++ b/submodules/Display/Display/PresentationContext.swift @@ -34,8 +34,6 @@ public final class PresentationContext { } } - weak var volumeControlStatusBarNodeView: UIView? - var updateIsInteractionBlocked: ((Bool) -> Void)? var updateHasBlocked: ((Bool) -> Void)? diff --git a/submodules/Display/Display/WindowContent.swift b/submodules/Display/Display/WindowContent.swift index 67e9280d67..fec5ee6303 100644 --- a/submodules/Display/Display/WindowContent.swift +++ b/submodules/Display/Display/WindowContent.swift @@ -141,46 +141,6 @@ public func doesViewTreeDisableInteractiveTransitionGestureRecognizer(_ view: UI return false } -private let transitionClass: AnyClass? = NSClassFromString(encodeText("VJUsbotjujpoWjfx", -1)) -private let previewingClass: AnyClass? = NSClassFromString("UIVisualEffectView") -private let previewingActionGroupClass: AnyClass? = NSClassFromString("UIInterfaceActionGroupView") -private func checkIsPreviewingView(_ view: UIView) -> Bool { - if let transitionClass = transitionClass, view.isKind(of: transitionClass) { - for subview in view.subviews { - if let previewingClass = previewingClass, subview.isKind(of: previewingClass) { - return true - } - } - } - return false -} - -private func applyThemeToPreviewingView(_ view: UIView, accentColor: UIColor, darkBlur: Bool) { - if let previewingActionGroupClass = previewingActionGroupClass, view.isKind(of: previewingActionGroupClass) { - view.tintColor = accentColor - if darkBlur { - applyThemeToPreviewingEffectView(view) - } - return - } - - for subview in view.subviews { - applyThemeToPreviewingView(subview, accentColor: accentColor, darkBlur: darkBlur) - } -} - -private func applyThemeToPreviewingEffectView(_ view: UIView) { - if let previewingClass = previewingClass, view.isKind(of: previewingClass) { - if let view = view as? UIVisualEffectView { - view.effect = UIBlurEffect(style: .dark) - } - } - - for subview in view.subviews { - applyThemeToPreviewingEffectView(subview) - } -} - public func getFirstResponderAndAccessoryHeight(_ view: UIView, _ accessoryHeight: CGFloat? = nil) -> (UIView?, CGFloat?) { if view.isFirstResponder { return (view, accessoryHeight) @@ -283,7 +243,6 @@ public class Window1 { private var deviceMetrics: DeviceMetrics private let statusBarHost: StatusBarHost? - //private let statusBarManager: StatusBarManager? private let keyboardManager: KeyboardManager? private let keyboardViewManager: KeyboardViewManager? private var statusBarChangeObserver: AnyObject? @@ -301,6 +260,7 @@ public class Window1 { private let presentationContext: PresentationContext private let overlayPresentationContext: GlobalOverlayPresentationContext + private let topPresentationContext: PresentationContext private var tracingStatusBarsInvalidated = false private var shouldUpdateDeferScreenEdgeGestures = false @@ -315,7 +275,6 @@ public class Window1 { public private(set) var forceInCallStatusBarText: String? = nil public var inCallNavigate: (() -> Void)? { didSet { - //self.statusBarManager?.inCallNavigate = self.inCallNavigate } } @@ -328,9 +287,6 @@ public class Window1 { private var keyboardTypeChangeTimer: SwiftSignalKit.Timer? - //private let volumeControlStatusBar: VolumeControlStatusBar - //private let volumeControlStatusBarNode: VolumeControlStatusBarNode - private var isInteractionBlocked = false public init(hostView: WindowHostView, statusBarHost: StatusBarHost?) { @@ -360,6 +316,7 @@ public class Window1 { self.updatingLayout = UpdatingLayout(layout: self.windowLayout, transition: .immediate) self.presentationContext = PresentationContext() self.overlayPresentationContext = GlobalOverlayPresentationContext(statusBarHost: statusBarHost, parentView: self.hostView.containerView) + self.topPresentationContext = PresentationContext() self.presentationContext.updateIsInteractionBlocked = { [weak self] value in self?.isInteractionBlocked = value @@ -424,13 +381,10 @@ public class Window1 { }) } - /*self.hostView.getAccessibilityElements = { [weak self] in - return self?.accessibilityElements - }*/ - self.presentationContext.view = self.hostView.containerView - //self.presentationContext.volumeControlStatusBarNodeView = self.volumeControlStatusBarNode.view + self.topPresentationContext.view = self.hostView.containerView self.presentationContext.containerLayoutUpdated(containedLayoutForWindowLayout(self.windowLayout, deviceMetrics: self.deviceMetrics), transition: .immediate) + self.topPresentationContext.containerLayoutUpdated(containedLayoutForWindowLayout(self.windowLayout, deviceMetrics: self.deviceMetrics), transition: .immediate) self.overlayPresentationContext.containerLayoutUpdated(containedLayoutForWindowLayout(self.windowLayout, deviceMetrics: self.deviceMetrics), transition: .immediate) self.statusBarChangeObserver = NotificationCenter.default.addObserver(forName: UIApplication.willChangeStatusBarFrameNotification, object: nil, queue: OperationQueue.main, using: { [weak self] notification in @@ -615,9 +569,6 @@ public class Window1 { } self.windowPanRecognizer = recognizer self.hostView.containerView.addGestureRecognizer(recognizer) - - //self.hostView.containerView.addSubview(self.volumeControlStatusBar) - //self.hostView.containerView.addSubview(self.volumeControlStatusBarNode.view) } public required init(coder aDecoder: NSCoder) { @@ -642,10 +593,6 @@ public class Window1 { } } - public func setupVolumeControlStatusBarGraphics(_ graphics: (UIImage, UIImage, UIImage)) { - //self.volumeControlStatusBarNode.graphics = graphics - } - public func setForceInCallStatusBar(_ forceInCallStatusBarText: String?, transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .easeInOut)) { if self.forceInCallStatusBarText != forceInCallStatusBarText { self.forceInCallStatusBarText = forceInCallStatusBarText @@ -695,6 +642,11 @@ public class Window1 { if self.isInteractionBlocked { return nil } + + if let result = self.topPresentationContext.hitTest(view: self.hostView.containerView, point: point, with: event) { + return result + } + if let coveringView = self.coveringView, !coveringView.isHidden, coveringView.superview != nil, coveringView.frame.contains(point) { return coveringView.hitTest(point, with: event) } @@ -828,7 +780,11 @@ public class Window1 { coveringView.layer.removeAnimation(forKey: "opacity") coveringView.layer.allowsGroupOpacity = false coveringView.alpha = 1.0 - self.hostView.containerView.addSubview(coveringView) + if let controller = self.topPresentationContext.controllers.first { + self.hostView.containerView.insertSubview(coveringView, belowSubview: controller.0.displayNode.view) + } else { + self.hostView.containerView.addSubview(coveringView) + } if !self.windowLayout.size.width.isZero { coveringView.frame = CGRect(origin: CGPoint(), size: self.windowLayout.size) coveringView.updateLayout(self.windowLayout.size) @@ -839,58 +795,9 @@ public class Window1 { } private func layoutSubviews(force: Bool) { - var hasPreview = false - var updatedHasPreview = false - for subview in self.hostView.eventView.subviews { - if checkIsPreviewingView(subview) { - applyThemeToPreviewingView(subview, accentColor: self.previewThemeAccentColor, darkBlur: self.previewThemeDarkBlur) - hasPreview = true - break - } - } - if hasPreview != self.cachedHasPreview { - self.cachedHasPreview = hasPreview - updatedHasPreview = true - } - - if self.tracingStatusBarsInvalidated || updatedHasPreview, let keyboardManager = keyboardManager { + if self.tracingStatusBarsInvalidated, let keyboardManager = keyboardManager { self.tracingStatusBarsInvalidated = false - /*if self.statusBarHidden { - statusBarManager.updateState(surfaces: [], withSafeInsets: false, forceInCallStatusBarText: nil, forceHiddenBySystemWindows: false, animated: false) - } else { - var statusBarSurfaces: [StatusBarSurface] = [] - for layers in self.hostView.containerView.layer.traceableLayerSurfaces(withTag: WindowTracingTags.statusBar) { - let surface = StatusBarSurface() - for layer in layers { - let traceableInfo = layer.traceableInfo() - if let statusBar = traceableInfo?.userData as? StatusBar { - surface.addStatusBar(statusBar) - } - } - statusBarSurfaces.append(surface) - } - self.hostView.containerView.layer.adjustTraceableLayerTransforms(CGSize()) - var animatedUpdate = false - if let updatingLayout = self.updatingLayout { - if case .animated = updatingLayout.transition { - animatedUpdate = true - } - } - self.cachedWindowSubviewCount = self.hostView.containerView.window?.subviews.count ?? 0 - statusBarManager.updateState(surfaces: statusBarSurfaces, withSafeInsets: !self.windowLayout.safeInsets.top.isZero, forceInCallStatusBarText: self.forceInCallStatusBarText, forceHiddenBySystemWindows: hasPreview, animated: animatedUpdate) - } - - var keyboardSurfaces: [KeyboardSurface] = [] - for layers in self.hostView.containerView.layer.traceableLayerSurfaces(withTag: WindowTracingTags.keyboard) { - for layer in layers { - if let view = layer.delegate as? UITracingLayerView { - keyboardSurfaces.append(KeyboardSurface(host: view)) - } - } - } - //keyboardManager.surfaces = keyboardSurfaces*/ - var supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .all) let orientationToLock: UIInterfaceOrientationMask if self.windowLayout.size.width < self.windowLayout.size.height { @@ -1085,9 +992,6 @@ public class Window1 { }) } - //self.volumeControlStatusBarNode.frame = CGRect(origin: CGPoint(), size: self.windowLayout.size) - //self.volumeControlStatusBarNode.updateLayout(layout: childLayout, transition: updatingLayout.transition) - if let coveringView = self.coveringView { coveringView.frame = CGRect(origin: CGPoint(), size: self.windowLayout.size) coveringView.updateLayout(self.windowLayout.size) @@ -1111,7 +1015,11 @@ public class Window1 { self.presentationContext.present(controller, on: level, blockInteraction: blockInteraction, completion: completion) } } else { - self.presentationContext.present(controller, on: level, blockInteraction: blockInteraction, completion: completion) + if let controller = controller as? ViewController, controller.presentedOverCoveringView { + self.topPresentationContext.present(controller, on: level, completion: completion) + } else { + self.presentationContext.present(controller, on: level, blockInteraction: blockInteraction, completion: completion) + } } } @@ -1270,5 +1178,10 @@ public class Window1 { break } } + for (controller, _) in self.topPresentationContext.controllers { + if !f(controller) { + break + } + } } } diff --git a/submodules/ImageBlur/Sources/ApplyScreenshotEffect.m b/submodules/ImageBlur/Sources/ApplyScreenshotEffect.m index 769a870df3..8cfd8109b5 100644 --- a/submodules/ImageBlur/Sources/ApplyScreenshotEffect.m +++ b/submodules/ImageBlur/Sources/ApplyScreenshotEffect.m @@ -133,6 +133,5 @@ UIImage * _Nullable applyBlurWithRadius(UIImage *image, CGFloat blurRadius, UICo } UIImage * _Nullable applyScreenshotEffectToImage(UIImage * _Nonnull image) { - UIColor *tintColor = [UIColor colorWithWhite:1.0f alpha:0.3f]; - return applyBlurWithRadius(image, 10.0f, tintColor, 1.8f, nil); + return applyBlurWithRadius(image, 10.0f, nil, 1.8f, nil); } diff --git a/submodules/MediaResources/Sources/MapResources.swift b/submodules/MediaResources/Sources/MapResources.swift index b0991ec29d..d7ef9ea20a 100644 --- a/submodules/MediaResources/Sources/MapResources.swift +++ b/submodules/MediaResources/Sources/MapResources.swift @@ -69,6 +69,25 @@ public class MapSnapshotMediaResource: TelegramMediaResource { } } +public final class MapSnapshotMediaResourceRepresentation: CachedMediaResourceRepresentation { + public let keepDuration: CachedMediaRepresentationKeepDuration = .shortLived + + public var uniqueId: String { + return "cached" + } + + public init() { + } + + public func isEqual(to: CachedMediaResourceRepresentation) -> Bool { + if let to = to as? MapSnapshotMediaResourceRepresentation { + return true + } else { + return false + } + } +} + let TGGoogleMapsOffset: Int = 268435456 let TGGoogleMapsRadius = Double(TGGoogleMapsOffset) / Double.pi @@ -85,7 +104,7 @@ private func adjustGMapLatitude(_ latitude: Double, offset: Int, zoom: Int) -> D return yToLatitude(latitudeToY(latitude) + t) } -public func fetchMapSnapshotResource(resource: MapSnapshotMediaResource) -> Signal { +public func fetchMapSnapshotResource(resource: MapSnapshotMediaResource) -> Signal { return Signal { subscriber in let disposable = MetaDisposable() @@ -96,14 +115,17 @@ public func fetchMapSnapshotResource(resource: MapSnapshotMediaResource) -> Sign options.mapType = .standard options.showsPointsOfInterest = false options.showsBuildings = true - options.size = CGSize(width: CGFloat(resource.width + 1), height: CGFloat(resource.height + 24)) + options.size = CGSize(width: CGFloat(resource.width + 1), height: CGFloat(resource.height + 10)) options.scale = 2.0 let snapshotter = MKMapSnapshotter(options: options) snapshotter.start(with: DispatchQueue.global(), completionHandler: { result, error in if let image = result?.image { if let data = image.jpegData(compressionQuality: 0.9) { - subscriber.putNext(MediaResourceDataFetchResult.dataPart(resourceOffset: 0, data: data, range: 0 ..< data.count, complete: true)) - subscriber.putCompletion() + let tempFile = TempBox.shared.tempFile(fileName: "image.jpg") + if let _ = try? data.write(to: URL(fileURLWithPath: tempFile.path), options: .atomic) { + subscriber.putNext(.tempFile(tempFile)) + subscriber.putCompletion() + } } } }) diff --git a/submodules/OverlayStatusController/Sources/OverlayStatusController.swift b/submodules/OverlayStatusController/Sources/OverlayStatusController.swift index a7e5bb0a97..7f1bc3e084 100644 --- a/submodules/OverlayStatusController/Sources/OverlayStatusController.swift +++ b/submodules/OverlayStatusController/Sources/OverlayStatusController.swift @@ -179,8 +179,9 @@ private final class OverlayStatusControllerImpl: ViewController, StandalonePrese } } - public func dismiss() { + override public func dismiss(completion: (() -> Void)? = nil) { self.controllerNode.dismiss() + completion?() } } diff --git a/submodules/PasscodeUI/Sources/PasscodeEntryController.swift b/submodules/PasscodeUI/Sources/PasscodeEntryController.swift index 7c3f31ecbc..e6f5a5062e 100644 --- a/submodules/PasscodeUI/Sources/PasscodeEntryController.swift +++ b/submodules/PasscodeUI/Sources/PasscodeEntryController.swift @@ -191,6 +191,10 @@ public final class PasscodeEntryController: ViewController { } } + public func ensureInputFocused() { + self.controllerNode.activateInput() + } + public func requestBiometrics(force: Bool = false) { guard case let .enabled(data) = self.biometrics, let _ = LocalAuth.biometricAuthentication else { return diff --git a/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift b/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift index 01c31ae65e..700dcd0d38 100644 --- a/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift +++ b/submodules/PeerInfoUI/Sources/GroupsInCommonController.swift @@ -218,6 +218,8 @@ private final class ContextControllerContentSourceImpl: ContextControllerContent let controller: ViewController weak var sourceNode: ASDisplayNode? + let navigationController: NavigationController? = nil + init(controller: ViewController, sourceNode: ASDisplayNode?) { self.controller = controller self.sourceNode = sourceNode diff --git a/submodules/PhotoResources/Sources/PhotoResources.swift b/submodules/PhotoResources/Sources/PhotoResources.swift index 12906f7b03..c3f6d0eec7 100644 --- a/submodules/PhotoResources/Sources/PhotoResources.swift +++ b/submodules/PhotoResources/Sources/PhotoResources.swift @@ -2471,15 +2471,13 @@ public func chatAvatarGalleryPhoto(account: Account, representations: [ImageRepr public func chatMapSnapshotData(account: Account, resource: MapSnapshotMediaResource) -> Signal { return Signal { subscriber in - let fetchedDisposable = account.postbox.mediaBox.fetchedResource(resource, parameters: nil).start() - let dataDisposable = account.postbox.mediaBox.resourceData(resource).start(next: { next in + let dataDisposable = account.postbox.mediaBox.cachedResourceRepresentation(resource, representation: MapSnapshotMediaResourceRepresentation(), complete: true).start(next: { next in if next.size != 0 { subscriber.putNext(next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: [])) } }, error: subscriber.putError, completed: subscriber.putCompletion) return ActionDisposable { - fetchedDisposable.dispose() dataDisposable.dispose() } } diff --git a/submodules/SSignalKit/SSignalKit/SSignalKit.h b/submodules/SSignalKit/SSignalKit/SSignalKit.h index 9842a184e1..2c6679ff51 100644 --- a/submodules/SSignalKit/SSignalKit/SSignalKit.h +++ b/submodules/SSignalKit/SSignalKit/SSignalKit.h @@ -1,11 +1,3 @@ -// -// SSignalKit.h -// SSignalKit -// -// Created by Peter on 31/01/15. -// Copyright (c) 2015 Telegram. All rights reserved. -// - #if __IPHONE_OS_VERSION_MIN_REQUIRED #import #else diff --git a/submodules/SettingsUI/Sources/SettingsController.swift b/submodules/SettingsUI/Sources/SettingsController.swift index e6dd35ff15..80e3e34461 100644 --- a/submodules/SettingsUI/Sources/SettingsController.swift +++ b/submodules/SettingsUI/Sources/SettingsController.swift @@ -44,6 +44,8 @@ private final class ContextControllerContentSourceImpl: ContextControllerContent let controller: ViewController weak var sourceNode: ASDisplayNode? + let navigationController: NavigationController? = nil + init(controller: ViewController, sourceNode: ASDisplayNode?) { self.controller = controller self.sourceNode = sourceNode diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index 071c7451fd..90ecb2ab68 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -20,6 +20,8 @@ private final class ContextControllerContentSourceImpl: ContextControllerContent let controller: ViewController weak var sourceNode: ASDisplayNode? + let navigationController: NavigationController? = nil + init(controller: ViewController, sourceNode: ASDisplayNode?) { self.controller = controller self.sourceNode = sourceNode