Skip to content

Commit

Permalink
feat(App): improve AppView (previously MainView)
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudjenny committed Apr 22, 2023
1 parent 50167bc commit f2b16e0
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 165 deletions.
8 changes: 4 additions & 4 deletions telltime/TellTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
4C5FD3DA29F1CB73008EB5C9 /* SwiftPastTenDependency in Frameworks */ = {isa = PBXBuildFile; productRef = 4C5FD3D929F1CB73008EB5C9 /* SwiftPastTenDependency */; };
4C86575425531EB20040EA04 /* RenaudJennyAboutView in Frameworks */ = {isa = PBXBuildFile; productRef = 4C86575325531EB20040EA04 /* RenaudJennyAboutView */; };
4CB1D4BC22A7293300786385 /* TellTimeUKApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB1D4BB22A7293300786385 /* TellTimeUKApp.swift */; };
4CB1D4C022A7293300786385 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB1D4BF22A7293300786385 /* MainView.swift */; };
4CB1D4C022A7293300786385 /* AppView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB1D4BF22A7293300786385 /* AppView.swift */; };
4CB1D4C222A7293500786385 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4CB1D4C122A7293500786385 /* Assets.xcassets */; };
4CB1D4C522A7293500786385 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4CB1D4C422A7293500786385 /* Preview Assets.xcassets */; };
4CB9C77327EB0C30006BC36E /* SwiftClockUI in Frameworks */ = {isa = PBXBuildFile; productRef = 4CB9C77227EB0C30006BC36E /* SwiftClockUI */; };
Expand Down Expand Up @@ -83,7 +83,7 @@
4CB1756329C729C200972E74 /* telltime */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = telltime; path = ..; sourceTree = "<group>"; };
4CB1D4B822A7293300786385 /* Tell Time UK.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Tell Time UK.app"; sourceTree = BUILT_PRODUCTS_DIR; };
4CB1D4BB22A7293300786385 /* TellTimeUKApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TellTimeUKApp.swift; sourceTree = "<group>"; };
4CB1D4BF22A7293300786385 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
4CB1D4BF22A7293300786385 /* AppView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppView.swift; sourceTree = "<group>"; };
4CB1D4C122A7293500786385 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
4CB1D4C422A7293500786385 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
4CB1D4C922A7293500786385 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -174,7 +174,6 @@
4C05AB5F2343FC2700970036 /* Common */,
4CB1D4C922A7293500786385 /* Info.plist */,
4CB1D4C322A7293500786385 /* Preview Content */,
4CB1D4BF22A7293300786385 /* MainView.swift */,
4C28CDB12513F72000DAE010 /* LaunchScreen.storyboard */,
);
path = TellTime;
Expand All @@ -201,6 +200,7 @@
4CFB1C6E25D7E05700AA7374 /* MainScreen */ = {
isa = PBXGroup;
children = (
4CB1D4BF22A7293300786385 /* AppView.swift */,
4CFB1C6925D726BA00AA7374 /* DateSelector.swift */,
4CFB1C6F25D7E0A800AA7374 /* Buttons.swift */,
);
Expand Down Expand Up @@ -369,7 +369,7 @@
4CFB1C7025D7E0A800AA7374 /* Buttons.swift in Sources */,
4CB1D4BC22A7293300786385 /* TellTimeUKApp.swift in Sources */,
4CFB1C6A25D726BA00AA7374 /* DateSelector.swift in Sources */,
4CB1D4C022A7293300786385 /* MainView.swift in Sources */,
4CB1D4C022A7293300786385 /* AppView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
147 changes: 147 additions & 0 deletions telltime/TellTime/MainScreen/AppView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import ConfigurationFeature
import SwiftUI
import ComposableArchitecture
import Combine
import SwiftClockUI
import RenaudJennyAboutView

struct AppView: View {
struct ViewState: Equatable {
var date: Date
var time: String?
var recognizedUtterance: String?
var clockStyle: ClockStyle
var clockConfiguration: ClockConfiguration
var isConfigurationPresented: Bool
var isAboutPresented: Bool

init(_ state: App.State) {
date = state.date
time = state.tellTime
recognizedUtterance = state.speechRecognizer.utterance
clockStyle = state.configuration.clockStyle
clockConfiguration = state.configuration.clock
isConfigurationPresented = state.configuration.isPresented
isAboutPresented = state.isAboutPresented
}
}

@Environment(\.verticalSizeClass) var verticalSizeClass: UserInterfaceSizeClass?
@Environment(\.horizontalSizeClass) var horizontalSizeClass: UserInterfaceSizeClass?

let store: StoreOf<App>

var body: some View {
WithViewStore(store.stateless) { viewStore in
NavigationView {
content
.navigationBarTitle("Tell Time")
.padding()
}
.navigationViewStyle(StackNavigationViewStyle())
.onAppear { viewStore.send(.appStarted) }
}
}

private var content: some View {
WithViewStore(store, observe: ViewState.init) { viewStore in
VStack {
if verticalSizeClass == .regular && horizontalSizeClass == .compact {
Spacer()
clockView
Spacer()
timeText
Spacer()
DateSelector(store: store)
Spacer()
Buttons(store: store)
} else if verticalSizeClass == .compact {
HStack {
clockView(viewStore: viewStore).padding()
VStack {
timeText(viewStore: viewStore)
Spacer()
DateSelector(store: store)
Spacer()
Buttons(store: store)
}
}
} else {
VStack {
clockView(viewStore: viewStore).padding()
VStack {
timeText(viewStore: viewStore)
DateSelector(store: store)
}
HStack {
Spacer()
Buttons(store: store)
Spacer()
}
}
}
navigationLinks(viewStore: viewStore)
}
}
}

private var clockView: some View {
WithViewStore(store, observe: ViewState.init) { viewStore in
ClockView()
.environment(\.clockDate, viewStore.binding(get: \.date, send: App.Action.setDate))
.environment(\.clockStyle, viewStore.clockStyle)
.environment(\.clockConfiguration, viewStore.clockConfiguration)
}
}

private var timeText: some View {
WithViewStore(store, observe: { $0.tellTime }) { viewStore in
viewStore.state.map { time in
Text(time)
.font(.title2)
.foregroundColor(.red)
.padding()
}
}
}

private var navigationLinks: some View {
WithViewStore(store, observe: ViewState.init) { viewStore in
VStack {
NavigationLink(
destination: ConfigurationView(store: store.scope(
state: \.configuration,
action: { App.Action.configuration($0) }
)),
isActive: viewStore.binding(get: \.isConfigurationPresented, send: App.Action.configuration(.hide)),
label: EmptyView.init
)
NavigationLink(
destination: AboutView(appId: "id1496541173") {
Image(uiImage: #imageLiteral(resourceName: "Logo")).shadow(radius: 5)
},
isActive: viewStore.binding(get: \.isAboutPresented, send: App.Action.hideAbout),
label: EmptyView.init
)
}
}
}
}

#if DEBUG
struct AppView_Previews: PreviewProvider {
static var previews: some View {
Group {
AppView(store: .preview)
AppView(store: .preview)
.previewLayout(.fixed(width: 800, height: 400))
.preferredColorScheme(.dark)
.environment(\.horizontalSizeClass, .compact)
.environment(\.verticalSizeClass, .compact)
AppView(store: .preview)
.previewLayout(.fixed(width: 1600, height: 1000))
.environment(\.locale, Locale(identifier: "fr_FR"))
}
}
}
#endif
161 changes: 0 additions & 161 deletions telltime/TellTime/MainView.swift

This file was deleted.

0 comments on commit f2b16e0

Please sign in to comment.