Skip to content

Commit

Permalink
update things
Browse files Browse the repository at this point in the history
  • Loading branch information
Brianna Doubt committed Oct 23, 2021
1 parent 4987619 commit d88a9c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
7 changes: 3 additions & 4 deletions Sources/FireUI/AppStyle/ViewStylizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
import SwiftUI

public extension View {
func viewStyle<SelectionValue: Hashable, AppState: FireState>(label: String, systemImage: String, selection: Binding<SelectionValue?>, tag: SelectionValue) -> some View {
modifier(ViewStylizer<SelectionValue, AppState>(label: label, systemImage: systemImage, selection: selection, tag: tag))
func viewStyle<SelectionValue: Hashable, AppState: FireState>(_ state: AppState, label: String, systemImage: String, selection: Binding<SelectionValue?>, tag: SelectionValue) -> some View {
modifier(ViewStylizer<SelectionValue, AppState>(state: state, label: label, systemImage: systemImage, selection: selection, tag: tag))
}
}

public struct ViewStylizer<SelectionValue: Hashable, AppState: FireState>: 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 {
Expand Down
21 changes: 16 additions & 5 deletions Sources/FireUI/DemoContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand All @@ -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
)
}
}
Expand Down

0 comments on commit d88a9c2

Please sign in to comment.