This commit is contained in:
Daniel Arantes Loverde
2026-03-10 09:19:50 -03:00
parent 728cc94525
commit 5fa98ce358
15 changed files with 570 additions and 94 deletions

View File

@@ -6,6 +6,11 @@ struct ContentView: View {
private let tokenStore: TokenStore = DefaultTokenStore()
@State var appState = AppState()
@State var isBootstrappingSession = false
@State var hasPerformedInitialLaunchBootstrap = false
@State var showLaunchSplash = true
@State var shouldPulseLaunchSplash = true
@State var shouldPrepareAuthEntryAnimation = DefaultTokenStore().jwt == nil
@State var authEntryAnimationToken = 0
#if os(iOS)
@State private var sessionExpiredObserver: NSObjectProtocol?
#endif
@@ -20,7 +25,14 @@ struct ContentView: View {
Group {
switch root {
case .auth:
AuthFlowView(root: $root, selectedTab: $selectedTab, tokenStore: tokenStore, appState: $appState)
AuthFlowView(
root: $root,
selectedTab: $selectedTab,
tokenStore: tokenStore,
appState: $appState,
shouldPrepareLoginEntry: shouldPrepareAuthEntryAnimation,
authEntryAnimationToken: authEntryAnimationToken
)
case .main:
if isBootstrappingSession {
sessionBootstrapLoadingView
@@ -31,6 +43,11 @@ struct ContentView: View {
}
SnackbarOverlay(center: snackbarCenter)
if showLaunchSplash {
LaunchSplashView(shouldPulse: shouldPulseLaunchSplash)
.transition(.opacity)
}
}
.sheet(item: $appState.activeModal) { modal in
switch modal {
@@ -55,8 +72,15 @@ struct ContentView: View {
.onReceive(NotificationCenter.default.publisher(for: .cartDidReset)) { _ in
appState.cart = CartState()
}
.task(id: root) {
await bootstrapSessionStateIfNeeded()
.task {
await performInitialLaunchBootstrap()
}
.onChange(of: root) { _, newValue in
if newValue == .main {
Task {
await bootstrapSessionStateIfNeeded()
}
}
}
.onAppear {
#if os(iOS)
@@ -81,6 +105,43 @@ struct ContentView: View {
.background(AppColors.backgroundLight)
}
@MainActor
private func performInitialLaunchBootstrap() async {
guard hasPerformedInitialLaunchBootstrap == false else { return }
hasPerformedInitialLaunchBootstrap = true
let start = Date()
await bootstrapSessionStateIfNeeded()
// Keep the in-app splash visible long enough to avoid abrupt transition
// between native launch screen and app content.
let elapsed = Date().timeIntervalSince(start)
let minimumSplashDuration: TimeInterval = 1.0
if elapsed < minimumSplashDuration {
let remaining = minimumSplashDuration - elapsed
let nanoseconds = UInt64(remaining * 1_000_000_000)
try? await Task.sleep(nanoseconds: nanoseconds)
}
if root == .auth {
shouldPrepareAuthEntryAnimation = true
shouldPulseLaunchSplash = false
try? await Task.sleep(nanoseconds: 180_000_000)
withAnimation(.easeInOut(duration: 0.34)) {
showLaunchSplash = false
}
try? await Task.sleep(nanoseconds: 360_000_000)
authEntryAnimationToken += 1
scheduleDisableAuthEntryPreparation()
return
}
shouldPulseLaunchSplash = false
withAnimation(.easeOut(duration: 0.28)) {
showLaunchSplash = false
}
}
@MainActor
private func bootstrapSessionStateIfNeeded() async {
guard root == .main else { return }
@@ -215,7 +276,17 @@ struct ContentView: View {
isBootstrappingSession = false
appState = AppState()
selectedTab = .home
shouldPrepareAuthEntryAnimation = true
root = .auth
authEntryAnimationToken += 1
scheduleDisableAuthEntryPreparation()
}
private func scheduleDisableAuthEntryPreparation() {
Task { @MainActor in
try? await Task.sleep(nanoseconds: 900_000_000)
shouldPrepareAuthEntryAnimation = false
}
}
private func hasConfiguredAddress() -> Bool {