Skip to content

Commit

Permalink
Merge pull request #3 from teufelaudio/FixNavLink
Browse files Browse the repository at this point in the history
Some NavigationLink fixes
  • Loading branch information
luizmb authored Jun 29, 2021
2 parents 9652d78 + 45b501f commit 95d852b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/CombineRextensions/NavigationLink+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ extension NavigationLink {
function: String = #function,
line: UInt = #line,
info: String? = nil,
dispatchActionOnTap: @escaping (RowTag) -> Action,
onOpen: @escaping (RowTag) -> Action,
onClose: @escaping () -> Action,
@ViewBuilder label: @escaping () -> Label
) {
self.init(
Expand All @@ -32,7 +33,11 @@ extension NavigationLink {
viewModel.state[keyPath: pathToSelectedRowTag]
},
set: { row in
viewModel.dispatch(dispatchActionOnTap(row ?? rowTag), from: .init(file: file, function: function, line: line, info: info))
if row != nil && row == rowTag {
viewModel.dispatch(onOpen(rowTag), from: .init(file: file, function: function, line: line, info: info))
} else if row == nil {
viewModel.dispatch(onClose(), from: .init(file: file, function: function, line: line, info: info))
}
}),
label: label)
}
Expand Down Expand Up @@ -61,7 +66,7 @@ extension NavigationLink {
self.init(
destination: producer.view(secondScreen),
tag: secondScreen,
selection: store.binding[path] { value in
selection: Binding<ViewProducerContext?>.store(store, state: path, file: file, function: function, line: line, info: info) { value in
// We want to dispatch the pop action here in case the user
// pops the detail screen so that the RouterReducer knows
// to manipulate the NavigationTree.
Expand Down

0 comments on commit 95d852b

Please sign in to comment.