From bb384705ca1a3ad93a18a2062dbf567c60a8cbfa Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Wed, 28 May 2025 11:24:35 +0100 Subject: [PATCH] Fix a couple of crashes on macOS from a missing environment object. (#4153) --- .../Sources/Screens/Timeline/View/TimelineView.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ElementX/Sources/Screens/Timeline/View/TimelineView.swift b/ElementX/Sources/Screens/Timeline/View/TimelineView.swift index 8cbffded9..b01725166 100644 --- a/ElementX/Sources/Screens/Timeline/View/TimelineView.swift +++ b/ElementX/Sources/Screens/Timeline/View/TimelineView.swift @@ -14,6 +14,10 @@ struct TimelineView: View { var body: some View { TimelineViewRepresentable() .id(timelineContext.viewState.roomID) + // It is tempting to inject these environment values last to avoid also injecting them into the sheets, + // and that approach works great on iOS. But it doesn't work on macOS (as of 15.5) where the app goes 💥 + .environmentObject(timelineContext) + .environment(\.timelineContext, timelineContext) .environment(\.focussedEventID, timelineContext.viewState.timelineState.focussedEvent?.eventID) .alert(item: $timelineContext.alertInfo) .sheet(item: $timelineContext.manageMemberViewModel) { @@ -33,6 +37,7 @@ struct TimelineView: View { .makeActions() if let actions { TimelineItemMenu(item: info.item, actions: actions) + .environmentObject(timelineContext) } } .sheet(item: $timelineContext.reactionSummaryInfo) { @@ -44,10 +49,8 @@ struct TimelineView: View { } .sheet(item: $timelineContext.readReceiptsSummaryInfo) { ReadReceiptsSummaryView(orderedReadReceipts: $0.orderedReceipts) + .environmentObject(timelineContext) } - // Ensure these are available in the sheets as well. The order is important. - .environmentObject(timelineContext) - .environment(\.timelineContext, timelineContext) } }