Fix crash al abrir Import Data en Mac Catalyst (@EnvironmentObject no heredado en sheets)

ImportDataView usa @EnvironmentObject (iapService/accountStore/tabSelection).
En Mac (Designed for iPad) las sheets no heredan el environment vía
PresentationHostingController → EnvironmentObject.error() / SIGTRAP al abrir
Import Data (ImportDataView.swift:247, shouldShowAccountSelection). Reinyectados
los 3 objects en las sheets de Settings, Dashboard y Onboarding.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L2p3gUZRNWW388rWFRjiU7
This commit is contained in:
alexandrev-tibco
2026-07-23 11:02:56 +02:00
parent d50926df76
commit 9539803d74
3 changed files with 21 additions and 0 deletions
@@ -6,6 +6,7 @@ import TipKit
struct DashboardView: View {
@EnvironmentObject var iapService: IAPService
@EnvironmentObject var accountStore: AccountStore
@EnvironmentObject var tabSelection: TabSelectionStore
@StateObject private var viewModel: DashboardViewModel
@StateObject private var goalsViewModel = GoalsViewModel()
@State private var showingImport = false
@@ -110,7 +111,12 @@ struct DashboardView: View {
goalsViewModel.refresh()
}
.sheet(isPresented: $showingImport) {
// Re-inject env objects: sheets don't inherit @EnvironmentObject on
// Mac Catalyst (Designed for iPad) ImportDataView crashed on open.
ImportDataView()
.environmentObject(iapService)
.environmentObject(accountStore)
.environmentObject(tabSelection)
}
.sheet(isPresented: $showingAddSource) {
AddSourceView()
@@ -13,6 +13,12 @@ struct OnboardingView: View {
@State private var showingImportSheet = false
@State private var showingAddSource = false
// Forwarded into the ImportDataView sheet sheets don't inherit
// @EnvironmentObject on Mac Catalyst, which crashed the import screen.
@EnvironmentObject private var iapService: IAPService
@EnvironmentObject private var accountStore: AccountStore
@EnvironmentObject private var tabSelection: TabSelectionStore
private let pages: [OnboardingPage] = [
OnboardingPage(
icon: "chart.line.uptrend.xyaxis",
@@ -123,6 +129,9 @@ struct OnboardingView: View {
}
.sheet(isPresented: $showingImportSheet) {
ImportDataView(importContext: .onboarding)
.environmentObject(iapService)
.environmentObject(accountStore)
.environmentObject(tabSelection)
}
.sheet(isPresented: $showingAddSource) {
AddSourceView()
@@ -6,6 +6,8 @@ struct SettingsView: View {
private let iapService: IAPService
@StateObject private var viewModel: SettingsViewModel
@EnvironmentObject private var adMobService: AdMobService
@EnvironmentObject private var accountStore: AccountStore
@EnvironmentObject private var tabSelection: TabSelectionStore
@AppStorage("showForecast") private var showForecast = true
@AppStorage("cloudSyncEnabled") private var cloudSyncEnabled = false
@AppStorage("faceIdEnabled") private var faceIdEnabled = false
@@ -86,7 +88,11 @@ struct SettingsView: View {
ActivityView(activityItems: [shareItem.url])
}
.sheet(isPresented: $viewModel.showingImportSheet) {
// Sheets don't inherit @EnvironmentObject on Mac Catalyst re-inject.
ImportDataView()
.environmentObject(iapService)
.environmentObject(accountStore)
.environmentObject(tabSelection)
}
.confirmationDialog(
"Reset All Data",