diff --git a/submodules/DrawingUI/Sources/StickerPickerScreen.swift b/submodules/DrawingUI/Sources/StickerPickerScreen.swift index 077db4d616..a4715931f4 100644 --- a/submodules/DrawingUI/Sources/StickerPickerScreen.swift +++ b/submodules/DrawingUI/Sources/StickerPickerScreen.swift @@ -370,6 +370,7 @@ class StickerPickerScreen: ViewController { updateScrollingToItemGroup: { [weak self] in self?.update(isExpanded: true, transition: .animated(duration: 0.4, curve: .spring)) }, + onScroll: {}, chatPeerId: nil, peekBehavior: nil, customLayout: nil, @@ -447,6 +448,7 @@ class StickerPickerScreen: ViewController { updateScrollingToItemGroup: { [weak self] in self?.update(isExpanded: true, transition: .animated(duration: 0.4, curve: .spring)) }, + onScroll: {}, chatPeerId: nil, peekBehavior: nil, customLayout: nil, @@ -571,6 +573,7 @@ class StickerPickerScreen: ViewController { updateScrollingToItemGroup: { [weak self] in self?.update(isExpanded: true, transition: .animated(duration: 0.4, curve: .spring)) }, + onScroll: {}, chatPeerId: nil, peekBehavior: stickerPeekBehavior, customLayout: nil, diff --git a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift index 00a8343191..0585b35c11 100644 --- a/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift +++ b/submodules/ReactionSelectionNode/Sources/ReactionContextNode.swift @@ -1513,6 +1513,7 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate { }, updateScrollingToItemGroup: { }, + onScroll: {}, chatPeerId: nil, peekBehavior: nil, customLayout: emojiContentLayout, diff --git a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift index 1d46b95b1e..2f80d438e4 100644 --- a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift +++ b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift @@ -577,6 +577,12 @@ final class AvatarEditorScreenComponent: Component { }, updateScrollingToItemGroup: { }, + onScroll: { [weak self] in + if let self, let state = self.state, state.expanded { + state.expanded = false + state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring))) + } + }, chatPeerId: nil, peekBehavior: nil, customLayout: nil, @@ -586,18 +592,6 @@ final class AvatarEditorScreenComponent: Component { hideBackground: true ) -// var stickerPeekBehavior: EmojiContentPeekBehaviorImpl? -// if let controller = self.controller { -// stickerPeekBehavior = EmojiContentPeekBehaviorImpl( -// context: controller.context, -// interaction: nil, -// chatPeerId: nil, -// present: { [weak controller] c, a in -// controller?.presentInGlobalOverlay(c, with: a) -// } -// ) -// } - data.stickers?.inputInteractionHolder.inputInteraction = EmojiPagerContentComponent.InputInteraction( performItemAction: { [weak self] _, item, _, _, _, _ in guard let self, let _ = item.itemFile else { @@ -707,6 +701,12 @@ final class AvatarEditorScreenComponent: Component { }, updateScrollingToItemGroup: { }, + onScroll: { [weak self] in + if let self, let state = self.state, state.expanded { + state.expanded = false + state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring))) + } + }, chatPeerId: nil, peekBehavior: nil, customLayout: nil, @@ -747,10 +747,12 @@ final class AvatarEditorScreenComponent: Component { } } + let backgroundIsBright = UIColor(rgb: state.selectedBackground.colors.first ?? 0).lightness > 0.8 + let navigationCancelButtonSize = self.navigationCancelButton.update( transition: transition, component: AnyComponent(Button( - content: AnyComponent(Text(text: environment.strings.Common_Cancel, font: Font.regular(17.0), color: state.expanded ? .white : environment.theme.rootController.navigationBar.accentTextColor)), + content: AnyComponent(Text(text: environment.strings.Common_Cancel, font: Font.regular(17.0), color: state.expanded && !backgroundIsBright ? .white : environment.theme.rootController.navigationBar.accentTextColor)), action: { [weak self] in guard let self else { return @@ -772,7 +774,7 @@ final class AvatarEditorScreenComponent: Component { let navigationDoneButtonSize = self.navigationDoneButton.update( transition: transition, component: AnyComponent(Button( - content: AnyComponent(Text(text: strings.AvatarEditor_Set, font: Font.semibold(17.0), color: state.isSearchActive ? environment.theme.rootController.navigationBar.accentTextColor : .white)), + content: AnyComponent(Text(text: strings.AvatarEditor_Set, font: Font.semibold(17.0), color: state.isSearchActive || (state.expanded && backgroundIsBright) ? environment.theme.rootController.navigationBar.accentTextColor : .white)), action: { [weak self] in guard let self else { return @@ -841,8 +843,13 @@ final class AvatarEditorScreenComponent: Component { context: component.context, background: state.selectedBackground, file: state.selectedFile, - tapped: { [weak state] in + tapped: { [weak state, weak self] in if let state, !state.editingColor { + if let emojiView = self?.keyboardView.findTaggedView(tag: EmojiPagerContentComponent.Tag(id: AnyHashable("emoji"))) as? EmojiPagerContentComponent.View { + emojiView.ensureSearchUnfocused() + } else if let emojiView = self?.keyboardView.findTaggedView(tag: EmojiPagerContentComponent.Tag(id: AnyHashable("stickers"))) as? EmojiPagerContentComponent.View { + emojiView.ensureSearchUnfocused() + } state.expanded = !state.expanded state.updated(transition: Transition(animation: .curve(duration: 0.35, curve: .spring))) } diff --git a/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift b/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift index 92ccb07f48..1140212e81 100644 --- a/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift +++ b/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift @@ -1084,6 +1084,7 @@ public final class ChatEntityKeyboardInputNode: ChatInputNode { }, updateScrollingToItemGroup: { }, + onScroll: {}, chatPeerId: chatPeerId, peekBehavior: stickerPeekBehavior, customLayout: nil, @@ -1348,6 +1349,7 @@ public final class ChatEntityKeyboardInputNode: ChatInputNode { }, updateScrollingToItemGroup: { }, + onScroll: {}, chatPeerId: chatPeerId, peekBehavior: stickerPeekBehavior, customLayout: nil, @@ -2168,6 +2170,7 @@ public final class EntityInputView: UIInputView, AttachmentTextInputPanelInputVi }, updateScrollingToItemGroup: { }, + onScroll: {}, chatPeerId: nil, peekBehavior: nil, customLayout: nil, diff --git a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift index fd1d470605..f039fe82b4 100644 --- a/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift +++ b/submodules/TelegramUI/Components/EmojiStatusSelectionComponent/Sources/EmojiStatusSelectionComponent.swift @@ -610,6 +610,7 @@ public final class EmojiStatusSelectionController: ViewController { }, updateScrollingToItemGroup: { }, + onScroll: {}, chatPeerId: nil, peekBehavior: nil, customLayout: nil, diff --git a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift index bce7df4cd2..3a321a4d50 100644 --- a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift +++ b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentComponent.swift @@ -2248,6 +2248,7 @@ public final class EmojiPagerContentComponent: Component { public let requestUpdate: (Transition) -> Void public let updateSearchQuery: (EmojiPagerContentComponent.SearchQuery?) -> Void public let updateScrollingToItemGroup: () -> Void + public let onScroll: () -> Void public let chatPeerId: PeerId? public let peekBehavior: EmojiContentPeekBehavior? public let customLayout: CustomLayout? @@ -2271,6 +2272,7 @@ public final class EmojiPagerContentComponent: Component { requestUpdate: @escaping (Transition) -> Void, updateSearchQuery: @escaping (SearchQuery?) -> Void, updateScrollingToItemGroup: @escaping () -> Void, + onScroll: @escaping () -> Void, chatPeerId: PeerId?, peekBehavior: EmojiContentPeekBehavior?, customLayout: CustomLayout?, @@ -2293,6 +2295,7 @@ public final class EmojiPagerContentComponent: Component { self.requestUpdate = requestUpdate self.updateSearchQuery = updateSearchQuery self.updateScrollingToItemGroup = updateScrollingToItemGroup + self.onScroll = onScroll self.chatPeerId = chatPeerId self.peekBehavior = peekBehavior self.customLayout = customLayout @@ -5007,6 +5010,14 @@ public final class EmojiPagerContentComponent: Component { } } + public func ensureSearchUnfocused() { + if self.isSearchActivated, let visibleSearchHeader = self.visibleSearchHeader, visibleSearchHeader.currentPresetSearchTerm == nil { + self.visibleSearchHeader?.deactivate() + } else { + self.visibleSearchHeader?.endEditing(true) + } + } + public func scrollViewDidScroll(_ scrollView: UIScrollView) { if self.ignoreScrolling { return @@ -5019,6 +5030,7 @@ public final class EmojiPagerContentComponent: Component { if self.isSearchActivated, let visibleSearchHeader = self.visibleSearchHeader, visibleSearchHeader.currentPresetSearchTerm == nil { self.visibleSearchHeader?.deactivate() } + self.component?.inputInteractionHolder.inputInteraction?.onScroll() } public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { diff --git a/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift b/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift index d01c58fd8a..9df3fffec1 100644 --- a/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift +++ b/submodules/TelegramUI/Components/ForumCreateTopicScreen/Sources/ForumCreateTopicScreen.swift @@ -969,6 +969,7 @@ private final class ForumCreateTopicScreenComponent: CombinedComponent { }, updateScrollingToItemGroup: { }, + onScroll: {}, chatPeerId: nil, peekBehavior: nil, customLayout: nil, diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 2967edc132..b29194e291 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -6727,18 +6727,22 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G let isPremium = self.context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.Peer(id: self.context.account.peerId)) |> map { peer -> Bool in return peer?.isPremium ?? false - } - self.translationStateDisposable = (combineLatest( - queue: .concurrentDefaultQueue(), - isPremium, - self.chatDisplayNode.historyNode.cachedPeerDataAndMessages - ) |> mapToSignal { isPremium, cachedDataAndMessages -> Signal in + } |> distinctUntilChanged + + let isHidden = self.chatDisplayNode.historyNode.cachedPeerDataAndMessages + |> map { cachedDataAndMessages -> Bool in let (cachedData, _) = cachedDataAndMessages var isHidden = false if let cachedData = cachedData as? CachedChannelData, cachedData.flags.contains(.translationHidden) { isHidden = true } - + return isHidden + } |> distinctUntilChanged + self.translationStateDisposable = (combineLatest( + queue: .concurrentDefaultQueue(), + isPremium, + isHidden + ) |> mapToSignal { isPremium, isHidden -> Signal in if isPremium && !isHidden { return chatTranslationState(context: context, peerId: peerId) |> map { translationState -> ChatPresentationTranslationState? in diff --git a/submodules/TranslateUI/Sources/ChatTranslation.swift b/submodules/TranslateUI/Sources/ChatTranslation.swift index 1b254eae8c..4a6e71ce6a 100644 --- a/submodules/TranslateUI/Sources/ChatTranslation.swift +++ b/submodules/TranslateUI/Sources/ChatTranslation.swift @@ -155,8 +155,11 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id) var fromLangs: [String: Int] = [:] var count = 0 for message in messages { + if let _ = URL(string: message.text) { + continue + } if message.text.count > 10 { - let text = String(message.text.prefix(64)) + let text = String(message.text.prefix(100)) languageRecognizer.processString(text) let hypotheses = languageRecognizer.languageHypotheses(withMaximum: 3) languageRecognizer.reset()