Files
Sportstime/SportsTime/Features/Paywall/ViewModifiers/ProGate.swift
Trey t 2917ae22b1 feat: add PostHog analytics with full event tracking across app
Integrate self-hosted PostHog (SPM) with AnalyticsManager singleton wrapping
all SDK calls. Adds ~40 type-safe events covering trip planning, schedule,
progress, IAP, settings, polls, export, and share flows. Includes session
replay, autocapture, network telemetry, privacy opt-out toggle in Settings,
and super properties (app version, device, pro status, selected sports).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-10 15:12:16 -06:00

72 lines
1.9 KiB
Swift

//
// ProGate.swift
// SportsTime
//
// View modifier that gates Pro-only features.
//
import SwiftUI
struct ProGateModifier: ViewModifier {
let feature: ProFeature
@State private var showPaywall = false
func body(content: Content) -> some View {
content
.onTapGesture {
if !StoreManager.shared.isPro {
showPaywall = true
}
}
.allowsHitTesting(!StoreManager.shared.isPro ? true : true)
.overlay {
if !StoreManager.shared.isPro {
Color.clear
.contentShape(Rectangle())
.onTapGesture {
showPaywall = true
}
}
}
.sheet(isPresented: $showPaywall) {
PaywallView(source: "pro_gate_\(feature.rawValue)")
}
}
}
/// Modifier for buttons that should show paywall when tapped by free users
struct ProGateButtonModifier: ViewModifier {
let feature: ProFeature
let action: () -> Void
@State private var showPaywall = false
func body(content: Content) -> some View {
Button {
if StoreManager.shared.isPro {
action()
} else {
showPaywall = true
}
} label: {
content
}
.sheet(isPresented: $showPaywall) {
PaywallView(source: "pro_gate_\(feature.rawValue)")
}
}
}
extension View {
/// Gates entire view - tapping shows paywall if not Pro
func proGate(feature: ProFeature) -> some View {
modifier(ProGateModifier(feature: feature))
}
/// Gates a button action - shows paywall instead of performing action if not Pro
func proGateButton(feature: ProFeature, action: @escaping () -> Void) -> some View {
modifier(ProGateButtonModifier(feature: feature, action: action))
}
}