Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigationDestination not triggered #138

Open
innoreq opened this issue Mar 30, 2023 · 3 comments
Open

navigationDestination not triggered #138

innoreq opened this issue Mar 30, 2023 · 3 comments

Comments

@innoreq
Copy link

innoreq commented Mar 30, 2023

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?

@stephencelis
Copy link
Member

@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?

@innoreq
Copy link
Author

innoreq commented Mar 30, 2023 via email

@stephencelis
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants