HomeiOS Developmentios - TCA: 'onAppear' Motion is triggered however adjustments will not be...

ios – TCA: ‘onAppear’ Motion is triggered however adjustments will not be proven on display screen


I am utilizing the TCA for an SwiftUI software and I’ve this bug that the ‘.onAppear’ motion will not be displaying any adjustments on the display screen. This occurs within the simulator and in addition on the telephone. The bizarre factor is that after I’m printing the adjustments of the State with ._printChanges() the whole lot is proven accurately.

I am working Xcode 14.3 and utilizing the prerelease/1.0 department, the identical occurred on the navigation-beta department.

What am I lacking?

This is some code to breed:


import SwiftUI

import ComposableArchitecture

struct PlayAround: ReducerProtocol {
  struct State: Equatable {
    var textual content: String = ""
  }

  enum Motion: Equatable {
    case setText(String)
    case onAppear
  }

  var physique: some ReducerProtocol<State, Motion> {
    Scale back { state, motion in
      swap motion {
      case .setText(let newText):
        state.textual content = newText
        return .none
      case .onAppear:
        state.textual content = "On Seem"
        return .none
      }
    }
    ._printChanges()
  }
}

struct PlayAroundView: View {
  let retailer: StoreOf<PlayAround>

  init(retailer: StoreOf<PlayAround>) {
    self.retailer = retailer
  }

  var physique: some View {
    WithViewStore(retailer, observe: { $0 }) { viewStore in
      VStack {

        Textual content(viewStore.textual content)

        Button {
          viewStore.ship(.setText("Ship Button"))
        } label: {
          Textual content("Ship textual content")
        }
      }
      .onAppear {
        viewStore.ship(.onAppear)
      }
    }
  }
}

struct PlayAround_Previews: PreviewProvider {
  static var previews: some View {
    NavigationStack {
      PlayAroundView(
        retailer: .init(
          initialState: PlayAround.State(textual content: "Init"),
          reducer: PlayAround()
        )
      )
    }
  }
}

I am anticipating to see the textual content to be “On Seem” nevertheless it stays on the textual content giving within the initialiser.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments