episode-code-samples icon indicating copy to clipboard operation
episode-code-samples copied to clipboard

navigationDestination not triggered

Open ghost opened this issue 2 years ago • 3 comments

I have a pretty simple feature:

public struct MaintainFeature: ReducerProtocol {

	public struct State: Equatable {
		// This is the domain we're working on here.
		var profile: Profile

		var personalData: PersonalDataFeature.State?
		var educations: EducationsFeature.State?
	}

	public enum Action: Equatable {
		case didSelect(MaintainRoute?)

		case personalData(PresentationAction<PersonalDataFeature.Action>)
		case educations(PresentationAction<EducationsFeature.Action>)
		...
	}

	public var body: some ReducerProtocol<State, Action> {

		Reduce { state, action in

			switch action {
				case .didSelect(let route):
					switch route {
						case .personalData:
							state.personalData = .init(personalData: state.profile.personalData)
							return .none

						case .educations:
							state.educations = .init(educationList: state.profile.educationList)
							return .none

						case .none:
							fatalError("Unsupported option")
					}

				...

				case .personalData(_):
					return .none

				...
				case .dismiss:
					return .none

				case .educations(_):
					return .none
				...
			}
		}
		.ifLet(\.personalData, action: /Action.personalData) {
			PersonalDataFeature()
		}
		.ifLet(\.educations, action: /Action.educations) {
			EducationsFeature()
		}
	}

and a pretty simple view:

struct MaintainView: View {

	let store: StoreOf<MaintainFeature>

	var body: some View {

		WithViewStore(store) { vs in

			List {

				Button {
					vs.send(.didSelect(.personalData))
				} label: {
					Text("Personal Data")
				}

				Button {
					vs.send(.didSelect(.educations))
				} label: {
					Text("Educations")
				}
			}
			.navigationDestination(
				store: self.store.scope(
					state: \.personalData,
					action: MaintainFeature.Action.personalData
				), destination: { substore in
					PersonalDataView(store: substore)
				}
			)
			.navigationDestination(
				store: self.store.scope(
					state: \.educations,
					action: MaintainFeature.Action.educations
				), destination: { substore in
					EducationsView(store: substore)
				}
			)
		}
		.navigationTitle("Maintain")
	}
}

together with the Navigation.swift content from your #228 episode, and the "navigation-beta" branch of TCA.

What's happening now is: nothing. It seems that the view is not triggered when a button is tapped, although the state is changed. The .navigationDestination code is not called, nor is the view redrawn.

Is this a bug or am I doing something wrong?

ghost avatar Mar 30 '23 13:03 ghost

@innoreq Are you using the tools that ship with the navigation-beta, or just the tools built during the episodes so far in Navigation.swift? Also, what version of Xcode are you running, and what OS are you targeting?

stephencelis avatar Mar 30 '23 15:03 stephencelis

Latest versions (Xcode RC), and both, the navigation-beta and additionally the navigation.swift from the 228.Von meinem iPhone gesendetAm 30.03.2023 um 17:37 schrieb Stephen Celis @.***>: @innoreq Are you using the tools that ship with the navigation-beta, or just the tools built during the episodes so far in Navigation.swift? Also, what version of Xcode are you running, and what OS are you targeting?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

ghost avatar Mar 30 '23 15:03 ghost

@innoreq We can take a look later, but if you could attach a full, compiling repro that would be helpful.

I will say though that navigationDestination is not without its bugs, and we'd recommend trying to reproduce the issue with vanilla SwiftUI to see if the bug exists there, too.

stephencelis avatar Mar 30 '23 15:03 stephencelis