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
{{ message }}
This repository was archived by the owner on May 16, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+23-27Lines changed: 23 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,55 +4,55 @@ Resolve SwiftUI views trough a resolver injected in parent that is inspired by N
4
4
5
5
## Usage
6
6
7
-
### Destinations with the `ResolvableDestination` protocol
7
+
### Destinations with `@ViewBuilder` closures
8
8
9
-
1. Implement a custom type that adopts the `ResolvableDestination` protocol
10
-
2. Provide a value of this type in the parent view with the `destination` view modifier
11
-
3. Resolve the view using `DestinationView` with the initializer that takes the destination type as the first argument
9
+
This is the most basic way to use Destinations.
10
+
11
+
1. Register a `@ViewBuilder` closure for a value type with the `destination(for:)` view modifier
12
+
2. In a child view, resolve the destination by using `DestinationView` with a matching value type
12
13
13
14
```swift
14
15
importDestinations
15
16
16
-
structMyDestination: ResolvableDestination {
17
-
let base: Int
18
-
19
-
funcbody(value: Int) ->some View {
20
-
Text(base + value, format: .number)
21
-
}
22
-
}
23
-
24
17
structParentView: View {
25
18
var body: some View {
26
19
ChildView()
27
-
.destination(MyDestination(base: 100))
20
+
.destination(for: Int.self) { value in
21
+
Text(100+ value, format: .number)
22
+
}
28
23
}
29
24
}
30
25
31
26
structChildView: View {
32
27
var body: some View {
33
-
DestinationView(MyDestination.self, value: 1)
28
+
DestinationView(value: 1)
34
29
}
35
30
}
36
31
```
37
32
38
-
### Destinations with `@ViewBuilder` closures
39
-
40
-
Destinations comes with one special destination that you can use to resolve any Hashable value without implementing a custom `ResolvableDestination` type.
33
+
### Destinations with the `ResolvableDestination` protocol
41
34
42
-
1. Provide a `@ViewBuilder` closure for a value type in the parent view with the `destination(for:)` view modifier
43
-
2. Resolve the view using `DestinationView` with the initializer with the value as the only argument
35
+
Alternatively, you can register a custom `ResolvableDestination` implementation. This way you can inject properties from the parent and hold some state with SwiftUI property wrappers.
44
36
45
-
Note, however, that while this approach more closely resembles NavigationStack and is easier to use, it has one significant one significant trade-off. Like NavigationStack, it uses `AnyView` inside to erase the type information of the view that you provide in the `destination` closure, which is an unavoidable syntax limitation. In practical terms, this is may be less efficient when SwiftUI needs to detect changes between view updates.
37
+
1. Implement a custom type that adopts the `ResolvableDestination` protocol
38
+
2. Register a value of this type with the `destination` view modifier
39
+
3. In a child view, resolve the view by using `DestinationView` with a value type that matches the value type used in step 1
0 commit comments