Replies: 1 comment
-
It seems there is simpler way with enum and functions: extension ATAppFeature {
enum Route {
case login(sessionId: UUID? = nil, userName: String? = nil, password: String? = nil)
case signup(sessionId: UUID? = nil, userName: String? = nil, password: String? = nil, email: String? = nil, token: String? = nil)
case content(tab: Int? = nil)
func view(with store: StoreOf<ATAppFeature>) -> some View {
Group {
switch self {
case .login:
NavigationStack {
ATLoginView(
store: store.scope(
state: \.login,
action: ATAppFeature.Action.showLogin
)
)
}
case .signup, .signupEmailVerification:
NavigationStack {
ATSignupView(
store: store.scope(
state: \.signup,
action: ATAppFeature.Action.showSignup
)
)
}
case .content:
ATContentView()
}
}
}
}
func route(to route: Route, with state: inout ATAppFeature.State) -> Effect<ATAppFeature.Action> {
switch route {
case let .login(_, userName, password):
state.login.userName = userName
state.login.password = password
state.flow = .login
return .none
case let .signup(_, userName, password, _, _):
state.signup.userName = userName
state.signup.password = password
state.flow = .signup
return .none
case let .signupEmailVerification(_, userName, password, email, token):
state.signup.userName = userName
state.signup.password = password
state.signup.destination = .emailVerification(ATEmailConfirmationFeature.State(email: email, login: userName, token: token))
state.flow = .signup
return .none
case .content:
state.flow = .content
return .none
}
}
} and now I can use it... in Reducer: case let .showLogin:
return route(to: .login(), with: &state) in View: public var body: some View {
WithViewStore(self.store, observe: ViewState.init) { viewStore in
Group {
switch (viewStore.flow) {
case .login: ATAppFeature.Route.login().view(with: store)
case .signup: ATAppFeature.Route.signup().view(with: store)
case .content: ATAppFeature.Route.content().view(with: store)
}
} The only thing that bothers me is the need to provide |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The idea here is to create a generic router for features to construct the view hierarchy based on a set of parameter, such as NSUserActivity and URLs (deep links and restoration).
So my thinking is to create a sub reducer and try to route all UI actions (that change the state and set destinations) through its actions. Something like below (some code is redacted for simplicity):
I get to the point where I set the
ATAppFeature.State.route
(seems like too deep, and not quite useful), but not sure where to go from here. Also probably theRouteAction/State
should be extended/defined, as well as the@PresentationState
is not the right wrapper (need a new one)?Or is the whole approach flawed, and I should think "functions" on the reducer?
Beta Was this translation helpful? Give feedback.
All reactions