diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernConversationInputMicButton.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernConversationInputMicButton.h index 271e7c16b7..9e94a8da14 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernConversationInputMicButton.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGModernConversationInputMicButton.h @@ -81,6 +81,7 @@ - (void)animateOut:(BOOL)toSmallSize; - (void)addMicLevel:(CGFloat)level; - (void)dismiss; +- (void)reset; - (void)updateOverlay; diff --git a/submodules/LegacyComponents/Sources/TGModernConversationInputMicButton.m b/submodules/LegacyComponents/Sources/TGModernConversationInputMicButton.m index 0b7799d810..b2ff07f07d 100644 --- a/submodules/LegacyComponents/Sources/TGModernConversationInputMicButton.m +++ b/submodules/LegacyComponents/Sources/TGModernConversationInputMicButton.m @@ -869,6 +869,11 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius } } +- (void)reset { + _targetTranslation = 0.0; + [self updateOverlay]; +} + - (void)addMicLevel:(CGFloat)level { _inputLevel = level; [_decoration updateLevel:level]; diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 5f73ba2cd1..e751b4a129 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -1167,9 +1167,16 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { } var scrollAnimationCurve: ListViewAnimationCurve? = nil - if let strongSelf = self, strongSelf.appliedPlayingMessageId != currentlyPlayingMessageId, let currentlyPlayingMessageId = currentlyPlayingMessageId { - updatedScrollPosition = .index(index: .message(currentlyPlayingMessageId), position: .center(.bottom), directionHint: .Down, animated: true, highlight: true) - scrollAnimationCurve = .Spring(duration: 0.4) + if let strongSelf = self, case .default = source { + if strongSelf.appliedPlayingMessageId != currentlyPlayingMessageId, let currentlyPlayingMessageId = currentlyPlayingMessageId { + if isFirstTime { + } else if case let .peer(peerId) = chatLocation, currentlyPlayingMessageId.id.peerId != peerId { + } else { + updatedScrollPosition = .index(index: .message(currentlyPlayingMessageId), position: .center(.bottom), directionHint: .Up, animated: true, highlight: true) + scrollAnimationCurve = .Spring(duration: 0.4) + } + } + isFirstTime = false } var disableAnimations = false diff --git a/submodules/TelegramUI/Sources/ChatTextInputMediaRecordingButton.swift b/submodules/TelegramUI/Sources/ChatTextInputMediaRecordingButton.swift index 50df9ac3d0..56868447d4 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputMediaRecordingButton.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputMediaRecordingButton.swift @@ -98,6 +98,8 @@ private final class ChatTextInputMediaRecordingButtonPresenter : NSObject, TGMod private let presentController: (ViewController) -> Void let container: ChatTextInputMediaRecordingButtonPresenterContainer private var presentationController: ChatTextInputMediaRecordingButtonPresenterController? + private var timer: SwiftSignalKit.Timer? + fileprivate weak var button: ChatTextInputMediaRecordingButton? init(account: Account, presentController: @escaping (ViewController) -> Void) { self.account = account @@ -111,6 +113,7 @@ private final class ChatTextInputMediaRecordingButtonPresenter : NSObject, TGMod presentationController.presentingViewController?.dismiss(animated: false, completion: {}) self.presentationController = nil } + self.timer?.invalidate() } func view() -> UIView! { @@ -124,6 +127,14 @@ private final class ChatTextInputMediaRecordingButtonPresenter : NSObject, TGMod func present() { if let keyboardWindow = LegacyComponentsGlobals.provider().applicationKeyboardWindow(), !keyboardWindow.isHidden { keyboardWindow.addSubview(self.container) + + self.timer = SwiftSignalKit.Timer(timeout: 0.05, repeat: true, completion: { [weak self] in + if let keyboardWindow = LegacyComponentsGlobals.provider().applicationKeyboardWindow(), !keyboardWindow.isHidden { + } else { + self?.present() + } + }, queue: Queue.mainQueue()) + self.timer?.start() } else { var presentNow = false if self.presentationController == nil { @@ -137,10 +148,16 @@ private final class ChatTextInputMediaRecordingButtonPresenter : NSObject, TGMod if let presentationController = self.presentationController, presentNow { self.presentController(presentationController) } + + if let timer = self.timer { + self.button?.reset() + timer.invalidate() + } } } func dismiss() { + self.timer?.invalidate() self.container.removeFromSuperview() if let presentationController = self.presentationController { presentationController.presentingViewController?.dismiss(animated: false, completion: {}) @@ -171,7 +188,7 @@ final class ChatTextInputMediaRecordingButton: TGModernConversationInputMicButto private var recordingOverlay: ChatTextInputAudioRecordingOverlay? private var startTouchLocation: CGPoint? - private(set) var controlsOffset: CGFloat = 0.0 + fileprivate var controlsOffset: CGFloat = 0.0 private(set) var cancelTranslation: CGFloat = 0.0 private var micLevelDisposable: MetaDisposable? @@ -426,6 +443,7 @@ final class ChatTextInputMediaRecordingButton: TGModernConversationInputMicButto func micButtonPresenter() -> TGModernConversationInputMicButtonPresentation! { let presenter = ChatTextInputMediaRecordingButtonPresenter(account: self.account!, presentController: self.presentController) + presenter.button = self self.currentPresenter = presenter.view() return presenter }