rickclephas / KMP-NativeCoroutines

Library to use Kotlin Coroutines from Swift code in KMP apps
MIT License
1.07k stars 32 forks source link

the issue where the TextField color is not updating #178

Closed mikek9084 closed 5 months ago

mikek9084 commented 5 months ago

I NEED your help : the issue where the TextField color is not updating until you press a button or write some text in another TextField I have this viewmodel and I am using https://github.com/rickclephas/KMP-NativeCoroutines ,

@MainActor
class PersonalInfoViewModelViewModel: ObservableObject {
  let viewModelKt = DIHelper().providePersonalInfoViewModel

  @Published private(set) var uiState = PersonalInfoViewModelContractMyUiState.companion.defaultInstance()

  init() {
    Task {
      do {
        let uiStateFlow = asyncSequence(for: self.viewModelKt.uiStateNativeFlow)
        for try await state in uiStateFlow {
          self.uiState = state as! PersonalInfoViewModelContractMyUiState
        }
      }
struct TextFieldN: View {

  var text: String
  var isValid: Bool
  var onTextChange: (String) -> Void

  var body: some View {
    var bind: Binding<String> = Binding(get: { text }, set: { value in
      onTextChange(value)
    })

    VStack(alignment: .leading) {

        TextField("", text: bind)
          .foregroundColor(isValid ? Neutral50 : Red)
    }
  }
}