From 56b9457fcf7ef5372cbba546b025eab27d6aec29 Mon Sep 17 00:00:00 2001 From: Anthony Biasi Date: Wed, 26 Nov 2025 08:25:23 -0700 Subject: [PATCH] fix(macos): Propagate ChatViewModel environment object to sheet presentations Fixes crash on macOS when presenting sheets due to missing @EnvironmentObject. Added .environmentObject(viewModel) to 8 sheet/fullScreenCover presentations. Fixed presentations: - AppInfoView sheet - FingerprintView sheet - ImagePickerView fullScreenCover (iOS, both contexts) - MacImagePickerView sheet (macOS, both contexts) - ImagePreviewView sheet - LocationChannelsSheet sheet Tested on macOS 26.1 (Apple Silicon M4). All sheet presentations now open without crash. Platform: macOS only Impact: Resolves EnvironmentObject.error() crashes --- bitchat/Views/ContentView.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bitchat/Views/ContentView.swift b/bitchat/Views/ContentView.swift index 544befc7..ba69c959 100644 --- a/bitchat/Views/ContentView.swift +++ b/bitchat/Views/ContentView.swift @@ -189,6 +189,7 @@ struct ContentView: View { } .sheet(isPresented: $showAppInfo) { AppInfoView() + .environmentObject(viewModel) .onAppear { viewModel.isAppInfoPresented = true } .onDisappear { viewModel.isAppInfoPresented = false } } @@ -198,6 +199,7 @@ struct ContentView: View { )) { if let peerID = viewModel.showingFingerprintFor { FingerprintView(viewModel: viewModel, peerID: peerID) + .environmentObject(viewModel) } } #if os(iOS) @@ -225,6 +227,7 @@ struct ContentView: View { } } } + .environmentObject(viewModel) .ignoresSafeArea() } #endif @@ -253,6 +256,7 @@ struct ContentView: View { } } } + .environmentObject(viewModel) } #endif .sheet(isPresented: Binding( @@ -261,6 +265,7 @@ struct ContentView: View { )) { if let url = imagePreviewURL { ImagePreviewView(url: url) + .environmentObject(viewModel) } } .alert("Recording Error", isPresented: $showRecordingAlert, actions: { @@ -825,6 +830,7 @@ struct ContentView: View { } } } + .environmentObject(viewModel) .ignoresSafeArea() } #endif @@ -845,6 +851,7 @@ struct ContentView: View { } } } + .environmentObject(viewModel) } #endif } @@ -1382,6 +1389,7 @@ struct ContentView: View { .padding(.horizontal, 12) .sheet(isPresented: $showLocationChannelsSheet) { LocationChannelsSheet(isPresented: $showLocationChannelsSheet) + .environmentObject(viewModel) .onAppear { viewModel.isLocationChannelsSheetPresented = true } .onDisappear { viewModel.isLocationChannelsSheetPresented = false } }