Files
ladill-mini/apps/ios/LadillMini/App/AppRouter.swift
T
isaaccladandCursor ea6afb80a4
Deploy Ladill Mini / deploy (push) Successful in 35s
Add Ladill Mini native Android and iOS apps.
Ship full-featured mobile clients with auth, payments, QRs, push notifications, and iOS polish including Figtree typography, app icons, and QR previews.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-11 22:30:35 +00:00

112 lines
3.3 KiB
Swift

import SwiftUI
enum AppRoute: Hashable {
case landing, login, register, pinLock, pinSetup, home
case profile, settings, security, wallet, billing, support
}
struct AppRouter: View {
@EnvironmentObject private var session: SessionStore
@State private var path = NavigationPath()
@State private var booted = false
@State private var initialRoute: AppRoute = .landing
var body: some View {
NavigationStack(path: $path) {
Group {
if !booted {
SplashView(onFinish: handleSplashFinish)
} else {
rootView
}
}
.navigationDestination(for: AppRoute.self) { route in
destination(for: route)
}
}
}
@ViewBuilder
private var rootView: some View {
switch initialRoute {
case .pinLock: PinLockView(onUnlocked: { goHome() })
case .home: HomeView(
onNavigate: { path.append($0) },
onLoggedOut: { resetToLanding() }
)
default: LandingView(
onSignIn: { path.append(AppRoute.login) },
onCreateAccount: { path.append(AppRoute.register) }
)
}
}
@ViewBuilder
private func destination(for route: AppRoute) -> some View {
switch route {
case .landing:
LandingView(
onSignIn: { path.append(AppRoute.login) },
onCreateAccount: { path.append(AppRoute.register) }
)
case .login:
LoginView(
onLoggedIn: { goHome() },
onCreateAccount: {
path.removeLast(path.count)
path.append(AppRoute.register)
},
onBack: { path.removeLast() }
)
case .register:
RegisterView(
onRegistered: { goHome() },
onSignIn: {
path.removeLast(path.count)
path.append(AppRoute.login)
},
onBack: { path.removeLast() }
)
case .pinLock:
PinLockView(onUnlocked: { goHome() })
case .pinSetup:
PinSetupView(onPinSet: { goHome() })
case .home:
HomeView(onNavigate: { path.append($0) }, onLoggedOut: { resetToLanding() })
case .profile:
ProfileView(onBack: { path.removeLast() })
case .settings:
SettingsView(onBack: { path.removeLast() })
case .security:
SecurityView(onBack: { path.removeLast() })
case .wallet:
WalletView(onBack: { path.removeLast() })
case .billing:
BillingView(onBack: { path.removeLast() })
case .support:
SupportView(onBack: { path.removeLast() })
}
}
private func handleSplashFinish() {
booted = true
if session.isLoggedIn {
initialRoute = PinStore.shared.hasPin() ? .pinLock : .home
} else {
initialRoute = .landing
}
}
private func goHome() {
path = NavigationPath()
initialRoute = .home
booted = true
}
private func resetToLanding() {
path = NavigationPath()
initialRoute = .landing
booted = true
}
}