SwiftUI
emelyanovkirill opened this issue · comments
emelyanovkirill commented
Is there a sample for SwiftUI?
I write like this, but clearing characters requires clearing mask characters too
@Published var myText = "" {
didSet {
if myText != myMask.mask(input: myText, exhaustive: false) {
myText = myMask.mask(input: myText, exhaustive: false)
}
}
}
Evgenii Sukhanov commented
import SwiftUI
struct MaskedTextFieldStyle: TextFieldStyle {
@Binding var text: String
var mask: Veil
func _body(configuration: TextField<Self._Label>) -> some View {
configuration
.valueChanged(value: text) { oldValue in
text = mask.mask(
input: oldValue,
exhaustive: false
)
}
}
}