From d91ec1bac796d66a3e1d7451225ffb55d7007bfc Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 15 Dec 2020 07:03:26 +0400 Subject: [PATCH] Various UI fixes --- .../Sources/GalleryController.swift | 5 +++-- .../GalleryUI/Sources/GalleryController.swift | 15 +++++++++++-- .../TGMediaPickerGalleryInterfaceView.h | 1 + .../TGMediaPickerGalleryModel.h | 1 + .../LegacyComponents/TGPhotoVideoEditor.h | 2 +- .../TGMediaPickerGalleryInterfaceView.m | 16 ++++++++++++++ .../Sources/TGMediaPickerGalleryModel.m | 14 +++++++++++++ .../Sources/TGPhotoVideoEditor.m | 16 +++++++++++--- .../Sources/LegacyAttachmentMenu.swift | 21 +++++++------------ .../TelegramUI/Sources/ChatController.swift | 8 ++++--- 10 files changed, 74 insertions(+), 25 deletions(-) diff --git a/submodules/AccountContext/Sources/GalleryController.swift b/submodules/AccountContext/Sources/GalleryController.swift index 5ac13919b4..376252b271 100644 --- a/submodules/AccountContext/Sources/GalleryController.swift +++ b/submodules/AccountContext/Sources/GalleryController.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit import Postbox import SwiftSignalKit import TelegramCore @@ -18,9 +19,9 @@ public final class GalleryControllerActionInteraction { public let openBotCommand: (String) -> Void public let addContact: (String) -> Void public let storeMediaPlaybackState: (MessageId, Double?) -> Void - public let editMedia: (MessageId) -> Void + public let editMedia: (MessageId, [UIView], @escaping () -> Void) -> Void - public init(openUrl: @escaping (String, Bool) -> Void, openUrlIn: @escaping (String) -> Void, openPeerMention: @escaping (String) -> Void, openPeer: @escaping (PeerId) -> Void, openHashtag: @escaping (String?, String) -> Void, openBotCommand: @escaping (String) -> Void, addContact: @escaping (String) -> Void, storeMediaPlaybackState: @escaping (MessageId, Double?) -> Void, editMedia: @escaping (MessageId) -> Void) { + public init(openUrl: @escaping (String, Bool) -> Void, openUrlIn: @escaping (String) -> Void, openPeerMention: @escaping (String) -> Void, openPeer: @escaping (PeerId) -> Void, openHashtag: @escaping (String?, String) -> Void, openBotCommand: @escaping (String) -> Void, addContact: @escaping (String) -> Void, storeMediaPlaybackState: @escaping (MessageId, Double?) -> Void, editMedia: @escaping (MessageId, [UIView], @escaping () -> Void) -> Void) { self.openUrl = openUrl self.openUrlIn = openUrlIn self.openPeerMention = openPeerMention diff --git a/submodules/GalleryUI/Sources/GalleryController.swift b/submodules/GalleryUI/Sources/GalleryController.swift index d58550f98f..dab45a332d 100644 --- a/submodules/GalleryUI/Sources/GalleryController.swift +++ b/submodules/GalleryUI/Sources/GalleryController.swift @@ -913,8 +913,19 @@ public class GalleryController: ViewController, StandalonePresentableController } }, editMedia: { [weak self] messageId in if let strongSelf = self { - strongSelf.dismiss(forceAway: true) - strongSelf.actionInteraction?.editMedia(messageId) + var snapshots: [UIView] = [] + if let navigationBar = strongSelf.navigationBar, let snapshotView = navigationBar.view.snapshotContentTree() { + snapshotView.frame = navigationBar.frame + snapshots.append(snapshotView) + } + if let snapshotView = strongSelf.galleryNode.footerNode.view.snapshotContentTree() { + snapshotView.frame = strongSelf.galleryNode.footerNode.frame + snapshots.append(snapshotView) + } + + strongSelf.actionInteraction?.editMedia(messageId, snapshots, { [weak self] in + self?.dismiss(forceAway: true) + }) } }) self.displayNode = GalleryControllerNode(controllerInteraction: controllerInteraction) diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryInterfaceView.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryInterfaceView.h index 062b5e8e0e..8c9bd087fe 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryInterfaceView.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryInterfaceView.h @@ -51,6 +51,7 @@ - (void)setAllInterfaceHidden:(bool)hidden delay:(NSTimeInterval)__unused delay animated:(bool)animated; - (void)setToolbarsHidden:(bool)hidden animated:(bool)animated; +- (void)immediateEditorTransitionIn; - (void)editorTransitionIn; - (void)editorTransitionOut; diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryModel.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryModel.h index af5300772c..b127c421e4 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryModel.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaPickerGalleryModel.h @@ -51,5 +51,6 @@ - (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName; - (void)presentPhotoEditorForItem:(id)item tab:(TGPhotoEditorTab)tab; +- (void)presentPhotoEditorForItem:(id)item tab:(TGPhotoEditorTab)tab snapshots:(NSArray *)snapshots; @end diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h index 7667dcf382..5db73d5a2b 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGPhotoVideoEditor.h @@ -4,6 +4,6 @@ + (void)presentWithContext:(id)context parentController:(TGViewController *)parentController image:(UIImage *)image video:(NSURL *)video didFinishWithImage:(void (^)(UIImage *image))didFinishWithImage didFinishWithVideo:(void (^)(UIImage *image, NSURL *url, TGVideoEditAdjustments *adjustments))didFinishWithVideo dismissed:(void (^)(void))dismissed; -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item paint:(bool)paint recipientName:(NSString *)recipientName stickersContext:(id)stickersContext completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed; ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item paint:(bool)paint recipientName:(NSString *)recipientName stickersContext:(id)stickersContext snapshots:(NSArray *)snapshots immediate:(bool)immediate appeared:(void (^)(void))appeared completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed; @end diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m index 1b210ffa7d..da2484ce0f 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m @@ -1307,6 +1307,22 @@ } } +- (void)immediateEditorTransitionIn { + [self setSelectionInterfaceHidden:true animated:false]; + _captionMixin.inputPanel.alpha = 0.0f; + _portraitToolbarView.doneButton.alpha = 0.0f; + _landscapeToolbarView.doneButton.alpha = 0.0f; + + _portraitToolbarView.hidden = true; + _landscapeToolbarView.hidden = true; + + TGDispatchAfter(0.5, dispatch_get_main_queue(), ^ + { + _portraitToolbarView.hidden = false; + _landscapeToolbarView.hidden = false; + }); +} + - (void)editorTransitionIn { [self setSelectionInterfaceHidden:true animated:true]; diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m index 159db145a1..8da4a30f77 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryModel.m @@ -344,6 +344,11 @@ } - (void)presentPhotoEditorForItem:(id)item tab:(TGPhotoEditorTab)tab +{ + [self presentPhotoEditorForItem:item tab:tab snapshots:@[]]; +} + +- (void)presentPhotoEditorForItem:(id)item tab:(TGPhotoEditorTab)tab snapshots:(NSArray *)snapshots { __weak TGMediaPickerGalleryModel *weakSelf = self; @@ -604,6 +609,15 @@ [self.controller addChildViewController:controller]; [self.controller.view addSubview:controller.view]; + + for (UIView *view in snapshots) { + [self.controller.view addSubview:view]; + [UIView animateWithDuration:0.3 animations:^{ + view.alpha = 0.0; + } completion:^(__unused BOOL finished) { + [view removeFromSuperview]; + }]; + } } - (void)_replaceItems:(NSArray *)items focusingOnItem:(id)item diff --git a/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m b/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m index 022a16f725..09a5887a24 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m +++ b/submodules/LegacyComponents/Sources/TGPhotoVideoEditor.m @@ -102,7 +102,7 @@ } } -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item paint:(bool)paint recipientName:(NSString *)recipientName stickersContext:(id)stickersContext completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item paint:(bool)paint recipientName:(NSString *)recipientName stickersContext:(id)stickersContext snapshots:(NSArray *)snapshots immediate:(bool)immediate appeared:(void (^)(void))appeared completion:(void (^)(id, TGMediaEditingContext *))completion dismissed:(void (^)())dismissed { id windowManager = [context makeOverlayWindowManager]; id windowContext = [windowManager context]; @@ -112,6 +112,10 @@ TGModernGalleryController *galleryController = [[TGModernGalleryController alloc] initWithContext:windowContext]; galleryController.adjustsStatusBarVisibility = true; + galleryController.animateTransition = !immediate; + galleryController.finishedTransitionIn = ^(id item, TGModernGalleryItemView *itemView) { + appeared(); + }; //galleryController.hasFadeOutTransition = true; id galleryItem = nil; @@ -199,14 +203,20 @@ dismissed(); } }; - + + [model.interfaceView immediateEditorTransitionIn]; + + for (UIView *view in snapshots) { + [galleryController.view addSubview:view]; + } + TGOverlayControllerWindow *controllerWindow = [[TGOverlayControllerWindow alloc] initWithManager:windowManager parentController:controller contentController:galleryController]; controllerWindow.hidden = false; galleryController.view.clipsToBounds = true; if (paint) { TGDispatchAfter(0.05, dispatch_get_main_queue(), ^{ - [model presentPhotoEditorForItem:galleryItem tab:TGPhotoEditorPaintTab]; + [model presentPhotoEditorForItem:galleryItem tab:TGPhotoEditorPaintTab snapshots:snapshots]; }); } } diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift index 67603bbb04..422ce445e1 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift @@ -59,7 +59,7 @@ public enum LegacyAttachmentMenuMediaEditing { case file } -public func legacyMediaEditor(context: AccountContext, peer: Peer, media: AnyMediaReference, initialCaption: String, presentStickers: @escaping (@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> TGPhotoPaintStickersScreen?, sendMessagesWithSignals: @escaping ([Any]?, Bool, Int32) -> Void, present: @escaping (ViewController, Any?) -> Void) { +public func legacyMediaEditor(context: AccountContext, peer: Peer, media: AnyMediaReference, initialCaption: String, snapshots: [UIView], transitionCompletion: (() -> Void)?, presentStickers: @escaping (@escaping (TelegramMediaFile, Bool, UIView, CGRect) -> Void) -> TGPhotoPaintStickersScreen?, sendMessagesWithSignals: @escaping ([Any]?, Bool, Int32) -> Void, present: @escaping (ViewController, Any?) -> Void) { let _ = (fetchMediaData(context: context, postbox: context.account.postbox, mediaReference: media) |> deliverOnMainQueue).start(next: { (value, isImage) in guard case let .data(data) = value, data.complete else { @@ -103,8 +103,9 @@ public func legacyMediaEditor(context: AccountContext, peer: Peer, media: AnyMed present(legacyController, nil) - TGPhotoVideoEditor.present(with: legacyController.context, controller: emptyController, caption: initialCaption, entities: [], withItem: item, paint: true, recipientName: recipientName, stickersContext: paintStickersContext, completion: { result, editingContext in - let intent: TGMediaAssetsControllerIntent = TGMediaAssetsControllerSendMediaIntent + TGPhotoVideoEditor.present(with: legacyController.context, controller: emptyController, caption: initialCaption, entities: [], withItem: item, paint: true, recipientName: recipientName, stickersContext: paintStickersContext, snapshots: snapshots as? [Any], immediate: transitionCompletion != nil, appeared: { + transitionCompletion?() + }, completion: { result, editingContext in let signals = TGCameraController.resultSignals(for: nil, editingContext: editingContext, currentItem: result as! TGMediaSelectableItem, storeAssets: false, saveEditedPhotos: false, descriptionGenerator: legacyAssetPickerItemGenerator()) sendMessagesWithSignals(signals, false, 0) }, dismissed: { [weak legacyController] in @@ -294,16 +295,8 @@ public func legacyAttachmentMenu(context: AccountContext, peer: Peer, chatLocati navigationController.setNavigationBarHidden(true, animated: false) legacyController.bind(controller: navigationController) - var hasTimer = false - var hasSilentPosting = false - if peer.id != context.account.peerId { - if peer is TelegramUser { - hasTimer = true - } - hasSilentPosting = true - } let recipientName = peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) - + legacyController.enableSizeClassSignal = true let presentationDisposable = context.sharedContext.presentationData.start(next: { [weak legacyController] presentationData in @@ -315,8 +308,8 @@ public func legacyAttachmentMenu(context: AccountContext, peer: Peer, chatLocati present(legacyController, nil) - TGPhotoVideoEditor.present(with: legacyController.context, controller: emptyController, caption: "", entities: [], withItem: item, paint: false, recipientName: recipientName, stickersContext: paintStickersContext, completion: { result, editingContext in - let intent: TGMediaAssetsControllerIntent = TGMediaAssetsControllerSendMediaIntent + TGPhotoVideoEditor.present(with: legacyController.context, controller: emptyController, caption: "", entities: [], withItem: item, paint: false, recipientName: recipientName, stickersContext: paintStickersContext, snapshots: [], immediate: false, appeared: { + }, completion: { result, editingContext in let signals = TGCameraController.resultSignals(for: nil, editingContext: editingContext, currentItem: result as! TGMediaSelectableItem, storeAssets: false, saveEditedPhotos: false, descriptionGenerator: legacyAssetPickerItemGenerator()) sendMessagesWithSignals(signals, false, 0) }, dismissed: { [weak legacyController] in diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index f939d0b11d..a03936c628 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -688,7 +688,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G storedState = MediaPlaybackStoredState(timestamp: timestamp, playbackRate: .x1) } let _ = updateMediaPlaybackStoredStateInteractively(postbox: strongSelf.context.account.postbox, messageId: messageId, state: storedState).start() - }, editMedia: { [weak self] messageId in + }, editMedia: { [weak self] messageId, snapshots, transitionCompletion in guard let strongSelf = self else { return } @@ -708,7 +708,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } if let mediaReference = mediaReference, let peer = message.peers[message.id.peerId] { - legacyMediaEditor(context: strongSelf.context, peer: peer, media: mediaReference, initialCaption: message.text, presentStickers: { [weak self] completion in + legacyMediaEditor(context: strongSelf.context, peer: peer, media: mediaReference, initialCaption: message.text, snapshots: snapshots, transitionCompletion: { + transitionCompletion() + }, presentStickers: { [weak self] completion in if let strongSelf = self { let controller = DrawingStickersScreen(context: strongSelf.context, selectSticker: { fileReference, node, rect in completion(fileReference.media, fileReference.media.isAnimatedSticker, node.view, rect) @@ -2377,7 +2379,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } if let mediaReference = mediaReference, let peer = message.peers[message.id.peerId] { - legacyMediaEditor(context: strongSelf.context, peer: peer, media: mediaReference, initialCaption: message.text, presentStickers: { [weak self] completion in + legacyMediaEditor(context: strongSelf.context, peer: peer, media: mediaReference, initialCaption: message.text, snapshots: [], transitionCompletion: nil, presentStickers: { [weak self] completion in if let strongSelf = self { let controller = DrawingStickersScreen(context: strongSelf.context, selectSticker: { fileReference, node, rect in completion(fileReference.media, fileReference.media.isAnimatedSticker, node.view, rect)