Primera build enviada
This commit is contained in:
@@ -60,15 +60,8 @@ struct ContentView: View {
|
||||
isUnlocked = false
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if coreDataStack.isLoaded {
|
||||
syncOnboardingState()
|
||||
}
|
||||
}
|
||||
.onChange(of: coreDataStack.isLoaded) { _, loaded in
|
||||
if loaded {
|
||||
syncOnboardingState()
|
||||
}
|
||||
.task {
|
||||
await waitForDataAndResolveOnboarding()
|
||||
}
|
||||
.onChange(of: onboardingCompleted) { _, completed in
|
||||
resolvedOnboardingCompleted = completed
|
||||
@@ -79,12 +72,28 @@ struct ContentView: View {
|
||||
coreDataStack.isLoaded && resolvedOnboardingCompleted != nil
|
||||
}
|
||||
|
||||
private func waitForDataAndResolveOnboarding() async {
|
||||
// Wait for Core Data to be loaded
|
||||
while !coreDataStack.isLoaded {
|
||||
try? await Task.sleep(nanoseconds: 50_000_000) // 50ms
|
||||
}
|
||||
|
||||
// Resolve onboarding state on main thread
|
||||
await MainActor.run {
|
||||
syncOnboardingState()
|
||||
}
|
||||
}
|
||||
|
||||
private func syncOnboardingState() {
|
||||
let settings = AppSettings.getOrCreate(in: coreDataStack.viewContext)
|
||||
var resolved = settings.onboardingCompleted || onboardingCompleted
|
||||
|
||||
// If user has existing data, skip onboarding
|
||||
if !resolved && hasExistingData() {
|
||||
resolved = true
|
||||
}
|
||||
|
||||
// Persist the resolved state
|
||||
if settings.onboardingCompleted != resolved {
|
||||
settings.onboardingCompleted = resolved
|
||||
CoreDataStack.shared.save()
|
||||
@@ -92,6 +101,7 @@ struct ContentView: View {
|
||||
if onboardingCompleted != resolved {
|
||||
onboardingCompleted = resolved
|
||||
}
|
||||
|
||||
resolvedOnboardingCompleted = resolved
|
||||
}
|
||||
|
||||
@@ -121,39 +131,41 @@ struct ContentView: View {
|
||||
private var mainContent: some View {
|
||||
ZStack {
|
||||
TabView(selection: $tabSelection.selectedTab) {
|
||||
DashboardView()
|
||||
bannerInsetView(DashboardView())
|
||||
.tabItem {
|
||||
Label("Home", systemImage: "house.fill")
|
||||
}
|
||||
.tag(0)
|
||||
|
||||
SourceListView(iapService: iapService)
|
||||
bannerInsetView(SourceListView(iapService: iapService))
|
||||
.tabItem {
|
||||
Label("Sources", systemImage: "list.bullet")
|
||||
}
|
||||
.tag(1)
|
||||
|
||||
ChartsContainerView(iapService: iapService)
|
||||
bannerInsetView(ChartsContainerView(iapService: iapService))
|
||||
.tabItem {
|
||||
Label("Charts", systemImage: "chart.xyaxis.line")
|
||||
}
|
||||
.tag(2)
|
||||
|
||||
JournalView()
|
||||
bannerInsetView(JournalView())
|
||||
.tabItem {
|
||||
Label("Journal", systemImage: "book.closed")
|
||||
}
|
||||
.tag(3)
|
||||
|
||||
SettingsView(iapService: iapService)
|
||||
bannerInsetView(SettingsView(iapService: iapService))
|
||||
.tabItem {
|
||||
Label("Settings", systemImage: "gearshape.fill")
|
||||
}
|
||||
.tag(4)
|
||||
}
|
||||
}
|
||||
// Banner ad at bottom for free users
|
||||
.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||
}
|
||||
|
||||
private func bannerInsetView<Content: View>(_ content: Content) -> some View {
|
||||
content.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||
if !iapService.isPremium {
|
||||
BannerAdView()
|
||||
.frame(height: AppConstants.UI.bannerAdHeight)
|
||||
|
||||
Reference in New Issue
Block a user