Skip to content

navigationDestination not triggered #138

@ghost

Description

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?

Activity

stephencelis

stephencelis commented on Mar 30, 2023

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

ghost

ghost commented on Mar 30, 2023

@ghost
stephencelis

stephencelis commented on Mar 30, 2023

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stephencelis

        Issue actions

          navigationDestination not triggered · Issue #138 · pointfreeco/episode-code-samples