Nested tree-based navigation issue #3007
-
Hello, Unfortunately, I’m facing some issues when implementing nested tree-based navigation with a structure like Specifically, I’m encountering a warning when attempting to dismiss PhotoPicker and PhotoCropper simultaneously and present PhotoForm when the “cropCompleted” action occurs in PhotoCropper. (To detect the “cropCompleted” action in PhotoCropper from PhotoList, I am doing the following.) // Unnecessary code was elminated.
import ComposableArchitecture
import Foundation
extension PhotoListFeature {
@Reducer(state: .equatable)
enum Destination {
case photoPicker(PhotoPickerFeature)
case photoForm(PhotoFormFeature)
}
}
@Reducer
struct PhotoListFeature {
@ObservableState
struct State: Equatable {
@Presents
var destination: Destination.State?
}
enum Action {
case destination(PresentationAction<Destination.Action>)
}
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case let .destination(.presented(.photoPicker(.destination(.presented(.photoCropper(.cropCompleted(uiImage: uiImage))))))):
// here !
state.destination = .photoForm(
PhotoFormFeature.State(uiImage: uiImage)
)
return .none
case .destination:
return .none
}
}
.ifLet(\.$destination, action: \.destination)
}
} The problem is that when replacing the destination as described above, the following warning occurs.
In this nested form of navigation, when replacing the destination from an ancestor (more than two levels deep, not the parent), it is suspected that the event of dismissing the destination of the child, PhotoPicker, is triggered, resulting in the above warning.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @teamboot88, this is happening due to bugs in SwiftUI navigation. When you dismiss two presented features at once, the intermediate view incorrectly writes
Yeah, for this particular situation it is ok to ignore because it is sadly just a SwiftUI bug.
What you have here should be fine, but there are two potential workarounds:
|
Beta Was this translation helpful? Give feedback.
Hi @teamboot88, this is happening due to bugs in SwiftUI navigation. When you dismiss two presented features at once, the intermediate view incorrectly writes
nil
to its binding, causing a.dismiss
action to be sent when it should not.Yeah, for this particular situation it is ok to ignore because it is sadly just a SwiftUI bug.