Add non-premium story tooltip

This commit is contained in:
Isaac 2024-04-11 16:59:25 +04:00
parent 3d597b95a5
commit b45e9fe24e
2 changed files with 37 additions and 11 deletions

View File

@ -198,10 +198,7 @@ final class PeerInfoHeaderNavigationButtonContainerNode: SparseNode {
}
let buttonSize = buttonNode.update(key: spec.key, presentationData: presentationData, height: size.height)
var nextButtonOrigin = spec.isForExpandedView ? nextExpandedButtonOrigin : nextRegularButtonOrigin
var buttonFrame = CGRect(origin: CGPoint(x: nextButtonOrigin - buttonSize.width, y: expandOffset + (spec.isForExpandedView ? maximumExpandOffset : 0.0)), size: buttonSize)
if case .postStory = spec.key {
buttonFrame.origin.x -= 12.0
}
let buttonFrame = CGRect(origin: CGPoint(x: nextButtonOrigin - buttonSize.width, y: expandOffset + (spec.isForExpandedView ? maximumExpandOffset : 0.0)), size: buttonSize)
nextButtonOrigin -= buttonSize.width + 15.0
if spec.isForExpandedView {
nextExpandedButtonOrigin = nextButtonOrigin
@ -263,10 +260,7 @@ final class PeerInfoHeaderNavigationButtonContainerNode: SparseNode {
if let buttonNode = self.rightButtonNodes[key] {
let buttonSize = buttonNode.bounds.size
var nextButtonOrigin = spec.isForExpandedView ? nextExpandedButtonOrigin : nextRegularButtonOrigin
var buttonFrame = CGRect(origin: CGPoint(x: nextButtonOrigin - buttonSize.width, y: expandOffset + (spec.isForExpandedView ? maximumExpandOffset : 0.0)), size: buttonSize)
if case .postStory = spec.key {
buttonFrame.origin.x -= 12.0
}
let buttonFrame = CGRect(origin: CGPoint(x: nextButtonOrigin - buttonSize.width, y: expandOffset + (spec.isForExpandedView ? maximumExpandOffset : 0.0)), size: buttonSize)
nextButtonOrigin -= buttonSize.width + 15.0
if spec.isForExpandedView {
nextExpandedButtonOrigin = nextButtonOrigin

View File

@ -4122,7 +4122,11 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
case .qrCode:
strongSelf.openQrCode()
case .postStory:
strongSelf.openPostStory()
var sourceFrame: CGRect?
if let source {
sourceFrame = source.view.convert(source.bounds, to: strongSelf.view)
}
strongSelf.openPostStory(sourceFrame: sourceFrame)
case .editPhoto, .editVideo, .moreToSearch:
break
}
@ -9542,12 +9546,12 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
self.controller?.push(controller)
}
private func openPostStory() {
private func openPostStory(sourceFrame: CGRect?) {
self.postingAvailabilityDisposable?.dispose()
let canPostStatus: Signal<StoriesUploadAvailability, NoError>
#if DEBUG && false
canPostStatus = .single(.available)
canPostStatus = .single(StoriesUploadAvailability.premiumRequired)
#else
canPostStatus = self.context.engine.messages.checkStoriesUploadAvailability(target: .peer(self.peerId))
#endif
@ -9599,6 +9603,34 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
self.hapticFeedback.impact(.light)
}).strict()
case .premiumRequired, .monthlyLimit, .weeklyLimit, .expiringLimit:
if let sourceFrame {
let context = self.context
let location = CGRect(origin: CGPoint(x: sourceFrame.midX, y: sourceFrame.maxY), size: CGSize())
let text: String
text = self.presentationData.strings.StoryFeed_TooltipPremiumPostingLimited
let tooltipController = TooltipScreen(
context: context,
account: context.account,
sharedContext: context.sharedContext,
text: .markdown(text: text),
style: .customBlur(UIColor(rgb: 0x2a2a2a), 2.0),
icon: .none,
location: .point(location, .top),
shouldDismissOnTouch: { [weak self] point, containerFrame in
if containerFrame.contains(point) {
let controller = context.sharedContext.makePremiumIntroController(context: context, source: .stories, forceDark: false, dismissed: nil)
self?.controller?.push(controller)
return .dismiss(consume: true)
} else {
return .dismiss(consume: false)
}
}
)
self.controller?.present(tooltipController, in: .current)
}
default:
break
}