From 77e4fae2fb879d8daec1aaa318ff22e5bc4b3fba Mon Sep 17 00:00:00 2001 From: Doug Date: Tue, 1 Oct 2024 13:34:16 +0100 Subject: [PATCH] Use the new @Entry macro everywhere. Fix analytics service optionality. --- .../RoomScreen/RoomScreenViewModel.swift | 12 ------------ .../Screens/Timeline/TimelineViewModel.swift | 19 ++----------------- .../Timeline/View/Style/TimelineStyle.swift | 9 +-------- .../Analytics/Helpers/Analytics+SwiftUI.swift | 9 +-------- 4 files changed, 4 insertions(+), 45 deletions(-) diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 990d30408..b58e04c1a 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -203,15 +203,3 @@ extension RoomScreenViewModel { analyticsService: ServiceLocator.shared.analytics) } } - -private struct RoomContextKey: EnvironmentKey { - @MainActor static let defaultValue: RoomScreenViewModel.Context? = nil -} - -extension EnvironmentValues { - /// Used to access and inject the room context without observing it - var roomContext: RoomScreenViewModel.Context? { - get { self[RoomContextKey.self] } - set { self[RoomContextKey.self] = newValue } - } -} diff --git a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift index e6d37a7df..517cc7d56 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift @@ -865,26 +865,11 @@ extension TimelineViewModel { analyticsService: ServiceLocator.shared.analytics) } -private struct TimelineContextKey: EnvironmentKey { - @MainActor static let defaultValue: TimelineViewModel.Context? = nil -} - -private struct FocussedEventID: EnvironmentKey { - static let defaultValue: String? = nil -} - extension EnvironmentValues { /// Used to access and inject the room context without observing it - var timelineContext: TimelineViewModel.Context? { - get { self[TimelineContextKey.self] } - set { self[TimelineContextKey.self] = newValue } - } - + @Entry var timelineContext: TimelineViewModel.Context? /// An event ID which will be non-nil when a timeline item should show as focussed. - var focussedEventID: String? { - get { self[FocussedEventID.self] } - set { self[FocussedEventID.self] = newValue } - } + @Entry var focussedEventID: String? } private enum SlashCommand: String, CaseIterable { diff --git a/ElementX/Sources/Screens/Timeline/View/Style/TimelineStyle.swift b/ElementX/Sources/Screens/Timeline/View/Style/TimelineStyle.swift index b8294a041..7726cee0f 100644 --- a/ElementX/Sources/Screens/Timeline/View/Style/TimelineStyle.swift +++ b/ElementX/Sources/Screens/Timeline/View/Style/TimelineStyle.swift @@ -26,13 +26,6 @@ enum TimelineGroupStyle: Hashable { // MARK: - Environment -private struct TimelineGroupStyleKey: EnvironmentKey { - static let defaultValue = TimelineGroupStyle.single -} - extension EnvironmentValues { - var timelineGroupStyle: TimelineGroupStyle { - get { self[TimelineGroupStyleKey.self] } - set { self[TimelineGroupStyleKey.self] = newValue } - } + @Entry var timelineGroupStyle: TimelineGroupStyle = .single } diff --git a/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift b/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift index cdc573bc6..2c5247b86 100644 --- a/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift +++ b/ElementX/Sources/Services/Analytics/Helpers/Analytics+SwiftUI.swift @@ -7,13 +7,6 @@ import SwiftUI -private struct AnalyticsServiceKey: EnvironmentKey { - static let defaultValue: AnalyticsService = ServiceLocator.shared.analytics -} - extension EnvironmentValues { - var analyticsService: AnalyticsService { - get { self[AnalyticsServiceKey.self] } - set { self[AnalyticsServiceKey.self] = newValue } - } + @Entry var analyticsService: AnalyticsService = ServiceLocator.shared.analytics }