Fixes ~95 issues from deep audit across 12 categories in 82 files: - Crash prevention: double-resume in PhotoMetadataExtractor, force unwraps in DateRangePicker, array bounds checks in polls/achievements, ProGate hit-test bypass, Dictionary(uniqueKeysWithValues:) → uniquingKeysWith in 4 files - Silent failure elimination: all 34 try? sites replaced with do/try/catch + logging (SavedTrip, TripDetailView, CanonicalSyncService, BootstrapService, CanonicalModels, CKModels, SportsTimeApp, and more) - Performance: cached DateFormatters (7 files), O(1) team lookups via AppDataProvider, achievement definition dictionary, AnimatedBackground consolidated from 19 Tasks to 1, task cancellation in SharePreviewView - Concurrency: UIKit drawing → MainActor.run, background fetch timeout guard, @MainActor on ThemeManager/AppearanceManager, SyncLogger read/write race fix - Planning engine: game end time in travel feasibility, state-aware city normalization, exact city matching, DrivingConstraints parameter propagation - IAP: unknown subscription states → expired, unverified transaction logging, entitlements updated before paywall dismiss, restore visible to all users - Security: API key to Info.plist lookup, filename sanitization in PDF export, honest User-Agent, removed stale "Feels" analytics super properties - Navigation: consolidated competing navigationDestination, boolean → value-based - Testing: 8 sleep() → waitForExistence, duplicates extracted, Swift 6 compat - Service bugs: infinite retry cap, duplicate achievement prevention, TOCTOU vote fix, PollVote.odg → voterId rename, deterministic placeholder IDs, parallel MKDirections, Sendable-safe POI struct Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
74 lines
2.1 KiB
Swift
74 lines
2.1 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)
|
|
.overlay {
|
|
if !StoreManager.shared.isPro {
|
|
Color.clear
|
|
.contentShape(Rectangle())
|
|
.onTapGesture {
|
|
showPaywall = true
|
|
}
|
|
.accessibilityLabel("Pro feature locked")
|
|
.accessibilityHint("Double-tap to view upgrade options")
|
|
}
|
|
}
|
|
.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))
|
|
}
|
|
}
|