Skip to content

Commit bd0a3ce

Browse files
authored
Fixed Modifying state during view update, this will cause undefined behavior (#31)
1 parent ff01653 commit bd0a3ce

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Sources/FloatingLabelTextFieldSwiftUI/FloatingLabelTextField.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,17 @@ public struct FloatingLabelTextField: View {
101101
} else {
102102
TextField("", text: $textFieldValue.animation(), onEditingChanged: { (isChanged) in
103103
withAnimation {
104-
self.isSelected = isChanged
104+
DispatchQueue.main.async {
105+
self.isSelected = isChanged
106+
}
107+
}
108+
109+
DispatchQueue.main.async {
110+
self.isShowError = self.notifier.isRequiredField
105111
}
106112

107113
self.validtionChecker = self.currentError.condition
108114
self.editingChanged(isChanged)
109-
self.isShowError = self.notifier.isRequiredField
110115
arrTextFieldEditActions = self.notifier.arrTextFieldEditActions
111116
}, onCommit: {
112117
self.isShowError = self.notifier.isRequiredField

0 commit comments

Comments
 (0)