[TIMOB-28433] Android: Setting value resets keyboard layout (parity issue)
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | None |
| Status | Open |
| Resolution | Unresolved |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Android |
| Labels | n/a |
| Reporter | Hans Knöchel |
| Assignee | Unknown |
| Created | 2021-04-30T11:50:00.000+0000 |
| Updated | 2021-05-01T01:49:46.000+0000 |
Description
When setting the value of a text field (e.g. to force uppercase in our case), the keyboard resets, which is a pretty bad UX experience when entering numbers and letters in mix (like flight numbers).
Test case:
const window = Ti.UI.createWindow({ backgroundColor: '#f0f0f0' });
const textField = Ti.UI.createTextField({ width: 300, height: 40, backgroundColor: '#fff' });
textField.addEventListener('change', event => {
event.source.value = event.source.value.toUpperCase();
});
window.add(textField);
window.open();
This does only happen on Android - iOS works correctly. If there is a workaround to force uppercase, I am happy to use that instead! Android natively solves this by using textAllCaps in the EditText, but unfortunately thats not available in Titanium.
[~hknoechel], we actually do support an all-caps features in Titanium. You can enable it by setting the
TextField"autocapitalization" property toTi.UI.TEXT_AUTOCAPITALIZATION_ALL. It works on both Android and iOS. https://titaniumsdk.com/api/titanium/ui/textfield.html#autocapitalization I don't know if we can do anything about the virtual keyboard relayout after calling setText(). That said, the *BEST* way to handle altering keyboard input before it's applied to theEditTextis to do so synchronously via a native [InputFilter](https://developer.android.com/reference/android/text/InputFilter) and [KeyListener](https://developer.android.com/reference/android/text/method/KeyListener)... which is exactly what we use to apply auto-capitalization, max length, emoji filtering, etc. So, we're already doing the *right* thing as can be seen [here](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIText.java#L970) . Since Android is a bit fussy on how these are configured, it's probably best to add these as filtering features like this. Does this help?