From 4a3292df29d1073bbc1ae47923ab8da94acfcad6 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 26 Jun 2023 17:38:22 +0300 Subject: [PATCH] Adjust input activation --- .../Sources/ApiUtils/TelegramMediaFile.swift | 3 ++ .../PendingMessageUploadedContent.swift | 3 ++ .../SyncCore/SyncCore_TelegramMediaFile.swift | 1 + .../Sources/StoryContainerScreen.swift | 46 +++++++++++++------ .../StoryItemSetContainerComponent.swift | 16 +++++++ 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift index 1242462a17..7fecddfd0b 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/TelegramMediaFile.swift @@ -105,6 +105,9 @@ func telegramMediaFileAttributesFromApiAttributes(_ attributes: [Api.DocumentAtt if (flags & (1 << 1)) != 0 { videoFlags.insert(.supportsStreaming) } + if (flags & (1 << 3)) != 0 { + videoFlags.insert(.isSilent) + } result.append(.Video(duration: Double(duration), size: PixelDimensions(width: w, height: h), flags: videoFlags, preloadSize: preloadSize)) case let .documentAttributeAudio(flags, duration, title, performer, waveform): let isVoice = (flags & (1 << 10)) != 0 diff --git a/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift b/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift index 7dd47bf835..855e7ec65e 100644 --- a/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/PendingMessageUploadedContent.swift @@ -569,6 +569,9 @@ func inputDocumentAttributesFromFileAttributes(_ fileAttributes: [TelegramMediaF if preloadSize != nil { flags |= (1 << 2) } + if videoFlags.contains(.isSilent) { + flags |= (1 << 3) + } attributes.append(.documentAttributeVideo(flags: flags, duration: duration, w: Int32(size.width), h: Int32(size.height), preloadPrefixSize: preloadSize)) case let .Audio(isVoice, duration, title, performer, waveform): diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift index 38ee46bc30..0dbfbf7aa3 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift @@ -188,6 +188,7 @@ public struct TelegramMediaVideoFlags: OptionSet { public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0) public static let supportsStreaming = TelegramMediaVideoFlags(rawValue: 1 << 1) + public static let isSilent = TelegramMediaVideoFlags(rawValue: 1 << 3) } public struct StickerMaskCoords: PostboxCoding, Equatable { diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift index c0adfdb3bf..48550f5008 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift @@ -392,30 +392,46 @@ private final class StoryContainerScreenComponent: Component { let translation = recognizer.translation(in: self) self.verticalPanState = ItemSetPanState(fraction: max(-1.0, min(1.0, translation.y / self.bounds.height)), didBegin: true) self.state?.updated(transition: .immediate) - case .cancelled, .ended: - let translation = recognizer.translation(in: self) - let velocity = recognizer.velocity(in: self) - self.verticalPanState = nil - var updateState = true - - if translation.y > 100.0 || velocity.y > 10.0 { - self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) - self.environment?.controller()?.dismiss() - } else if translation.y < -100.0 || velocity.y < -40.0 { + if translation.y < -40.0 { if let component = self.component, let stateValue = component.content.stateValue, let slice = stateValue.slice, let itemSetView = self.visibleItemSetViews[slice.peer.id] { if let itemSetComponentView = itemSetView.view.view as? StoryItemSetContainerComponent.View { - if itemSetComponentView.activateInput() { - updateState = false + if let activateInputWhileDragging = itemSetComponentView.activateInputWhileDragging() { + activateInputWhileDragging() + + self.verticalPanState = nil + recognizer.state = .cancelled + self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) } } } + } + case .cancelled, .ended: + if self.verticalPanState != nil { + let translation = recognizer.translation(in: self) + let velocity = recognizer.velocity(in: self) - if updateState || "".isEmpty { + self.verticalPanState = nil + var updateState = true + + if translation.y > 100.0 || velocity.y > 10.0 { + self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) + self.environment?.controller()?.dismiss() + } else if translation.y < -100.0 || velocity.y < -40.0 { + if let component = self.component, let stateValue = component.content.stateValue, let slice = stateValue.slice, let itemSetView = self.visibleItemSetViews[slice.peer.id] { + if let itemSetComponentView = itemSetView.view.view as? StoryItemSetContainerComponent.View { + if itemSetComponentView.activateInput() { + updateState = false + } + } + } + + if updateState || "".isEmpty { + self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) + } + } else { self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) } - } else { - self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) } default: break diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift index 8f7f5b40f1..ed8ba3e363 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift @@ -969,6 +969,22 @@ public final class StoryItemSetContainerComponent: Component { return false } + func activateInputWhileDragging() -> (() -> Void)? { + guard let component = self.component else { + return nil + } + if component.slice.peer.id == component.context.account.peerId { + } else { + if let inputPanelView = self.inputPanel.view as? MessageInputPanelComponent.View { + return { [weak inputPanelView] in + inputPanelView?.activateInput() + } + } + } + + return nil + } + func animateIn(transitionIn: StoryContainerScreen.TransitionIn) { self.closeButton.layer.animateScale(from: 0.001, to: 1.0, duration: 0.2, delay: 0.12, timingFunction: kCAMediaTimingFunctionSpring)