From 7afdef9dfa214d4efca54a6c293211a144b95705 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 3 Dec 2023 15:39:58 +0400 Subject: [PATCH] Various improvements --- .../Sources/CaptureControlsComponent.swift | 6 +- .../MessageInputActionButtonComponent.swift | 130 ++++++++++-------- .../Sources/StoryFooterPanelComponent.swift | 32 +++-- 3 files changed, 100 insertions(+), 68 deletions(-) diff --git a/submodules/TelegramUI/Components/CameraScreen/Sources/CaptureControlsComponent.swift b/submodules/TelegramUI/Components/CameraScreen/Sources/CaptureControlsComponent.swift index cdec27a8cc..6c68b85610 100644 --- a/submodules/TelegramUI/Components/CameraScreen/Sources/CaptureControlsComponent.swift +++ b/submodules/TelegramUI/Components/CameraScreen/Sources/CaptureControlsComponent.swift @@ -956,9 +956,9 @@ final class CaptureControlsComponent: Component { } else { galleryButtonFrame = CGRect(origin: CGPoint(x: buttonSideInset, y: floorToScreenPixels((size.height - galleryButtonSize.height) / 2.0)), size: galleryButtonSize) } - if let galleryButtonView = self.galleryButtonView.view { - galleryButtonView.clipsToBounds = true - galleryButtonView.layer.cornerRadius = galleryCornerRadius + if let galleryButtonView = self.galleryButtonView.view as? CameraButton.View { + galleryButtonView.contentView.clipsToBounds = true + galleryButtonView.contentView.layer.cornerRadius = galleryCornerRadius if galleryButtonView.superview == nil { self.addSubview(galleryButtonView) } diff --git a/submodules/TelegramUI/Components/MessageInputActionButtonComponent/Sources/MessageInputActionButtonComponent.swift b/submodules/TelegramUI/Components/MessageInputActionButtonComponent/Sources/MessageInputActionButtonComponent.swift index 9698490cdf..cbbfddcb39 100644 --- a/submodules/TelegramUI/Components/MessageInputActionButtonComponent/Sources/MessageInputActionButtonComponent.swift +++ b/submodules/TelegramUI/Components/MessageInputActionButtonComponent/Sources/MessageInputActionButtonComponent.swift @@ -327,68 +327,73 @@ public final class MessageInputActionButtonComponent: Component { self.containerNode.isUserInteractionEnabled = component.longPressAction != nil if self.micButton == nil { - let micButton = ChatTextInputMediaRecordingButton( - context: component.context, - theme: defaultDarkPresentationTheme, - useDarkTheme: true, - strings: component.strings, - presentController: component.presentController - ) - self.micButton = micButton - micButton.statusBarHost = component.context.sharedContext.mainWindow?.statusBarHost - self.addSubview(micButton) - - micButton.disablesInteractiveKeyboardGestureRecognizer = true - - micButton.beginRecording = { [weak self] in - guard let self, let component = self.component else { - return + switch component.mode { + case .videoInput, .voiceInput, .unavailableVoiceInput, .send: + let micButton = ChatTextInputMediaRecordingButton( + context: component.context, + theme: defaultDarkPresentationTheme, + useDarkTheme: true, + strings: component.strings, + presentController: component.presentController + ) + self.micButton = micButton + micButton.statusBarHost = component.context.sharedContext.mainWindow?.statusBarHost + self.addSubview(micButton) + + micButton.disablesInteractiveKeyboardGestureRecognizer = true + + micButton.beginRecording = { [weak self] in + guard let self, let component = self.component else { + return + } + switch component.mode { + case .voiceInput, .videoInput: + component.action(component.mode, .down, false) + default: + break + } } - switch component.mode { - case .voiceInput, .videoInput: - component.action(component.mode, .down, false) - default: - break + micButton.stopRecording = { [weak self] in + guard let self, let component = self.component else { + return + } + component.stopAndPreviewMediaRecording() } - } - micButton.stopRecording = { [weak self] in - guard let self, let component = self.component else { - return + micButton.endRecording = { [weak self] sendMedia in + guard let self, let component = self.component else { + return + } + switch component.mode { + case .voiceInput, .videoInput: + component.action(component.mode, .up, sendMedia) + default: + break + } } - component.stopAndPreviewMediaRecording() - } - micButton.endRecording = { [weak self] sendMedia in - guard let self, let component = self.component else { - return + micButton.updateLocked = { [weak self] _ in + guard let self, let component = self.component else { + return + } + component.lockMediaRecording() } - switch component.mode { - case .voiceInput, .videoInput: - component.action(component.mode, .up, sendMedia) - default: - break + micButton.switchMode = { [weak self] in + guard let self, let component = self.component else { + return + } + if case .unavailableVoiceInput = component.mode { + component.action(component.mode, .up, false) + } else { + component.switchMediaInputMode() + } } - } - micButton.updateLocked = { [weak self] _ in - guard let self, let component = self.component else { - return + micButton.updateCancelTranslation = { [weak self] in + guard let self, let micButton = self.micButton, let component = self.component else { + return + } + component.updateMediaCancelFraction(micButton.cancelTranslation) } - component.lockMediaRecording() - } - micButton.switchMode = { [weak self] in - guard let self, let component = self.component else { - return - } - if case .unavailableVoiceInput = component.mode { - component.action(component.mode, .up, false) - } else { - component.switchMediaInputMode() - } - } - micButton.updateCancelTranslation = { [weak self] in - guard let self, let micButton = self.micButton, let component = self.component else { - return - } - component.updateMediaCancelFraction(micButton.cancelTranslation) + default: + break } } @@ -636,6 +641,19 @@ public final class MessageInputActionButtonComponent: Component { return availableSize } + + public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + var result = super.hitTest(point, with: event) + if result == nil { + for view in self.button.view.subviews { + if view.point(inside: self.convert(point, to: view), with: event) { + result = self.button.view + break + } + } + } + return result + } } public func makeView() -> View { diff --git a/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift b/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift index 2ff0324c26..1af28ee73c 100644 --- a/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryFooterPanelComponent/Sources/StoryFooterPanelComponent.swift @@ -404,7 +404,6 @@ public final class StoryFooterPanelComponent: Component { likeStatsText = AnimatedCountLabelView(frame: CGRect()) likeStatsText.isUserInteractionEnabled = false self.likeStatsText = likeStatsText - self.externalContainerView.addSubview(likeStatsText) } let reactionStatsLayout = likeStatsText.update( @@ -472,7 +471,7 @@ public final class StoryFooterPanelComponent: Component { environment: {}, containerSize: CGSize(width: 33.0, height: 33.0) ) - if let likeButtonView = likeButton.view { + if let likeButtonView = likeButton.view as? MessageInputActionButtonComponent.View { if likeButtonView.superview == nil { self.addSubview(likeButtonView) } @@ -491,6 +490,15 @@ public final class StoryFooterPanelComponent: Component { likeStatsTransition.setAlpha(view: likeButtonView, alpha: 1.0 - component.expandFraction) rightContentOffset -= likeButtonSize.width + 14.0 + + if likeStatsText.superview == nil { + likeButtonView.button.view.addSubview(likeStatsText) + } + + likeStatsFrame.origin.x -= likeButtonFrame.minX + likeStatsFrame.origin.y -= likeButtonFrame.minY + likeStatsTransition.setPosition(view: likeStatsText, position: likeStatsFrame.center) + likeStatsTransition.setBounds(view: likeStatsText, bounds: CGRect(origin: CGPoint(), size: likeStatsFrame.size)) } if component.canShare { @@ -502,7 +510,6 @@ public final class StoryFooterPanelComponent: Component { forwardStatsText = AnimatedCountLabelView(frame: CGRect()) forwardStatsText.isUserInteractionEnabled = false self.forwardStatsText = forwardStatsText - self.externalContainerView.addSubview(forwardStatsText) } let forwardStatsLayout = forwardStatsText.update( @@ -515,8 +522,6 @@ public final class StoryFooterPanelComponent: Component { var forwardStatsFrame = CGRect(origin: CGPoint(x: rightContentOffset - forwardStatsLayout.size.width, y: floor((size.height - forwardStatsLayout.size.height) * 0.5)), size: forwardStatsLayout.size) forwardStatsFrame.origin.y += component.expandFraction * 45.0 - forwardStatsTransition.setPosition(view: forwardStatsText, position: forwardStatsFrame.center) - forwardStatsTransition.setBounds(view: forwardStatsText, bounds: CGRect(origin: CGPoint(), size: forwardStatsFrame.size)) var forwardStatsAlpha: CGFloat = (1.0 - component.expandFraction) if forwardCount == 0 { forwardStatsAlpha = 0.0 @@ -578,18 +583,27 @@ public final class StoryFooterPanelComponent: Component { environment: {}, containerSize: CGSize(width: 33.0, height: 33.0) ) - if let repostButtonView = repostButton.view { + if let repostButtonView = repostButton.view as? MessageInputActionButtonComponent.View { if repostButtonView.superview == nil { self.addSubview(repostButtonView) } var repostButtonFrame = CGRect(origin: CGPoint(x: rightContentOffset - repostButtonSize.width, y: floor((size.height - repostButtonSize.height) * 0.5)), size: repostButtonSize) repostButtonFrame.origin.y += component.expandFraction * 45.0 - likeStatsTransition.setPosition(view: repostButtonView, position: repostButtonFrame.center) - likeStatsTransition.setBounds(view: repostButtonView, bounds: CGRect(origin: CGPoint(), size: repostButtonFrame.size)) - likeStatsTransition.setAlpha(view: repostButtonView, alpha: 1.0 - component.expandFraction) + forwardStatsTransition.setPosition(view: repostButtonView, position: repostButtonFrame.center) + forwardStatsTransition.setBounds(view: repostButtonView, bounds: CGRect(origin: CGPoint(), size: repostButtonFrame.size)) + forwardStatsTransition.setAlpha(view: repostButtonView, alpha: 1.0 - component.expandFraction) rightContentOffset -= repostButtonSize.width + 14.0 + + if forwardStatsText.superview == nil { + repostButtonView.button.view.addSubview(forwardStatsText) + } + + forwardStatsFrame.origin.x -= repostButtonFrame.minX + forwardStatsFrame.origin.y -= repostButtonFrame.minY + forwardStatsTransition.setPosition(view: forwardStatsText, position: forwardStatsFrame.center) + forwardStatsTransition.setBounds(view: forwardStatsText, bounds: CGRect(origin: CGPoint(), size: forwardStatsFrame.size)) } let forwardButtonSize = forwardButton.update(