Check input behavior
On Android, be careful when using TextWatcher methods. Do not trigger a change of context when text changes.
kotlin
private val textWatcher = object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
// Ignored
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
// Ignored
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
// Do not change context
}
} In Jetpack Compose, be careful when defining logic for onValueChange inside the TextField). Do not trigger a change of context when the text changes.
kotlin
TextField(
value = "",
onValueChange = {
// Do not trigger change of context here
},
) With iOS, be careful when using UITextFieldDelegate methods. Do not trigger a change of context when text changes.
swift
extension ApptViewController: UITextFieldDelegate {
func textField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> Bool {
// Do not change context
return true
}
} In SwiftUI, when using the onChange-4psgg) modifier to listen for changes in a TextField, ensure that you do not trigger a change in context when the text changes.
swift
@State private var text = ""
var body: some View {
TextField("Enter text", text: $text)
.onChange(of: text) { _, newValue in
// Handle text changes without changing the context.
// You can add any validation or additional behaviour here.
}
} In Flutter, be careful when using onChanged callbacks. Do not trigger a change of context when text changes.
dart
TextField(
onChanged: (text) {
// Do not change context
},
), In React Native, be careful when using onChange or onChangeText callbacks. Do not trigger a change of context when text changes.
jsx
<TextInput
onChangeText={ /* Do not change context */ }
/> In MAUI, all input components have the TextChanged handler to listen for any changes to the input text.
Usage (C#)
csharp
var entry = new Entry();
entry.TextChanged += Entry_TextChanged;
private void Entry_TextChanged(object? sender, TextChangedEventArgs e)
{
//Apply any logic
} xml
<Entry
TextChanged="Entry_TextChanged" /> In Xamarin, be careful when using TextChanged callbacks. Do not trigger a change of context when text changes.
csharp
entry.TextChanged += OnEntryTextChanged;
void OnEntryTextChanged(object sender, TextChangedEventArgs args)
{
// Do not change context
}