0

Now I have ListTabView it is parent and want to show MakeCardView by sheet. I am using @PresentationState for showing children View.

It works well, but the problems is children view' s all action intercept by parents view.

struct ListTabFeature: Reducer {
    
    //MARK: State
    struct State: Equatable {
        @PresentationState var addNewCard: MakeCardFeature.State?
    }
    
    //MARK: Action
    enum Action: Equatable {
        case tabMakeCardButton
        case addNewCard(PresentationAction<MakeCardFeature.Action>)
    }
    
    //MARK: Reducer
    func reduce(into state: inout State, action: Action) -> Effect<Action> {
        switch action {
        case .tabMakeCardButton:
            print(" make card btn ")
            state.addNewCard = MakeCardFeature.State()
            return .none
        case .addNewCard(.dismiss):
            print(" dismiss")
            state.addNewCard = nil
            return .none
        case .addNewCard(.presented(.tabCancelButton)):
            print(" cancel tabed")
            state.addNewCard = nil
            return .none
        default:
            print(" default")
            return .none
        }
    }
}
.sheet(store: self.store.scope(state: \.$addNewCard, action: ListTabFeature.Action.addNewCard)) { store in
                    MakeCardView(store: store)
                }

when I action tab children view's button, it keep log default

this is my first project to using TCA! please help!

red
  • 25
  • 3
  • You may want to print state and action in the default clause, which gives you a better clue what happens at which state. Surely, the reducer function will be called, when any view sends an action to _this_ store which has _this_ reducer. So, in `MakeCardView(store: store)` when `store` is the store which has the reducer above, and some child view sends actions to this sore, it works like expected. – CouchDeveloper Aug 08 '23 at 09:13
  • First of all I would recommend using the ReducerProtocol, rather than the old Reducer. Then you will need to use and IfLet in the body of the reducer so that the parent can react properly to the child actions. You can follow this example: https://github.com/pointfreeco/swift-composable-architecture/blob/main/Examples/Standups/Standups/StandupDetail.swift#L117 – Sebastian Guerrero Aug 30 '23 at 08:53

0 Answers0