mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-15 18:59:54 +00:00
Add premium demo pages switching by tap
This commit is contained in:
parent
3e99385716
commit
a65d7bba8f
@ -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)
|
||||
|
||||
|
||||
@ -283,15 +283,18 @@ final class DemoPagerComponent: Component {
|
||||
|
||||
let items: [Item]
|
||||
let index: Int
|
||||
let nextAction: ActionSlot<Void>?
|
||||
let updated: (CGFloat, Int) -> Void
|
||||
|
||||
public init(
|
||||
items: [Item],
|
||||
index: Int = 0,
|
||||
nextAction: ActionSlot<Void>? = 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,
|
||||
|
||||
@ -618,6 +618,8 @@ public class PremiumLimitsListScreen: ViewController {
|
||||
var disposable: Disposable?
|
||||
var promoConfiguration: PremiumPromoConfiguration?
|
||||
|
||||
let nextAction = ActionSlot<Void>()
|
||||
|
||||
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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user