From 3d4ccb4eb033208790aebdd5f7ed2826f824054d Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 22 Oct 2023 20:29:11 +0400 Subject: [PATCH] Various fixes --- .../Sources/SheetComponent.swift | 20 ++++++++++++++++++- .../Display/Source/ViewController.swift | 2 +- .../PremiumUI/Sources/PremiumDemoScreen.swift | 11 ++++++++++ .../Sources/PremiumLimitScreen.swift | 6 ++++++ .../Sources/ChatMessageBubbleItemNode.swift | 6 ++++-- .../TelegramUI/Sources/OpenResolvedUrl.swift | 2 +- 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/submodules/Components/SheetComponent/Sources/SheetComponent.swift b/submodules/Components/SheetComponent/Sources/SheetComponent.swift index d4cc02c048..7ea3f24fe2 100644 --- a/submodules/Components/SheetComponent/Sources/SheetComponent.swift +++ b/submodules/Components/SheetComponent/Sources/SheetComponent.swift @@ -37,7 +37,9 @@ public final class SheetComponentEnvironment: Equatable { } } +public let sheetComponentTag = GenericComponentViewTag() public final class SheetComponent: Component { + public typealias EnvironmentType = (ChildEnvironmentType, SheetComponentEnvironment) public enum BackgroundColor: Equatable { @@ -90,7 +92,19 @@ public final class SheetComponent: Component { } } - public final class View: UIView, UIScrollViewDelegate { + public final class View: UIView, UIScrollViewDelegate, ComponentTaggedView { + public final class Tag { + public init() { + } + } + + public func matches(tag: Any) -> Bool { + if let _ = tag as? Tag { + return true + } + return false + } + private let dimView: UIView private let scrollView: ScrollView private let backgroundView: UIView @@ -159,6 +173,10 @@ public final class SheetComponent: Component { } } + public func dismissAnimated() { + self.dismiss?(true) + } + private var scrollingOut = false public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { let contentOffset = (scrollView.contentOffset.y + scrollView.contentInset.top - scrollView.contentSize.height) * -1.0 diff --git a/submodules/Display/Source/ViewController.swift b/submodules/Display/Source/ViewController.swift index 7a7fecd24f..ea8372fc72 100644 --- a/submodules/Display/Source/ViewController.swift +++ b/submodules/Display/Source/ViewController.swift @@ -571,7 +571,7 @@ public protocol CustomViewControllerNavigationDataSummary: AnyObject { (self.navigationController as? NavigationController)?.pushViewController(controller) } - public func replace(with controller: ViewController) { + open func replace(with controller: ViewController) { if let navigationController = self.navigationController as? NavigationController { var controllers = navigationController.viewControllers controllers.removeAll(where: { $0 === self }) diff --git a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift index 6c45aa8334..7166917916 100644 --- a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift @@ -1262,6 +1262,17 @@ public class PremiumDemoScreen: ViewControllerComponentContainer { self.view.disablesInteractiveModalDismiss = true } + public override func replace(with controller: ViewController) { + self.dismissAnimated() + super.replace(with: controller) + } + + public func dismissAnimated() { + if let view = self.node.hostView.findTaggedView(tag: SheetComponent.View.Tag()) as? SheetComponent.View { + view.dismissAnimated() + } + } + public override func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { super.containerLayoutUpdated(layout, transition: transition) diff --git a/submodules/PremiumUI/Sources/PremiumLimitScreen.swift b/submodules/PremiumUI/Sources/PremiumLimitScreen.swift index 6e5a18f43c..8ca220b408 100644 --- a/submodules/PremiumUI/Sources/PremiumLimitScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumLimitScreen.swift @@ -1697,6 +1697,12 @@ public class PremiumLimitScreen: ViewControllerComponentContainer { self.view.disablesInteractiveModalDismiss = true } + public func dismissAnimated() { + if let view = self.node.hostView.findTaggedView(tag: SheetComponent.View.Tag()) as? SheetComponent.View { + view.dismissAnimated() + } + } + public func updateSubject(_ subject: Subject, count: Int32) { let component = LimitSheetComponent(context: self.context, subject: subject, count: count, cancel: {}, action: { return true diff --git a/submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode/Sources/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode/Sources/ChatMessageBubbleItemNode.swift index a9cf6b8602..c0613b3751 100644 --- a/submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode/Sources/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode/Sources/ChatMessageBubbleItemNode.swift @@ -2128,13 +2128,15 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI return adminBadgeSizeAndApply.1() }) - let sizeAndApply = authorNameLayout(TextNodeLayoutArguments(attributedString: attributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(0, maximumNodeWidth - layoutConstants.text.bubbleInsets.left - layoutConstants.text.bubbleInsets.right - credibilityIconWidth - adminBadgeSizeAndApply.0.size.width), height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) + let closeButtonWidth: CGFloat = item.message.adAttribute != nil ? 18.0 : 0.0 + + let sizeAndApply = authorNameLayout(TextNodeLayoutArguments(attributedString: attributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(0, maximumNodeWidth - layoutConstants.text.bubbleInsets.left - layoutConstants.text.bubbleInsets.right - credibilityIconWidth - adminBadgeSizeAndApply.0.size.width - closeButtonWidth), height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) nameNodeSizeApply = (sizeAndApply.0.size, { return sizeAndApply.1() }) nameNodeOriginY = headerSize.height - headerSize.width = max(headerSize.width, nameNodeSizeApply.0.width + adminBadgeSizeAndApply.0.size.width + credibilityIconWidth + bubbleWidthInsets) + headerSize.width = max(headerSize.width, nameNodeSizeApply.0.width + adminBadgeSizeAndApply.0.size.width + credibilityIconWidth + closeButtonWidth + bubbleWidthInsets) headerSize.height += nameNodeSizeApply.0.height } diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index 996985a855..e173439098 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -934,7 +934,7 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur } } dismissImpl = { [weak controller] in - controller?.dismiss() + controller?.dismissAnimated() } }) case let .premiumGiftCode(slug):