pers
06/12/2024, 8:02 PMTextField
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)
}
}
}
@Chrimaeon plz do not answer or not kotlin but kotlin coloredpers
06/13/2024, 12:25 AMuiState
, SwiftUI is triggered to observe changes and re-render the view. However, if you access nested properties (like uiState.firstName
), SwiftUI may not recognize these nested changes immediately unless the entire uiState
object is replaced.