You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-24Lines changed: 28 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ There is an Example app available [here](https://github.com/mdb1/ViewStateContro
8
8
9
9
# ViewStateController Object
10
10
11
-
The ViewStateController struct is the one that contains the array of historical [ViewStates](https://mdb1.github.io/2023-01-08-new-app-view-state/) and has computed properties that will be used by the ViewStateModifier to determine what to do.
11
+
The [ViewStateController](https://github.com/mdb1/ViewStateController/blob/main/Sources/ViewStateController/ViewState/ViewStateController.swift) struct is the one that contains the array of historical [ViewStates](https://mdb1.github.io/2023-01-08-new-app-view-state/) and has computed properties that will be used by the ViewStateModifier to determine what to do.
12
12
13
13
*`isInitialLoading`: Returns true only if loading state was set once and there hasn't been errors or info yet.
14
14
*`isLoading`: Returns true if state is loading.
@@ -23,35 +23,35 @@ There are also two mutating methods:
23
23
*`setState(_ state: ViewState<Info>)`: Sets the new state into the states array.
24
24
*`reset()`: Resets everything.
25
25
26
-
# ViewStateModifier
26
+
##ViewStateModifier
27
27
28
-
The ViewStateModifier is a ViewModifier that uses the given ViewStateController and configurable options to automatically update the state of a view.
28
+
The [ViewStateModifier](https://github.com/mdb1/ViewStateController/blob/main/Sources/ViewStateController/ViewModifiers/ViewStateModifier.swift) is a ViewModifier that uses the given ViewStateController and configurable options to automatically update the state of a view.
29
29
30
30
The code of the modifier is pretty straight forward:
31
31
```swift
32
32
funcbody(content: Content) ->some View {
33
-
if controller.isInitialLoading {
34
-
// Initial loading modifier displayed on the initial loading state.
35
-
content.modifier(initialLoadingModifier)
36
-
} elseiflet info = controller.latestValidInfo {
37
-
// If we have valid info loaded we display it:
38
-
loadedView(info)
39
-
.if(controller.isLoading) { view in
40
-
// If we are on a subsequent loading, we add the modifier.
41
-
view.modifier(loadingAfterInfoModifier)
42
-
}
43
-
} elseiflet error = controller.latestValidError {
44
-
// If we have a value error we display it:
45
-
errorView(error)
46
-
.if(controller.isLoading) { view in
47
-
// If we are on a subsequent loading, we add the modifier.
48
-
view.modifier(loadingAfterErrorModifier)
49
-
}
50
-
} else {
51
-
// Otherwise, we display the initial content.
52
-
content
53
-
}
33
+
if controller.isInitialLoading {
34
+
// Initial loading modifier displayed on the initial loading state.
35
+
content.modifier(initialLoadingModifier)
36
+
} elseiflet info = controller.latestValidInfo {
37
+
// If we have valid info loaded we display it:
38
+
loadedView(info)
39
+
.if(controller.isLoading) { view in
40
+
// If we are on a subsequent loading, we add the modifier.
41
+
view.modifier(loadingAfterInfoModifier)
42
+
}
43
+
} elseiflet error = controller.latestValidError {
44
+
// If we have a value error we display it:
45
+
errorView(error)
46
+
.if(controller.isLoading) { view in
47
+
// If we are on a subsequent loading, we add the modifier.
48
+
view.modifier(loadingAfterErrorModifier)
49
+
}
50
+
} else {
51
+
// Otherwise, we display the initial content.
52
+
content
54
53
}
54
+
}
55
55
```
56
56
57
57
The method `withViewStateModifier`, is just a convenience way to add the ViewStateModifier to any view:
The [LoadingModifierType](https://github.com/mdb1/ViewStateController/blob/main/Sources/ViewStateController/ViewModifiers/LoadingViewModifier.swift) provides some different loading options with configurable parameters.
0 commit comments