diff --git a/submodules/AttachmentUI/Sources/AttachmentController.swift b/submodules/AttachmentUI/Sources/AttachmentController.swift index 522ee00d63..09fcf5f202 100644 --- a/submodules/AttachmentUI/Sources/AttachmentController.swift +++ b/submodules/AttachmentUI/Sources/AttachmentController.swift @@ -22,7 +22,7 @@ public enum AttachmentButtonType: Equatable { public protocol AttachmentContainable: ViewController { var requestAttachmentMenuExpansion: () -> Void { get set } - var updateNavigationStack: (@escaping ([AttachmentContainable]) -> [AttachmentContainable]) -> Void { get set } + var updateNavigationStack: (@escaping ([AttachmentContainable]) -> ([AttachmentContainable], AttachmentMediaPickerContext?)) -> Void { get set } var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void { get set } var cancelPanGesture: () -> Void { get set } @@ -298,7 +298,9 @@ public class AttachmentController: ViewController { } controller.updateNavigationStack = { [weak self] f in if let strongSelf = self { - strongSelf.currentControllers = f(strongSelf.currentControllers) + let (controllers, mediaPickerContext) = f(strongSelf.currentControllers) + strongSelf.currentControllers = controllers + strongSelf.mediaPickerContext = mediaPickerContext if let layout = strongSelf.validLayout { strongSelf.containerLayoutUpdated(layout, transition: .animated(duration: 0.4, curve: .spring)) } diff --git a/submodules/ComposePollUI/Sources/CreatePollController.swift b/submodules/ComposePollUI/Sources/CreatePollController.swift index cf94154189..a11dc5f509 100644 --- a/submodules/ComposePollUI/Sources/CreatePollController.swift +++ b/submodules/ComposePollUI/Sources/CreatePollController.swift @@ -518,7 +518,7 @@ public final class ComposedPoll { private class CreatePollControllerImpl: ItemListController, AttachmentContainable { public var requestAttachmentMenuExpansion: () -> Void = {} - public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> [AttachmentContainable]) -> Void = { _ in } + public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> ([AttachmentContainable], AttachmentMediaPickerContext?)) -> Void = { _ in } public var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void = { _, _ in } public var cancelPanGesture: () -> Void = { } } diff --git a/submodules/LegacyUI/Sources/LegacyController.swift b/submodules/LegacyUI/Sources/LegacyController.swift index f8b851b42a..eb8ea5f944 100644 --- a/submodules/LegacyUI/Sources/LegacyController.swift +++ b/submodules/LegacyUI/Sources/LegacyController.swift @@ -406,7 +406,7 @@ open class LegacyController: ViewController, PresentableController, AttachmentCo public var disposables = DisposableSet() open var requestAttachmentMenuExpansion: () -> Void = {} - open var updateNavigationStack: (@escaping ([AttachmentContainable]) -> [AttachmentContainable]) -> Void = { _ in } + open var updateNavigationStack: (@escaping ([AttachmentContainable]) -> ([AttachmentContainable], AttachmentMediaPickerContext?)) -> Void = { _ in } open var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void = { _, _ in } open var cancelPanGesture: () -> Void = { } diff --git a/submodules/LocationUI/Sources/LocationPickerController.swift b/submodules/LocationUI/Sources/LocationPickerController.swift index 90d643b12e..5dace1b7f1 100644 --- a/submodules/LocationUI/Sources/LocationPickerController.swift +++ b/submodules/LocationUI/Sources/LocationPickerController.swift @@ -72,7 +72,7 @@ public final class LocationPickerController: ViewController, AttachmentContainab private var interaction: LocationPickerInteraction? public var requestAttachmentMenuExpansion: () -> Void = {} - public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> [AttachmentContainable]) -> Void = { _ in } + public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> ([AttachmentContainable], AttachmentMediaPickerContext?)) -> Void = { _ in } public var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void = { _, _ in } public var cancelPanGesture: () -> Void = { } diff --git a/submodules/LocationUI/Sources/LocationPickerControllerNode.swift b/submodules/LocationUI/Sources/LocationPickerControllerNode.swift index e539daae1d..65b39f4240 100644 --- a/submodules/LocationUI/Sources/LocationPickerControllerNode.swift +++ b/submodules/LocationUI/Sources/LocationPickerControllerNode.swift @@ -298,7 +298,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM private var placeholderBackgroundNode: NavigationBackgroundNode? private var placeholderNode: LocationPlaceholderNode? - private var locationAccessDenied = true + private var locationAccessDenied = false private var enqueuedTransitions: [LocationPickerTransaction] = [] @@ -994,6 +994,10 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM self.placeholderNode = nil placeholderNode.removeFromSupernode() } + if let placeholderBackgroundNode = self.placeholderBackgroundNode { + self.placeholderBackgroundNode = nil + placeholderBackgroundNode.removeFromSupernode() + } self.controller?.updateTabBarAlpha(1.0, .immediate) } diff --git a/submodules/MediaPickerUI/Sources/LegacyMediaPickerGallery.swift b/submodules/MediaPickerUI/Sources/LegacyMediaPickerGallery.swift index 1b4b7058eb..11c67686bb 100644 --- a/submodules/MediaPickerUI/Sources/LegacyMediaPickerGallery.swift +++ b/submodules/MediaPickerUI/Sources/LegacyMediaPickerGallery.swift @@ -74,7 +74,7 @@ enum LegacyMediaPickerGallerySource { case selection(item: TGMediaSelectableItem) } -func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?, chatLocation: ChatLocation?, presentationData: PresentationData, source: LegacyMediaPickerGallerySource, immediateThumbnail: UIImage?, selectionContext: TGMediaSelectionContext?, editingContext: TGMediaEditingContext, hasSilentPosting: Bool, hasSchedule: Bool, hasTimer: Bool, updateHiddenMedia: @escaping (String?) -> Void, initialLayout: ContainerViewLayout?, transitionHostView: @escaping () -> UIView?, transitionView: @escaping (String) -> UIView?, completed: @escaping (TGMediaSelectableItem & TGMediaEditableItem, Bool, Int32?) -> Void, presentStickers: ((@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> TGPhotoPaintStickersScreen?)?, presentSchedulePicker: @escaping (Bool, @escaping (Int32) -> Void) -> Void, presentTimerPicker: @escaping (@escaping (Int32) -> Void) -> Void, getCaptionPanelView: @escaping () -> TGCaptionPanelView?, present: @escaping (ViewController, Any?) -> Void, finishedTransitionIn: @escaping () -> Void) { +func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?, chatLocation: ChatLocation?, presentationData: PresentationData, source: LegacyMediaPickerGallerySource, immediateThumbnail: UIImage?, selectionContext: TGMediaSelectionContext?, editingContext: TGMediaEditingContext, hasSilentPosting: Bool, hasSchedule: Bool, hasTimer: Bool, updateHiddenMedia: @escaping (String?) -> Void, initialLayout: ContainerViewLayout?, transitionHostView: @escaping () -> UIView?, transitionView: @escaping (String) -> UIView?, completed: @escaping (TGMediaSelectableItem & TGMediaEditableItem, Bool, Int32?) -> Void, presentStickers: ((@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> TGPhotoPaintStickersScreen?)?, presentSchedulePicker: @escaping (Bool, @escaping (Int32) -> Void) -> Void, presentTimerPicker: @escaping (@escaping (Int32) -> Void) -> Void, getCaptionPanelView: @escaping () -> TGCaptionPanelView?, present: @escaping (ViewController, Any?) -> Void, finishedTransitionIn: @escaping () -> Void, dismissAll: @escaping () -> Void) { let reminder = peer?.id == context.account.peerId let legacyController = LegacyController(presentation: .custom, theme: presentationData.theme, initialLayout: nil) @@ -186,10 +186,12 @@ func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?, updateHiddenMedia(nil) legacyController?.dismiss() } + model.interfaceView.donePressed = { [weak controller] item in if let item = item as? TGMediaPickerGalleryItem { controller?.dismissWhenReady(animated: true) - completed(item.asset, false, nil) + completed(item.asset, false, nil) + dismissAll() } } model.interfaceView.doneLongPressed = { [weak selectionContext, weak editingContext, weak legacyController, weak model] item in diff --git a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift index c8b5f74c42..cd61bf837e 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift @@ -101,10 +101,12 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { public var legacyCompletion: (_ signals: [Any], _ silently: Bool, _ scheduleTime: Int32?) -> Void = { _, _, _ in } public var requestAttachmentMenuExpansion: () -> Void = { } - public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> [AttachmentContainable]) -> Void = { _ in } + public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> ([AttachmentContainable], AttachmentMediaPickerContext?)) -> Void = { _ in } public var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void = { _, _ in } public var cancelPanGesture: () -> Void = { } + var dismissAll: () -> Void = { } + private class Node: ViewControllerTracingNode, UIGestureRecognizerDelegate { enum DisplayMode { case all @@ -165,9 +167,13 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self.backgroundNode = NavigationBackgroundNode(color: self.presentationData.theme.rootController.tabBar.backgroundColor) self.backgroundNode.backgroundColor = self.presentationData.theme.list.plainBackgroundColor self.gridNode = GridNode() - + super.init() - + + if controller.collection != nil { + self.preloadPromise.set(false) + } + self.addSubnode(self.containerNode) self.containerNode.addSubnode(self.backgroundNode) self.containerNode.addSubnode(self.gridNode) @@ -492,8 +498,10 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { } }, presentStickers: controller.presentStickers, presentSchedulePicker: controller.presentSchedulePicker, presentTimerPicker: controller.presentTimerPicker, getCaptionPanelView: controller.getCaptionPanelView, present: { [weak self] c, a in self?.controller?.present(c, in: .window(.root), with: a) - }, finishedTransitionIn: { - self.openingMedia = false + }, finishedTransitionIn: { [weak self] in + self?.openingMedia = false + }, dismissAll: { [weak self] in + self?.controller?.dismissAll() }) } @@ -523,8 +531,10 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { } }, presentStickers: controller.presentStickers, presentSchedulePicker: controller.presentSchedulePicker, presentTimerPicker: controller.presentTimerPicker, getCaptionPanelView: controller.getCaptionPanelView, present: { [weak self] c, a in self?.controller?.present(c, in: .window(.root), with: a, blockInteraction: true) - }, finishedTransitionIn: { - self.openingMedia = false + }, finishedTransitionIn: { [weak self] in + self?.openingMedia = false + }, dismissAll: { [weak self] in + self?.controller?.dismissAll() }) } @@ -986,6 +996,8 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { } }, selectionState: selectionContext ?? TGMediaSelectionContext(), editingState: editingContext ?? TGMediaEditingContext()) self.interaction?.selectionState?.grouping = true + + self.updateSelectionState(count: Int32(selectionContext?.count() ?? 0)) } required init(coder aDecoder: NSCoder) { @@ -1032,7 +1044,11 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { @objc private func backPressed() { self.updateNavigationStack { current in - return current.filter { $0 !== self } + var mediaPickerContext: AttachmentMediaPickerContext? + if let first = current.first as? MediaPickerScreen { + mediaPickerContext = first.webSearchController?.mediaPickerContext ?? first.mediaPickerContext + } + return (current.filter { $0 !== self }, mediaPickerContext) } } @@ -1079,9 +1095,19 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { } if collection.assetCollectionSubtype != .smartAlbumUserLibrary { let mediaPicker = MediaPickerScreen(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, peer: strongSelf.peer, chatLocation: strongSelf.chatLocation, bannedSendMedia: strongSelf.bannedSendMedia, collection: collection, editingContext: strongSelf.interaction?.editingState, selectionContext: strongSelf.interaction?.selectionState) + + mediaPicker.presentStickers = strongSelf.presentStickers + mediaPicker.presentSchedulePicker = strongSelf.presentSchedulePicker + mediaPicker.presentTimerPicker = strongSelf.presentTimerPicker + mediaPicker.getCaptionPanelView = strongSelf.getCaptionPanelView + mediaPicker.legacyCompletion = strongSelf.legacyCompletion + mediaPicker.dismissAll = { [weak self] in + self?.dismiss(animated: true, completion: nil) + } + mediaPicker._presentedInModal = true mediaPicker.updateNavigationStack = strongSelf.updateNavigationStack - strongSelf.updateNavigationStack({ _ in return [strongSelf, mediaPicker]}) + strongSelf.updateNavigationStack({ _ in return ([strongSelf, mediaPicker], strongSelf.mediaPickerContext)}) } } })) diff --git a/submodules/TelegramUI/Sources/AttachmentFileController.swift b/submodules/TelegramUI/Sources/AttachmentFileController.swift index f39f6cdf7a..dc7d2b2917 100644 --- a/submodules/TelegramUI/Sources/AttachmentFileController.swift +++ b/submodules/TelegramUI/Sources/AttachmentFileController.swift @@ -165,7 +165,7 @@ private func attachmentFileControllerEntries(presentationData: PresentationData, private class AttachmentFileControllerImpl: ItemListController, AttachmentContainable { public var requestAttachmentMenuExpansion: () -> Void = {} - public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> [AttachmentContainable]) -> Void = { _ in } + public var updateNavigationStack: (@escaping ([AttachmentContainable]) -> ([AttachmentContainable], AttachmentMediaPickerContext?)) -> Void = { _ in } public var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void = { _, _ in } public var cancelPanGesture: () -> Void = { } diff --git a/submodules/TelegramUI/Sources/ContactSelectionController.swift b/submodules/TelegramUI/Sources/ContactSelectionController.swift index 3baf874ab4..f805c0e89d 100644 --- a/submodules/TelegramUI/Sources/ContactSelectionController.swift +++ b/submodules/TelegramUI/Sources/ContactSelectionController.swift @@ -76,7 +76,7 @@ class ContactSelectionControllerImpl: ViewController, ContactSelectionController } var requestAttachmentMenuExpansion: () -> Void = {} - var updateNavigationStack: (@escaping ([AttachmentContainable]) -> [AttachmentContainable]) -> Void = { _ in } + var updateNavigationStack: (@escaping ([AttachmentContainable]) -> ([AttachmentContainable], AttachmentMediaPickerContext?)) -> Void = { _ in } var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void = { _, _ in } var cancelPanGesture: () -> Void = { }