diff --git a/Sources/FireUI/AppStyle/ViewStylizer.swift b/Sources/FireUI/AppStyle/ViewStylizer.swift index ec272e0..fbc86fb 100644 --- a/Sources/FireUI/AppStyle/ViewStylizer.swift +++ b/Sources/FireUI/AppStyle/ViewStylizer.swift @@ -8,20 +8,19 @@ import SwiftUI public extension View { - func viewStyle(label: String, systemImage: String, selection: Binding, tag: SelectionValue) -> some View { - modifier(ViewStylizer(label: label, systemImage: systemImage, selection: selection, tag: tag)) + func viewStyle(_ state: AppState, label: String, systemImage: String, selection: Binding, tag: SelectionValue) -> some View { + modifier(ViewStylizer(state: state, label: label, systemImage: systemImage, selection: selection, tag: tag)) } } public struct ViewStylizer: ViewModifier { + @ObservedObject public var state: AppState public let label: String public let systemImage: String @Binding public var selection: SelectionValue? public let tag: SelectionValue - @EnvironmentObject fileprivate var state: AppState - public func body(content: Content) -> some View { #if os(iOS) switch UIDevice.current.userInterfaceIdiom { diff --git a/Sources/FireUI/DemoContent.swift b/Sources/FireUI/DemoContent.swift index 2fc8139..026caf2 100644 --- a/Sources/FireUI/DemoContent.swift +++ b/Sources/FireUI/DemoContent.swift @@ -44,6 +44,8 @@ class DemoAppState: FireState { } public protocol SelectedView: RawRepresentable, Hashable, CaseIterable, Identifiable { + associatedtype SelectionValue = Hashable + var id: String { get } var systemImage: String { get } } @@ -55,19 +57,28 @@ struct DemoContentView: View { @EnvironmentObject private var state: DemoAppState - enum Tab: String { + enum Tab: String, SelectedView { case a, b - + var id: String { rawValue } + var systemImage: String { + switch self { + case .a: + return "circle" + case .b: + return "square" + } + } } var body: some View { Text("Hello, World!") .padding() .viewStyle( - label: "A", - systemImage: "circle.fill", + state, + label: Tab.a.label, + systemImage: Tab.a.systemImage, selection: $state.selectedViewIdentifier, - tag: "a" + tag: Tab.a.id ) } }