Skip to content

Commit

Permalink
feat(App): improve App architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
renaudjenny committed Apr 23, 2023
1 parent f2b16e0 commit f484d92
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 100 deletions.
28 changes: 8 additions & 20 deletions telltime/TellTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
4CB1D4C522A7293500786385 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4CB1D4C422A7293500786385 /* Preview Assets.xcassets */; };
4CB9C77327EB0C30006BC36E /* SwiftClockUI in Frameworks */ = {isa = PBXBuildFile; productRef = 4CB9C77227EB0C30006BC36E /* SwiftClockUI */; };
4CC951C329E291440022C537 /* ConfigurationFeature in Frameworks */ = {isa = PBXBuildFile; productRef = 4CC951C229E291440022C537 /* ConfigurationFeature */; };
4CCF193A234E665A002E6D46 /* PreviewLayout+PredefinedDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CCF1939234E665A002E6D46 /* PreviewLayout+PredefinedDevice.swift */; };
4CD9494527E7BC67003EA782 /* SwiftClockUI in Frameworks */ = {isa = PBXBuildFile; productRef = 4CD9494427E7BC67003EA782 /* SwiftClockUI */; };
4CEB6042238ADEAF0085B07C /* AppCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEB6041238ADEAF0085B07C /* AppCore.swift */; };
4CEB6042238ADEAF0085B07C /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEB6041238ADEAF0085B07C /* App.swift */; };
4CEEF27829D92B8C00CD1DC8 /* SpeechRecognizerCore in Frameworks */ = {isa = PBXBuildFile; productRef = 4CEEF27729D92B8C00CD1DC8 /* SpeechRecognizerCore */; };
4CFB1C5C25D5BBC900AA7374 /* ComposableArchitecture in Frameworks */ = {isa = PBXBuildFile; productRef = 4CFB1C5B25D5BBC900AA7374 /* ComposableArchitecture */; };
4CFB1C6A25D726BA00AA7374 /* DateSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CFB1C6925D726BA00AA7374 /* DateSelector.swift */; };
Expand Down Expand Up @@ -88,8 +87,7 @@
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>"; };
4CCBFD0C23F870CA004EFBD8 /* NotificationCenter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NotificationCenter.framework; path = System/Library/Frameworks/NotificationCenter.framework; sourceTree = SDKROOT; };
4CCF1939234E665A002E6D46 /* PreviewLayout+PredefinedDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PreviewLayout+PredefinedDevice.swift"; sourceTree = "<group>"; };
4CEB6041238ADEAF0085B07C /* AppCore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCore.swift; sourceTree = "<group>"; };
4CEB6041238ADEAF0085B07C /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
4CFB1C6925D726BA00AA7374 /* DateSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateSelector.swift; sourceTree = "<group>"; };
4CFB1C6F25D7E0A800AA7374 /* Buttons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Buttons.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -124,15 +122,6 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
4C05AB5F2343FC2700970036 /* Common */ = {
isa = PBXGroup;
children = (
4C460CA424443D53006D02EA /* RandomDate.swift */,
4CCF1939234E665A002E6D46 /* PreviewLayout+PredefinedDevice.swift */,
);
path = Common;
sourceTree = "<group>";
};
4C3CCC6424B39353008F0699 /* TellTimeWidget */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -167,11 +156,9 @@
4CB1D4BA22A7293300786385 /* TellTime */ = {
isa = PBXGroup;
children = (
4CFB1C6E25D7E05700AA7374 /* MainScreen */,
4CEB6041238ADEAF0085B07C /* AppCore.swift */,
4CFB1C6E25D7E05700AA7374 /* App */,
4CB1D4BB22A7293300786385 /* TellTimeUKApp.swift */,
4CB1D4C122A7293500786385 /* Assets.xcassets */,
4C05AB5F2343FC2700970036 /* Common */,
4CB1D4C922A7293500786385 /* Info.plist */,
4CB1D4C322A7293500786385 /* Preview Content */,
4C28CDB12513F72000DAE010 /* LaunchScreen.storyboard */,
Expand All @@ -197,14 +184,16 @@
name = Frameworks;
sourceTree = "<group>";
};
4CFB1C6E25D7E05700AA7374 /* MainScreen */ = {
4CFB1C6E25D7E05700AA7374 /* App */ = {
isa = PBXGroup;
children = (
4C460CA424443D53006D02EA /* RandomDate.swift */,
4CEB6041238ADEAF0085B07C /* App.swift */,
4CB1D4BF22A7293300786385 /* AppView.swift */,
4CFB1C6925D726BA00AA7374 /* DateSelector.swift */,
4CFB1C6F25D7E0A800AA7374 /* Buttons.swift */,
);
path = MainScreen;
path = App;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -363,8 +352,7 @@
buildActionMask = 2147483647;
files = (
4C3CCC6C24B39356008F0699 /* TellTimeWidget.intentdefinition in Sources */,
4CEB6042238ADEAF0085B07C /* AppCore.swift in Sources */,
4CCF193A234E665A002E6D46 /* PreviewLayout+PredefinedDevice.swift in Sources */,
4CEB6042238ADEAF0085B07C /* App.swift in Sources */,
4C460CA524443D53006D02EA /* RandomDate.swift in Sources */,
4CFB1C7025D7E0A800AA7374 /* Buttons.swift in Sources */,
4CB1D4BC22A7293300786385 /* TellTimeUKApp.swift in Sources */,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,42 @@ struct AppView: View {
}

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)
}
VStack {
if verticalSizeClass == .regular && horizontalSizeClass == .compact {
Spacer()
clockView
Spacer()
timeText
Spacer()
DateSelector(store: store)
Spacer()
Buttons(store: store)
} else if verticalSizeClass == .compact {
HStack {
clockView.padding()
VStack {
timeText
Spacer()
DateSelector(store: store)
Spacer()
Buttons(store: store)
}
} else {
}
} else {
VStack {
clockView
VStack {
clockView(viewStore: viewStore).padding()
VStack {
timeText(viewStore: viewStore)
DateSelector(store: store)
}
HStack {
Spacer()
Buttons(store: store)
Spacer()
}
timeText
DateSelector(store: store)
}
HStack {
Spacer()
Buttons(store: store)
Spacer()
}
}
navigationLinks(viewStore: viewStore)
}
navigationLinks
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ import ComposableArchitecture
import TTSCore

struct Buttons: View {
struct ViewState: Equatable { }

enum ViewAction: Equatable {
case presentAbout
case presentConfiguration
case setRandomDate
}

let store: Store<AppState, AppAction>
let store: StoreOf<App>

var body: some View {
WithViewStore(store.scope(state: { $0.view }, action: AppAction.view)) { viewStore in
WithViewStore(store.stateless) { viewStore in
HStack {
SpeakButton(store: store.scope(state: \.tts, action: AppAction.tts))
SpeakButton(store: store.scope(state: \.tts, action: App.Action.tts))
Spacer()
Button { viewStore.send(.setRandomDate) } label: {
Image(systemName: "shuffle")
Expand All @@ -26,7 +18,7 @@ struct Buttons: View {
.cornerRadius(8)
}
Spacer()
Button { viewStore.send(.presentConfiguration) } label: {
Button { viewStore.send(.configuration(.present)) } label: {
Image(systemName: "gear")
.padding()
.accentColor(.red)
Expand All @@ -43,19 +35,3 @@ struct Buttons: View {
}
}
}

private extension AppState {
var view: Buttons.ViewState {
Buttons.ViewState()
}
}

private extension AppAction {
static func view(localAction: Buttons.ViewAction) -> Self {
switch localAction {
case .presentAbout: return .presentAbout
case .presentConfiguration: return .configuration(.present)
case .setRandomDate: return .setRandomDate
}
}
}
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions telltime/TellTime/Common/PreviewLayout+PredefinedDevice.swift

This file was deleted.

2 changes: 1 addition & 1 deletion telltime/TellTime/TellTimeUKApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct TellTimeUKApp: SwiftUI.App {
var body: some Scene {
WindowGroup {
WithViewStore(store.stateless) { viewStore in
MainView(store: store)
AppView(store: store)
.onOpenURL(perform: { openURL($0, viewStore: viewStore) })
}
}
Expand Down

0 comments on commit f484d92

Please sign in to comment.