Skip to content

Commit

Permalink
Merge pull request #794 from coffmark/feature/use-navigationstack
Browse files Browse the repository at this point in the history
[iOS][#789] Use NavigationStack
  • Loading branch information
ry-itto authored Oct 1, 2022
2 parents 75dbfc6 + 995a75d commit f3dbfc2
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 80 deletions.
19 changes: 13 additions & 6 deletions app-ios/Sources/AboutFeature/AboutNavigationItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,45 @@ struct AboutNavigationItem {
let image: ImageAsset
let title: String
let action: AboutAction
let destination: AboutDestination?

static var items: [Self] {
[
AboutNavigationItem(
image: AboutViewAssets.train,
title: StringsKt.shared.about_access.localized(),
action: .openAccess
action: .openAccess,
destination: nil
),
AboutNavigationItem(
image: AboutViewAssets.person,
title: StringsKt.shared.about_staff.localized(),
action: .openStaffs
action: .openStaffs,
destination: .staffs
),
AboutNavigationItem(
image: AboutViewAssets.people,
title: StringsKt.shared.title_contributors.localized(),
action: .openContributors
action: .openContributors,
destination: .contributor
),
AboutNavigationItem(
image: AboutViewAssets.company,
title: StringsKt.shared.title_sponsors.localized(),
action: .openSponsors
action: .openSponsors,
destination: .sponsor
),
AboutNavigationItem(
image: AboutViewAssets.shield,
title: StringsKt.shared.about_privacy.localized(),
action: .openPrivacyPolicy
action: .openPrivacyPolicy,
destination: nil
),
AboutNavigationItem(
image: AboutViewAssets.folder,
title: StringsKt.shared.about_license.localized(),
action: .openLicense
action: .openLicense,
destination: .license
),
]
}
Expand Down
17 changes: 17 additions & 0 deletions app-ios/Sources/AboutFeature/AboutNavigationItemView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

struct AboutNavigationItemView: View {
let image: Image
let title: String

var body: some View {
HStack(spacing: 12) {
image
.renderingMode(.template)
Text(title)
Spacer()
}
.padding(16)
.frame(minHeight: 56)
}
}
97 changes: 34 additions & 63 deletions app-ios/Sources/AboutFeature/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import StaffFeature
import SwiftUI
import Theme

public enum AboutDestination {
case none
public enum AboutDestination: Hashable {
case staffs
case license
case contributor
Expand All @@ -19,23 +18,19 @@ public struct AboutState: Equatable {
public var staffState: StaffState
public var contributorState: ContributorState
public var sponsorState: SponsorState
public var navigationDestination: AboutDestination

public init(
staffState: StaffState = .init(),
contributorState: ContributorState = .init(),
sponsorState: SponsorState = .init(),
navigationDestination: AboutDestination = .none
sponsorState: SponsorState = .init()
) {
self.staffState = staffState
self.contributorState = contributorState
self.sponsorState = sponsorState
self.navigationDestination = navigationDestination
}
}

public enum AboutAction {
case backToTop
case openAccess
case openStaffs
case openContributors
Expand Down Expand Up @@ -92,22 +87,15 @@ public let aboutReducer = Reducer<AboutState, AboutAction, AboutEnvironment>.com
)
}
),
.init { state, action, environment in
.init { _, action, environment in
switch action {
case .backToTop:
state.navigationDestination = .none
return .none
case .openLicense:
state.navigationDestination = .license
return .none
case .openStaffs:
state.navigationDestination = .staffs
return .none
case .openContributors:
state.navigationDestination = .contributor
return .none
case .openSponsors:
state.navigationDestination = .sponsor
return .none
case .openAccess:
environment.openURL(URL(string: StaticURLs.access)!)
Expand All @@ -134,7 +122,7 @@ public struct AboutView: View {

public var body: some View {
WithViewStore(store) { viewStore in
NavigationView {
NavigationStack {
ScrollView {
AboutViewAssets.logoCharacter.swiftUIImage
VStack(alignment: .leading, spacing: 24) {
Expand Down Expand Up @@ -165,17 +153,16 @@ public struct AboutView: View {
.padding(.horizontal, 45)

ForEach(AboutNavigationItem.items, id: \.title) { item in
Button {
viewStore.send(item.action)
} label: {
HStack(spacing: 12) {
item.image.swiftUIImage
.renderingMode(.template)
Text(item.title)
Spacer()
if let destination = item.destination {
NavigationLink(value: destination, label: {
AboutNavigationItemView(image: item.image.swiftUIImage, title: item.title)
})
} else {
Button {
viewStore.send(item.action)
} label: {
AboutNavigationItemView(image: item.image.swiftUIImage, title: item.title)
}
.padding(16)
.frame(minHeight: 56)
}
}
.padding(.horizontal, 29)
Expand All @@ -195,47 +182,31 @@ public struct AboutView: View {

Spacer()
.frame(height: 32)

NavigationLink(isActive: Binding<Bool>(
get: {
viewStore.navigationDestination != .none
}, set: { newValue in
if !newValue {
viewStore.send(.backToTop)
}
}), destination: {
switch viewStore.state.navigationDestination {
case .none:
EmptyView()
case .staffs:
StaffView(
store: store.scope(state: \.staffState, action: AboutAction.staff)
)
case .license:
AboutLicenseView()
case .contributor:
ContributorView(
store: store.scope(
state: \.contributorState,
action: AboutAction.contributor
)
)
case .sponsor:
SponsorView(
store: store.scope(
state: \.sponsorState,
action: AboutAction.sponsor
)
)
}
}, label: {
EmptyView()
}
)
}
.foregroundColor(AssetColors.onBackground.swiftUIColor)
.background(AssetColors.background.swiftUIColor)
.navigationBarHidden(true)
.navigationDestination(for: AboutDestination.self) { destination in
switch destination {
case .staffs:
StaffView(
store: store.scope(state: \.staffState, action: AboutAction.staff)
)
case .license:
AboutLicenseView()
case .contributor:
ContributorView(
store: store.scope(state: \.contributorState, action: AboutAction.contributor)
)
case .sponsor:
SponsorView(
store: store.scope(
state: \.sponsorState,
action: AboutAction.sponsor
)
)
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Sources/AnnouncementFeature/AnnouncementView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct AnnouncementView: View {

public var body: some View {
WithViewStore(store) { viewStore in
NavigationView {
NavigationStack {
ZStack {
AssetColors.background.swiftUIColor
if !viewStore.isLoaded {
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Sources/ContributorFeature/ContributorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct ListItemButtonStyle: ButtonStyle {
#if DEBUG
struct ContributorView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
NavigationStack {
ContributorView(
store: .init(
initialState: .init(
Expand Down
7 changes: 3 additions & 4 deletions app-ios/Sources/MapFeature/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ public struct MapView: View {

public var body: some View {
WithViewStore(store) { viewStore in
NavigationView {
NavigationStack {
ZStack {
AssetColors.background.swiftUIColor
Image(asset: Assets.floorMap)
.resizable()
.scaledToFit()
.padding(14)
.navigationTitle(StringsKt.shared.title_map.localized())
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button(
Expand All @@ -55,8 +53,9 @@ public struct MapView: View {
}
}
}
.navigationTitle(StringsKt.shared.title_map.localized())
.navigationBarTitleDisplayMode(.inline)
}
.navigationViewStyle(.stack)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Sources/SearchFeature/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public struct SearchView: View {

public var body: some View {
WithViewStore(store) { viewStore in
NavigationView {
NavigationStack {
Group {
if viewStore.searchResult.values.allSatisfy(\.timetableItems.isEmpty) {
EmptyResultView()
Expand Down
4 changes: 2 additions & 2 deletions app-ios/Sources/SponsorFeature/SponsorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct SponsorItemView: View {
#if DEBUG
struct SponsorView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
NavigationStack {
SponsorView(
store: .init(
initialState: .init(
Expand All @@ -221,7 +221,7 @@ struct SponsorView_Previews: PreviewProvider {
}
struct SponsorView_Loading_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
NavigationStack {
SponsorView(
store: .init(
initialState: .init(
Expand Down
3 changes: 1 addition & 2 deletions app-ios/Sources/TimetableFeature/TimetableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public struct TimetableView: View {

public var body: some View {
WithViewStore(store) { viewStore in
NavigationView {
NavigationStack {
ZStack(alignment: .top) {

if viewStore.state.showSheet {
Expand Down Expand Up @@ -192,7 +192,6 @@ public struct TimetableView: View {
}
.navigationBarTitleDisplayMode(.inline)
}
.navigationViewStyle(.stack)
}
}
}
Expand Down

0 comments on commit f3dbfc2

Please sign in to comment.