diff --git a/submodules/PremiumUI/Sources/PhoneDemoComponent.swift b/submodules/PremiumUI/Sources/PhoneDemoComponent.swift index 7e0530f6ab..fdbfa8d939 100644 --- a/submodules/PremiumUI/Sources/PhoneDemoComponent.swift +++ b/submodules/PremiumUI/Sources/PhoneDemoComponent.swift @@ -457,6 +457,7 @@ final class PhoneDemoComponent: Component { self.containerView.clipsToBounds = true self.phoneView = PhoneView(frame: CGRect(origin: .zero, size: phoneSize)) + self.phoneView.isUserInteractionEnabled = false super.init(frame: frame) diff --git a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift index bf6f407549..2ef5236446 100644 --- a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift @@ -283,15 +283,18 @@ final class DemoPagerComponent: Component { let items: [Item] let index: Int + let nextAction: ActionSlot? let updated: (CGFloat, Int) -> Void public init( items: [Item], index: Int = 0, + nextAction: ActionSlot? = nil, updated: @escaping (CGFloat, Int) -> Void ) { self.items = items self.index = index + self.nextAction = nextAction self.updated = updated } @@ -346,6 +349,17 @@ final class DemoPagerComponent: Component { func update(component: DemoPagerComponent, availableSize: CGSize, transition: Transition) -> CGSize { var validIds: [AnyHashable] = [] + component.nextAction?.connect { [weak self] in + if let self { + var nextContentOffset = self.scrollView.contentOffset + nextContentOffset.x += self.scrollView.frame.width + if nextContentOffset.x >= self.scrollView.contentSize.width { + nextContentOffset.x = 0.0 + } + self.scrollView.contentOffset = nextContentOffset + } + } + let firstTime = self.itemViews.isEmpty let contentSize = CGSize(width: availableSize.width * CGFloat(component.items.count), height: availableSize.height) @@ -787,7 +801,8 @@ private final class DemoSheetContent: CombinedComponent { content: AnyComponent( StickersCarouselComponent( context: component.context, - stickers: stickers + stickers: stickers, + tapAction: {} ) ), title: strings.Premium_Stickers, diff --git a/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift b/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift index b85422c728..d9340ea5e4 100644 --- a/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumLimitsListScreen.swift @@ -618,6 +618,8 @@ public class PremiumLimitsListScreen: ViewController { var disposable: Disposable? var promoConfiguration: PremiumPromoConfiguration? + let nextAction = ActionSlot() + init(context: AccountContext, controller: PremiumLimitsListScreen, buttonTitle: String, gloss: Bool) { self.presentationData = context.sharedContext.currentPresentationData.with { $0 } @@ -761,6 +763,8 @@ public class PremiumLimitsListScreen: ViewController { self.dim.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTapGesture(_:)))) + self.pagerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.pagerTapGesture(_:)))) + self.controller?.navigationBar?.updateBackgroundAlpha(0.0, transition: .immediate) } @@ -770,6 +774,12 @@ public class PremiumLimitsListScreen: ViewController { } } + @objc func pagerTapGesture(_ recognizer: UITapGestureRecognizer) { + if case .ended = recognizer.state { + self.nextAction.invoke(Void()) + } + } + override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { if let layout = self.currentLayout { if case .regular = layout.metrics.widthClass { @@ -1067,7 +1077,10 @@ public class PremiumLimitsListScreen: ViewController { content: AnyComponent( StickersCarouselComponent( context: context, - stickers: stickers + stickers: stickers, + tapAction: { [weak self] in + self?.nextAction.invoke(Void()) + } ) ), title: strings.Premium_Stickers, @@ -1224,6 +1237,7 @@ public class PremiumLimitsListScreen: ViewController { DemoPagerComponent( items: items, index: index, + nextAction: nextAction, updated: { [weak self] position, count in if let strongSelf = self { strongSelf.footerNode.updatePosition(position, count: count) diff --git a/submodules/PremiumUI/Sources/StickersCarouselComponent.swift b/submodules/PremiumUI/Sources/StickersCarouselComponent.swift index 1238fc5bfc..bedd056e90 100644 --- a/submodules/PremiumUI/Sources/StickersCarouselComponent.swift +++ b/submodules/PremiumUI/Sources/StickersCarouselComponent.swift @@ -19,13 +19,16 @@ final class StickersCarouselComponent: Component { let context: AccountContext let stickers: [TelegramMediaFile] + let tapAction: () -> Void public init( context: AccountContext, - stickers: [TelegramMediaFile] + stickers: [TelegramMediaFile], + tapAction: @escaping () -> Void ) { self.context = context self.stickers = stickers + self.tapAction = tapAction } public static func ==(lhs: StickersCarouselComponent, rhs: StickersCarouselComponent) -> Bool { @@ -48,7 +51,8 @@ final class StickersCarouselComponent: Component { if self.node == nil && !component.stickers.isEmpty { let node = StickersCarouselNode( context: component.context, - stickers: component.stickers + stickers: component.stickers, + tapAction: component.tapAction ) self.node = node self.addSubnode(node) @@ -278,6 +282,8 @@ private class StickerNode: ASDisplayNode { private class StickersCarouselNode: ASDisplayNode, UIScrollViewDelegate { private let context: AccountContext private let stickers: [TelegramMediaFile] + private let tapAction: () -> Void + private var itemContainerNodes: [ASDisplayNode] = [] private var itemNodes: [Int: StickerNode] = [:] private let scrollNode: ASScrollNode @@ -296,9 +302,10 @@ private class StickersCarouselNode: ASDisplayNode, UIScrollViewDelegate { private var previousInteractionTimestamp: Double = 0.0 private var timer: SwiftSignalKit.Timer? - init(context: AccountContext, stickers: [TelegramMediaFile]) { + init(context: AccountContext, stickers: [TelegramMediaFile], tapAction: @escaping () -> Void) { self.context = context self.stickers = stickers + self.tapAction = tapAction self.scrollNode = ASScrollNode() self.tapNode = ASDisplayNode() @@ -335,11 +342,17 @@ private class StickersCarouselNode: ASDisplayNode, UIScrollViewDelegate { @objc private func stickerTapped(_ gestureRecognizer: UITapGestureRecognizer) { self.previousInteractionTimestamp = CACurrentMediaTime() + 1.0 + let point = gestureRecognizer.location(in: self.view) + let size = self.bounds.size + if point.y > size.height / 3.0 && point.y < size.height - size.height / 3.0 { + self.tapAction() + return + } + guard self.animator == nil, self.scrollStartPosition == nil else { return } - let point = gestureRecognizer.location(in: self.view) guard let index = self.itemContainerNodes.firstIndex(where: { $0.frame.contains(point) }) else { return }