Simple UIKit Navigation #1497
-
I've recently started exploring TCA and am getting hung up on simple UIKit navigation. I started by building a simple feature contained in a UIViewController, and I had no problems with that. Now I am trying to create a main view controller that will link to my existing feature view controller and will have other features that will link out from my main view controller via just having a bunch of UIButtons on the screen for each feature. I am struggling with the setup for this main view controller. I have a reducer and state for the main view controller. The state contains a property for my feature state. Where I am confused is when it comes to actions. I want it so when one UIButton is tapped, that feature is launched modally. What should the actions look like for this main view controller? It is my understanding that in the actions enum, you should have your child feature actions as a case, but what is used to trigger the actual display? Should one make another action called
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Take a look at the Tic-Tac-Toe demo that comes with the repo. It has both SwiftUI and UIKit implementations that share the same domain code. The The action that kicks off the event happens to be the result of a side effect in the reducer. But if you want to immediately present based off a button tap, you could use that action to set your associated "echo" state to non- |
Beta Was this translation helpful? Give feedback.
-
Thanks a ton for the response. So this works, but this feels wrong. In my actions I have an action that changes the state, and then I have another action for the child actions. Is this correct? struct TCAExample: ReducerProtocol {
struct State: Equatable {
var echo: Echo.State?
}
enum Action: Equatable {
case dislayEchoFeature
case echo(Echo.Action)
}
var body: some ReducerProtocol<State, Action> {
Reduce { state, action in
switch action {
case .dislayEchoFeature:
state.echo = .init()
return .none
case .echo:
return .none
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Take a look at the Tic-Tac-Toe demo that comes with the repo. It has both SwiftUI and UIKit implementations that share the same domain code.
The
LoginViewController
has an example of pushing a view controller based off optional state here:swift-composable-architecture/Examples/TicTacToe/tic-tac-toe/Sources/LoginUIKit/LoginViewController.swift
Lines 159 to 173 in 86438fa