Various fixes

This commit is contained in:
Ilya Laktyushin 2023-10-22 20:29:11 +04:00
parent d136aa683d
commit 3d4ccb4eb0
6 changed files with 42 additions and 5 deletions

View File

@ -37,7 +37,9 @@ public final class SheetComponentEnvironment: Equatable {
}
}
public let sheetComponentTag = GenericComponentViewTag()
public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
public typealias EnvironmentType = (ChildEnvironmentType, SheetComponentEnvironment)
public enum BackgroundColor: Equatable {
@ -90,7 +92,19 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: 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<ChildEnvironmentType: Equatable>: Component {
}
}
public func dismissAnimated() {
self.dismiss?(true)
}
private var scrollingOut = false
public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let contentOffset = (scrollView.contentOffset.y + scrollView.contentInset.top - scrollView.contentSize.height) * -1.0

View File

@ -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 })

View File

@ -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<ViewControllerComponentContainer.Environment>.View.Tag()) as? SheetComponent<ViewControllerComponentContainer.Environment>.View {
view.dismissAnimated()
}
}
public override func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, transition: transition)

View File

@ -1697,6 +1697,12 @@ public class PremiumLimitScreen: ViewControllerComponentContainer {
self.view.disablesInteractiveModalDismiss = true
}
public func dismissAnimated() {
if let view = self.node.hostView.findTaggedView(tag: SheetComponent<ViewControllerComponentContainer.Environment>.View.Tag()) as? SheetComponent<ViewControllerComponentContainer.Environment>.View {
view.dismissAnimated()
}
}
public func updateSubject(_ subject: Subject, count: Int32) {
let component = LimitSheetComponent(context: self.context, subject: subject, count: count, cancel: {}, action: {
return true

View File

@ -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
}

View File

@ -934,7 +934,7 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur
}
}
dismissImpl = { [weak controller] in
controller?.dismiss()
controller?.dismissAnimated()
}
})
case let .premiumGiftCode(slug):