Skip to content

Commit 3efc6a7

Browse files
lks574interactord
authored andcommitted
fix: Singnavigator02 - Easily transfer InjectionData
1 parent 0a3dd55 commit 3efc6a7

2 files changed

Lines changed: 3 additions & 19 deletions

File tree

Examples/SingleNavigator/02-SingleEventSubscriber/SingleEventSubscriber/Page/Page2/Page2LinkSubscriber.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import LinkNavigator
22
import Combine
33

44
class Page2LinkSubscriber: ObservableObject {
5-
private(set) var linkAction: PassthroughSubject<Page2LinkSubscriber.Action, Never> = .init()
5+
@Published var linkAction: Page3View.Page2InjectionData? = .none
66

77
deinit {
88
print("Page2LinkSubscriber deinit...")
@@ -12,14 +12,7 @@ class Page2LinkSubscriber: ObservableObject {
1212
extension Page2LinkSubscriber: LinkNavigatorItemSubscriberProtocol {
1313
func receive(encodedItemString: String) {
1414
if let scope: Page3View.Page2InjectionData? = encodedItemString.decoded() {
15-
guard let scope else { return }
16-
linkAction.send(.page2ToData(scope))
15+
linkAction = scope
1716
}
1817
}
1918
}
20-
21-
extension Page2LinkSubscriber {
22-
enum Action {
23-
case page2ToData(Page3View.Page2InjectionData)
24-
}
25-
}

Examples/SingleNavigator/02-SingleEventSubscriber/SingleEventSubscriber/Page/Page2/Page2View.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ struct Page2View: View {
1414
self.linkSubscriber = linkSubscriber
1515
}
1616

17-
@State var message: String = ""
18-
1917
var body: some View {
2018
ScrollView {
2119
VStack(spacing: 40) {
@@ -39,20 +37,13 @@ struct Page2View: View {
3937
.font(.footnote)
4038
.foregroundColor(.secondary)
4139

42-
Text(message)
40+
Text(linkSubscriber.linkAction?.message ?? "-")
4341
}
4442
}
4543

4644
Spacer()
4745
}
4846
.padding()
4947
}
50-
.onReceive(linkSubscriber.linkAction) { action in
51-
switch action {
52-
case .page2ToData(let eventData):
53-
message = eventData.message
54-
return
55-
}
56-
}
5748
}
5849
}

0 commit comments

Comments
 (0)