Skip to content

Commit 72d9e61

Browse files
committed
Updated to SwiftDux 0.11.0
1 parent aee9468 commit 72d9e61

14 files changed

+33
-36
lines changed

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22

33
A reference implementation of a todo app to test out SwiftUI using [SwiftDux](https://github.com/StevenLambion/SwiftDux). This example is still a work in progress. There's partial iPad support, but SwiftUI's split view and navigation functionality is still not fully complete. It currently requires iOS 13.1 to work properly.
44

5-
<div style="text-align: center">
6-
<div>
7-
<img style="border: 1px solid #aaa; box-shadow: 0px 2px 12px #ccc" src="./screenshots/todoLists-iPad-screenshot.png" width="600"/>
8-
</div>
9-
</div>
5+
<img src="./screenshots/todoLists-iPad-screenshot.png" width="100%"/>
106

11-
## Things left to do:
7+
## Things to do:
128

13-
Some of the items below are possible now if using a custom built SplitView and deprecated APIs. The point of this project though is to see where SwiftUI is at while it develops. It's still in an early preview stage, so many parts of it are in flux or missing.
9+
Some of the items below are possible now if using a custom built SplitView and deprecated APIs. The point of this project though is to see what's possible in SwiftUI while it develops.
1410

1511
- Multi-window support with UIScene.
16-
- Initially selected todo list on iPad.
1712
- Split view navigation button to expand / collapse the master view.
1813
- This is currently missing. It was also missing in the SwiftUI Essentials video.
1914
- Remove arrows from master view on iPad.
2015
- This is an implemenation detail of NavigationLink.
2116
- Autofocus text fields when adding a new item.
22-
- Persist state.
23-
- Restore previous navigation on relaunch.

Todo.xcodeproj/project.pbxproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@
117117
path = TodoListDetails;
118118
sourceTree = "<group>";
119119
};
120+
AA2606122318D3E500B46F56 /* Styles */ = {
121+
isa = PBXGroup;
122+
children = (
123+
AA2F1A80231782D3003B088A /* CheckedToggleStyle.swift */,
124+
);
125+
path = Styles;
126+
sourceTree = "<group>";
127+
};
120128
AA427B0022C31B28005A4368 /* App */ = {
121129
isa = PBXGroup;
122130
children = (
@@ -158,9 +166,7 @@
158166
AA94FB9122F4D0E8008D0272 /* Views */ = {
159167
isa = PBXGroup;
160168
children = (
161-
AA427ACB22C143AE005A4368 /* MainSceneView.swift */,
162169
AA94FB9B22F4D969008D0272 /* AddButton.swift */,
163-
AA2F1A80231782D3003B088A /* CheckedToggleStyle.swift */,
164170
);
165171
path = Views;
166172
sourceTree = "<group>";
@@ -196,6 +202,7 @@
196202
AA9DA94322AD8A2100617E46 /* Todo */ = {
197203
isa = PBXGroup;
198204
children = (
205+
AA2606122318D3E500B46F56 /* Styles */,
199206
AA94FB9122F4D0E8008D0272 /* Views */,
200207
AA9DA97622ADA74C00617E46 /* Containers */,
201208
AA9DA96022AD8B2A00617E46 /* State */,
@@ -238,6 +245,7 @@
238245
AA9DA97622ADA74C00617E46 /* Containers */ = {
239246
isa = PBXGroup;
240247
children = (
248+
AA427ACB22C143AE005A4368 /* MainSceneView.swift */,
241249
AA116DD022D25AB50046D5A3 /* TodoListDetails */,
242250
AA116DCC22D257850046D5A3 /* TodoLists */,
243251
);
@@ -556,7 +564,7 @@
556564
repositoryURL = "https://github.com/StevenLambion/SwiftDux.git";
557565
requirement = {
558566
kind = upToNextMajorVersion;
559-
minimumVersion = 0.10.0;
567+
minimumVersion = 0.11.0;
560568
};
561569
};
562570
/* End XCRemoteSwiftPackageReference section */

Todo/AppDelegate.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88

99
import UIKit
1010
import SwiftDux
11+
import SwiftDuxExtras
1112

1213
@UIApplicationMain
1314
class AppDelegate: UIResponder, UIApplicationDelegate {
1415

15-
let store = Store(
16+
var store = Store(
1617
state: AppState(),
1718
reducer: AppReducer(),
18-
middleware: PrintActionMiddleware()
19+
middleware: [
20+
PrintActionMiddleware(),
21+
PersistStateMiddleware(JSONStatePersistor<AppState>()) { state in
22+
state.schemaVersion == AppState.currentSchemaVersion
23+
}
24+
]
1925
)
2026

2127
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
File renamed without changes.

Todo/Containers/TodoListDetails/TodoListDetailsContainer.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Combine
33
import SwiftDux
44

55
struct TodoListDetailsContainer : View {
6-
6+
@Environment(\.horizontalSizeClass) var sizeClass
77
@MappedState private var todoList: TodoList
88
@MappedDispatch() private var dispatch
99

@@ -21,7 +21,9 @@ struct TodoListDetailsContainer : View {
2121
)
2222
.environment(\.editMode, $editMode)
2323
.onDisappear {
24-
self.dispatch(MainSceneAction.selectList(byId: nil))
24+
if self.sizeClass == .compact {
25+
self.dispatch(MainSceneAction.selectList(byId: nil))
26+
}
2527
}
2628
}
2729

Todo/State/App/AppState.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22
import SwiftDux
3-
import SwiftUI
43

54
func createTodos() -> [Todo] {
65
let count = 1
@@ -25,14 +24,11 @@ fileprivate let defaultTodoList = OrderedState(
2524
)
2625

2726
struct AppState : StateType {
28-
var mainScene: MainScene
29-
var todoLists: OrderedState<TodoList>
3027

31-
init(
32-
mainScene: MainScene = MainScene(),
33-
todoLists: OrderedState<TodoList> = defaultTodoList
34-
) {
35-
self.mainScene = mainScene
36-
self.todoLists = todoLists
37-
}
28+
static let currentSchemaVersion = 1
29+
30+
var schemaVersion: Int = currentSchemaVersion
31+
var mainScene: MainScene = MainScene()
32+
var todoLists: OrderedState<TodoList> = defaultTodoList
33+
3834
}

Todo/State/MainScene/MainScene.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,4 @@ struct MainScene: StateType {
1414
private enum CodingKeys: String, CodingKey {
1515
case selectedListId
1616
}
17-
18-
init(displayMode: MainSceneDisplayMode = .compact, selectedListId: String? = nil) {
19-
self.displayMode = displayMode
20-
self.selectedListId = selectedListId
21-
}
2217
}

Todo/State/TodoLists/TodoList.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import SwiftUI
32
import SwiftDux
43

54
struct TodoList: IdentifiableState {

Todo/State/Todos/Todo.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import Foundation
2-
import SwiftUI
32
import SwiftDux
43

5-
struct Todo: IdentifiableState, Identifiable {
4+
struct Todo: IdentifiableState {
65
var id: String
76
var text: String
87
var completed: Bool = false

Todo/State/Todos/TodosReducer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
import Foundation
3-
import SwiftUI
43
import SwiftDux
54

65
enum TodosAction: Action {
-72 KB
Loading

screenshots/todoLists-screenshot.png

-420 KB
Binary file not shown.

screenshots/todos-screenshot.png

-435 KB
Binary file not shown.

0 commit comments

Comments
 (0)