Skip to content

Commit

Permalink
add feature flag handle for stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ry-itto committed Sep 3, 2023
1 parent e5f0fe3 commit 6d505d7
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 67 deletions.
147 changes: 80 additions & 67 deletions app-ios/Modules/Sources/Navigation/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,88 +18,101 @@ enum Tab {
}

public struct RootView: View {
@ObservedObject var viewModel: RootViewModel = .init()
@State var selection = Tab.timeline

public init() {}

public var body: some View {
TabView(selection: $selection) {
TimetableView(
sessionViewBuilder: { timetableItem in
SessionView(timetableItem: timetableItem)
switch viewModel.state.isStampEnabled {
case .initial, .loading:
ProgressView()
.task {
await viewModel.load()
}
)
.tag(Tab.timeline)
.tabItem {
Label {
Text("Timetable")
} icon: {
if selection == .timeline {
Assets.Icons.timetable.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.timetableFillOff.swiftUIImage
.renderingMode(.template)
}
case .failed:
EmptyView()
case .loaded(let isStampEnabled):
TabView(selection: $selection) {
TimetableView(
sessionViewBuilder: { timetableItem in
SessionView(timetableItem: timetableItem)
}
}
FloorMapView()
.tag(Tab.floorMap)
.tabItem {
Label {
Text("FloorMap")
} icon: {
if selection == .floorMap {
Assets.Icons.floorMap.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.floorMapFillOff.swiftUIImage
.renderingMode(.template)
)
.tag(Tab.timeline)
.tabItem {
Label {
Text("Timetable")
} icon: {
if selection == .timeline {
Assets.Icons.timetable.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.timetableFillOff.swiftUIImage
.renderingMode(.template)
}
}
}
}
StampsView()
.tag(Tab.stamps)
.tabItem {
Label {
Text("Stamps")
} icon: {
if selection == .stamps {
Assets.Icons.stamp.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.stampFillOff.swiftUIImage
.renderingMode(.template)
FloorMapView()
.tag(Tab.floorMap)
.tabItem {
Label {
Text("FloorMap")
} icon: {
if selection == .floorMap {
Assets.Icons.floorMap.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.floorMapFillOff.swiftUIImage
.renderingMode(.template)
}
}
}
if isStampEnabled {
StampsView()
.tag(Tab.stamps)
.tabItem {
Label {
Text("Stamps")
} icon: {
if selection == .stamps {
Assets.Icons.stamp.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.stampFillOff.swiftUIImage
.renderingMode(.template)
}
}
}
}
AboutView(
contributorViewProvider: { _ in
ContributorView()
},
staffViewProvider: { _ in
StaffView()
},
sponsorViewProvider: { _ in
SponsorView()
}
)
.tag(Tab.about)
.tabItem {
Label {
Text("About")
} icon: {
if selection == .about {
Assets.Icons.info.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.infoFillOff.swiftUIImage
.renderingMode(.template)
AboutView(
contributorViewProvider: { _ in
ContributorView()
},
staffViewProvider: { _ in
StaffView()
},
sponsorViewProvider: { _ in
SponsorView()
}
)
.tag(Tab.about)
.tabItem {
Label {
Text("About")
} icon: {
if selection == .about {
Assets.Icons.info.swiftUIImage
.renderingMode(.template)
} else {
Assets.Icons.infoFillOff.swiftUIImage
.renderingMode(.template)
}
}
}
}
}
.tint(AssetColors.Secondary.onSecondaryContainer.swiftUIColor)
}
.tint(AssetColors.Secondary.onSecondaryContainer.swiftUIColor)
}
}

Expand Down
26 changes: 26 additions & 0 deletions app-ios/Modules/Sources/Navigation/RootViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Dependencies
import Foundation
import KMPContainer
import Model

struct RootViewState: ViewModelState {
var isStampEnabled: LoadingState<Bool> = .initial
}

@MainActor
class RootViewModel: ObservableObject {
@Dependency(\.stampData) var stampData
@Published var state: RootViewState = .init()

func load() async {
state.isStampEnabled = .loading

do {
for try await isStampEnabled in stampData.stampEnabled() {
state.isStampEnabled = .loaded(isStampEnabled)
}
} catch {
state.isStampEnabled = .failed(error)
}
}
}

0 comments on commit 6d505d7

Please sign in to comment.