From 0874d92b11f28daa792797b1bcdd44df4ec09ba2 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 27 Feb 2022 17:19:12 +0400 Subject: [PATCH] Various fixes --- .../Sources/AttachmentController.swift | 3 +- submodules/ChatMessageBackground/BUILD | 21 +++++++++++ submodules/ChatMessageBackground/Info.plist | 22 ++++++++++++ .../Sources/ChatMessageBackground.swift | 35 ++++++++++--------- .../TGMediaPickerGalleryInterfaceView.m | 2 +- .../Sources/TGPhotoCaptionInputMixin.m | 12 +++++-- submodules/MediaPickerUI/BUILD | 1 + .../Sources/LegacyMediaPickerGallery.swift | 4 ++- .../Sources/MediaPickerScreen.swift | 6 ++++ .../Sources/MediaPickerSelectedListNode.swift | 1 + submodules/TelegramUI/BUILD | 1 + .../Sources/ChatMessageBubbleBackdrop.swift | 1 + .../Sources/ChatMessageBubbleItemNode.swift | 3 +- .../ChatTextInputActionButtonsNode.swift | 1 + .../Sources/HorizontalStickerGridItem.swift | 20 ++++++++++- 15 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 submodules/ChatMessageBackground/BUILD create mode 100644 submodules/ChatMessageBackground/Info.plist rename submodules/{TelegramUI => ChatMessageBackground}/Sources/ChatMessageBackground.swift (91%) diff --git a/submodules/AttachmentUI/Sources/AttachmentController.swift b/submodules/AttachmentUI/Sources/AttachmentController.swift index 09fcf5f202..c8e87a54c2 100644 --- a/submodules/AttachmentUI/Sources/AttachmentController.swift +++ b/submodules/AttachmentUI/Sources/AttachmentController.swift @@ -372,8 +372,9 @@ public class AttachmentController: ViewController { self.container.position = startPosition let transition = ContainedViewLayoutTransition.animated(duration: 0.4, curve: .spring) transition.animateView(allowUserInteraction: true, { - self.animating = false self.container.position = targetPosition + }, completion: { _ in + self.animating = false }) } } diff --git a/submodules/ChatMessageBackground/BUILD b/submodules/ChatMessageBackground/BUILD new file mode 100644 index 0000000000..51dc28d4b1 --- /dev/null +++ b/submodules/ChatMessageBackground/BUILD @@ -0,0 +1,21 @@ +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") + +swift_library( + name = "ChatMessageBackground", + module_name = "ChatMessageBackground", + srcs = glob([ + "Sources/**/*.swift", + ]), + copts = [ + "-warnings-as-errors", + ], + deps = [ + "//submodules/AsyncDisplayKit:AsyncDisplayKit", + "//submodules/Display:Display", + "//submodules/TelegramPresentationData:TelegramPresentationData", + "//submodules/WallpaperBackgroundNode:WallpaperBackgroundNode", + ], + visibility = [ + "//visibility:public", + ], +) diff --git a/submodules/ChatMessageBackground/Info.plist b/submodules/ChatMessageBackground/Info.plist new file mode 100644 index 0000000000..e1fe4cfb7b --- /dev/null +++ b/submodules/ChatMessageBackground/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + + diff --git a/submodules/TelegramUI/Sources/ChatMessageBackground.swift b/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift similarity index 91% rename from submodules/TelegramUI/Sources/ChatMessageBackground.swift rename to submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift index 4b5eee990c..72314a0f33 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBackground.swift +++ b/submodules/ChatMessageBackground/Sources/ChatMessageBackground.swift @@ -5,10 +5,10 @@ import Display import TelegramPresentationData import WallpaperBackgroundNode -enum ChatMessageBackgroundMergeType: Equatable { +public enum ChatMessageBackgroundMergeType: Equatable { case None, Side, Top(side: Bool), Bottom, Both, Extracted - init(top: Bool, bottom: Bool, side: Bool) { + public init(top: Bool, bottom: Bool, side: Bool) { if top && bottom { self = .Both } else if top { @@ -29,12 +29,12 @@ enum ChatMessageBackgroundMergeType: Equatable { } } -enum ChatMessageBackgroundType: Equatable { +public enum ChatMessageBackgroundType: Equatable { case none case incoming(ChatMessageBackgroundMergeType) case outgoing(ChatMessageBackgroundMergeType) - static func ==(lhs: ChatMessageBackgroundType, rhs: ChatMessageBackgroundType) -> Bool { + public static func ==(lhs: ChatMessageBackgroundType, rhs: ChatMessageBackgroundType) -> Bool { switch lhs { case .none: if case .none = rhs { @@ -58,8 +58,8 @@ enum ChatMessageBackgroundType: Equatable { } } -class ChatMessageBackground: ASDisplayNode { - private(set) var type: ChatMessageBackgroundType? +public class ChatMessageBackground: ASDisplayNode { + public private(set) var type: ChatMessageBackgroundType? private var currentHighlighted: Bool? private var hasWallpaper: Bool? private var graphics: PrincipalThemeEssentialGraphics? @@ -68,11 +68,11 @@ class ChatMessageBackground: ASDisplayNode { private let outlineImageNode: ASImageNode private weak var backgroundNode: WallpaperBackgroundNode? - var hasImage: Bool { + public var hasImage: Bool { self.imageNode.image != nil } - override init() { + public override init() { self.imageNode = ASImageNode() self.imageNode.displaysAsynchronously = false self.imageNode.displayWithoutProcessing = true @@ -88,23 +88,23 @@ class ChatMessageBackground: ASDisplayNode { self.addSubnode(self.imageNode) } - func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) { + public func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) { transition.updateFrame(node: self.imageNode, frame: CGRect(origin: CGPoint(), size: size).insetBy(dx: -1.0, dy: -1.0)) transition.updateFrame(node: self.outlineImageNode, frame: CGRect(origin: CGPoint(), size: size).insetBy(dx: -1.0, dy: -1.0)) } - func updateLayout(size: CGSize, transition: ListViewItemUpdateAnimation) { + public func updateLayout(size: CGSize, transition: ListViewItemUpdateAnimation) { transition.animator.updateFrame(layer: self.imageNode.layer, frame: CGRect(origin: CGPoint(), size: size).insetBy(dx: -1.0, dy: -1.0), completion: nil) transition.animator.updateFrame(layer: self.outlineImageNode.layer, frame: CGRect(origin: CGPoint(), size: size).insetBy(dx: -1.0, dy: -1.0), completion: nil) } - func setMaskMode(_ maskMode: Bool) { + public func setMaskMode(_ maskMode: Bool) { if let type = self.type, let hasWallpaper = self.hasWallpaper, let highlighted = self.currentHighlighted, let graphics = self.graphics, let backgroundNode = self.backgroundNode { self.setType(type: type, highlighted: highlighted, graphics: graphics, maskMode: maskMode, hasWallpaper: hasWallpaper, transition: .immediate, backgroundNode: backgroundNode) } } - func setType(type: ChatMessageBackgroundType, highlighted: Bool, graphics: PrincipalThemeEssentialGraphics, maskMode: Bool, hasWallpaper: Bool, transition: ContainedViewLayoutTransition, backgroundNode: WallpaperBackgroundNode?) { + public func setType(type: ChatMessageBackgroundType, highlighted: Bool, graphics: PrincipalThemeEssentialGraphics, maskMode: Bool, hasWallpaper: Bool, transition: ContainedViewLayoutTransition, backgroundNode: WallpaperBackgroundNode?) { let previousType = self.type if let currentType = previousType, currentType == type, self.currentHighlighted == highlighted, self.graphics === graphics, backgroundNode === self.backgroundNode, self.maskMode == maskMode, self.hasWallpaper == hasWallpaper { return @@ -244,7 +244,7 @@ class ChatMessageBackground: ASDisplayNode { self.outlineImageNode.image = outlineImage } - func animateFrom(sourceView: UIView, transition: CombinedTransition) { + public func animateFrom(sourceView: UIView, transition: CombinedTransition) { if transition.isAnimated { self.imageNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) self.outlineImageNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) @@ -262,11 +262,11 @@ class ChatMessageBackground: ASDisplayNode { } } -final class ChatMessageShadowNode: ASDisplayNode { +public final class ChatMessageShadowNode: ASDisplayNode { private let contentNode: ASImageNode private var graphics: PrincipalThemeEssentialGraphics? - override init() { + public override init() { self.contentNode = ASImageNode() self.contentNode.isLayerBacked = true self.contentNode.displaysAsynchronously = false @@ -281,7 +281,7 @@ final class ChatMessageShadowNode: ASDisplayNode { self.addSubnode(self.contentNode) } - func setType(type: ChatMessageBackgroundType, hasWallpaper: Bool, graphics: PrincipalThemeEssentialGraphics) { + public func setType(type: ChatMessageBackgroundType, hasWallpaper: Bool, graphics: PrincipalThemeEssentialGraphics) { let shadowImage: UIImage? if hasWallpaper { @@ -334,7 +334,8 @@ final class ChatMessageShadowNode: ASDisplayNode { self.contentNode.image = shadowImage } - func updateLayout(backgroundFrame: CGRect, transition: ContainedViewLayoutTransition) { + public func updateLayout(backgroundFrame: CGRect, transition: ContainedViewLayoutTransition) { transition.updateFrame(node: self.contentNode, frame: CGRect(origin: CGPoint(x: backgroundFrame.minX - 10.0, y: backgroundFrame.minY - 10.0), size: CGSize(width: backgroundFrame.width + 20.0, height: backgroundFrame.height + 20.0))) } } + diff --git a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m index b4d2e8cbcf..70f099b628 100644 --- a/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m +++ b/submodules/LegacyComponents/Sources/TGMediaPickerGalleryInterfaceView.m @@ -1646,7 +1646,7 @@ _selectedPhotosView.frame = CGRectMake(screenEdges.left + TGPhotoEditorToolbarSize + 66 + _safeAreaInset.left, screenEdges.top + 4 + headerInset, photosViewSize, self.frame.size.height - 4 * 2 - headerInset); - _landscapeToolbarView.frame = CGRectMake(screenEdges.left, screenEdges.top, TGPhotoEditorToolbarSize + _safeAreaInset.left, self.frame.size.height); + _landscapeToolbarView.frame = CGRectMake(screenEdges.left + _safeAreaInset.left, screenEdges.top, TGPhotoEditorToolbarSize + _safeAreaInset.left, self.frame.size.height); }]; _headerWrapperView.frame = CGRectMake(screenEdges.left + TGPhotoEditorToolbarSize + _safeAreaInset.left, screenEdges.top, self.frame.size.width - TGPhotoEditorToolbarSize - _safeAreaInset.left, 64); diff --git a/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m b/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m index d865895ee9..954b9083f3 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m +++ b/submodules/LegacyComponents/Sources/TGPhotoCaptionInputMixin.m @@ -222,13 +222,21 @@ _currentEdgeInsets = edgeInsets; CGFloat panelHeight = [_inputPanel updateLayoutSize:frame.size sideInset:0.0]; - _inputPanelView.frame = CGRectMake(edgeInsets.left, frame.size.height - panelHeight - MAX(edgeInsets.bottom, _keyboardHeight), frame.size.width, panelHeight); + + CGFloat y = 0.0; + if (frame.size.width > frame.size.height) { + y = edgeInsets.top + frame.size.height; + } else { + y = edgeInsets.top + frame.size.height - panelHeight - MAX(edgeInsets.bottom, _keyboardHeight); + } + + _inputPanelView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, panelHeight); CGFloat backgroundHeight = panelHeight; if (_keyboardHeight > 0.0) { backgroundHeight += _keyboardHeight - edgeInsets.bottom; } - _backgroundView.frame = CGRectMake(edgeInsets.left, frame.size.height - panelHeight - MAX(edgeInsets.bottom, _keyboardHeight), frame.size.width, backgroundHeight); + _backgroundView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, backgroundHeight); } @end diff --git a/submodules/MediaPickerUI/BUILD b/submodules/MediaPickerUI/BUILD index 7ede37f694..f2da9f36a8 100644 --- a/submodules/MediaPickerUI/BUILD +++ b/submodules/MediaPickerUI/BUILD @@ -37,6 +37,7 @@ swift_library( "//submodules/PresentationDataUtils:PresentationDataUtils", "//submodules/WallpaperBackgroundNode:WallpaperBackgroundNode", "//submodules/WebSearchUI:WebSearchUI", + "//submodules/ChatMessageBackground:ChatMessageBackground", ], visibility = [ "//visibility:public", diff --git a/submodules/MediaPickerUI/Sources/LegacyMediaPickerGallery.swift b/submodules/MediaPickerUI/Sources/LegacyMediaPickerGallery.swift index 11c67686bb..ae546328f3 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, dismissAll: @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, willTransitionOut: @escaping () -> Void, dismissAll: @escaping () -> Void) { let reminder = peer?.id == context.account.peerId let legacyController = LegacyController(presentation: .custom, theme: presentationData.theme, initialLayout: nil) @@ -168,6 +168,8 @@ func presentLegacyMediaPickerGallery(context: AccountContext, peer: EnginePeer?, } } controller.beginTransitionOut = { item, itemView in + willTransitionOut() + if let item = item as? TGMediaPickerGalleryItem { if let itemView = itemView as? TGMediaPickerGalleryVideoItemView { itemView.stop() diff --git a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift index cd61bf837e..68efd7616d 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift @@ -500,6 +500,9 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self?.controller?.present(c, in: .window(.root), with: a) }, finishedTransitionIn: { [weak self] in self?.openingMedia = false + self?.cameraView?.pausePreview() + }, willTransitionOut: { [weak self] in + self?.cameraView?.resumePreview() }, dismissAll: { [weak self] in self?.controller?.dismissAll() }) @@ -533,6 +536,9 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { self?.controller?.present(c, in: .window(.root), with: a, blockInteraction: true) }, finishedTransitionIn: { [weak self] in self?.openingMedia = false + self?.cameraView?.pausePreview() + }, willTransitionOut: { [weak self] in + self?.cameraView?.resumePreview() }, dismissAll: { [weak self] in self?.controller?.dismissAll() }) diff --git a/submodules/MediaPickerUI/Sources/MediaPickerSelectedListNode.swift b/submodules/MediaPickerUI/Sources/MediaPickerSelectedListNode.swift index f1dd8125ef..4d62d5bf84 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerSelectedListNode.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerSelectedListNode.swift @@ -210,6 +210,7 @@ final class MediaPickerSelectedListNode: ASDisplayNode, UIScrollViewDelegate, UI init(context: AccountContext) { self.context = context self.wallpaperBackgroundNode = createWallpaperBackgroundNode(context: context, forChatDisplay: true, useSharedAnimationPhase: false, useExperimentalImplementation: context.sharedContext.immediateExperimentalUISettings.experimentalBackground) + self.wallpaperBackgroundNode.backgroundColor = .black self.scrollNode = ASScrollNode() super.init() diff --git a/submodules/TelegramUI/BUILD b/submodules/TelegramUI/BUILD index ff61a7197e..9628e0b0e6 100644 --- a/submodules/TelegramUI/BUILD +++ b/submodules/TelegramUI/BUILD @@ -264,6 +264,7 @@ swift_library( "//submodules/ChatSendMessageActionUI:ChatSendMessageActionUI", "//submodules/ChatTextLinkEditUI:ChatTextLinkEditUI", "//submodules/MediaPickerUI:MediaPickerUI", + "//submodules/ChatMessageBackground:ChatMessageBackground", ] + select({ "@build_bazel_rules_apple//apple:ios_armv7": [], "@build_bazel_rules_apple//apple:ios_arm64": appcenter_targets, diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift index a07d186ee2..3b7ba324ed 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleBackdrop.swift @@ -4,6 +4,7 @@ import Display import Postbox import TelegramPresentationData import WallpaperBackgroundNode +import ChatMessageBackground private let maskInset: CGFloat = 1.0 diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift index 5a5b806925..2e2ec3b160 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import Display +import SwiftSignalKit import Postbox import TelegramCore import TelegramPresentationData @@ -21,8 +22,8 @@ import GridMessageSelectionNode import AppBundle import Markdown import WallpaperBackgroundNode -import SwiftSignalKit import ChatPresentationInterfaceState +import ChatMessageBackground enum InternalBubbleTapAction { case action(() -> Void) diff --git a/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift b/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift index 7dce2b95dc..b805b4dc1c 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift @@ -6,6 +6,7 @@ import TelegramCore import TelegramPresentationData import ContextUI import ChatPresentationInterfaceState +import ChatMessageBackground final class ChatTextInputActionButtonsNode: ASDisplayNode { private let presentationContext: ChatPresentationContext? diff --git a/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift b/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift index 2d7d12b128..3873ed3c96 100755 --- a/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift +++ b/submodules/TelegramUI/Sources/HorizontalStickerGridItem.swift @@ -58,10 +58,15 @@ final class HorizontalStickerGridItemNode: GridItemNode { private var currentIsPreviewing: Bool = false + private var setupTimestamp: Double? + override var isVisibleInGrid: Bool { didSet { if oldValue != self.isVisibleInGrid { if self.isVisibleInGrid { + if self.setupTimestamp == nil { + self.setupTimestamp = CACurrentMediaTime() + } self.animationNode?.visibility = true } else { self.animationNode?.visibility = false @@ -158,7 +163,20 @@ final class HorizontalStickerGridItemNode: GridItemNode { self.imageNode.setSignal(chatMessageAnimatedSticker(postbox: account.postbox, file: item.file, small: true, size: fittedDimensions, synchronousLoad: false)) } animationNode.started = { [weak self] in - self?.imageNode.alpha = 0.0 + guard let strongSelf = self else { + return + } + + strongSelf.imageNode.alpha = 0.0 + + let current = CACurrentMediaTime() + if let setupTimestamp = strongSelf.setupTimestamp, current - setupTimestamp > 0.3 { + if let placeholderNode = strongSelf.placeholderNode, !placeholderNode.alpha.isZero { + strongSelf.removePlaceholder(animated: true) + } + } else { + strongSelf.removePlaceholder(animated: false) + } } animationNode.setup(source: AnimatedStickerResourceSource(account: account, resource: item.file.resource, isVideo: item.file.isVideoSticker), width: Int(fittedDimensions.width), height: Int(fittedDimensions.height), mode: .cached)