android-fhir
android-fhir copied to clipboard
Cursor skipping back while start typing a value in numeric field
Describe the bug Cursor is skipping back while start typing on the numeric field if the initial value is set to 0
Component SDC library
To Reproduce Steps to reproduce the behavior:
- Go to any questionnaire.
- Click on any field that has a support number only.
- Type a 0 first.
- Then type any number like 100 after 0.
- You'll notice that the cursor is back to the second last character instead of the end.
Expected behavior Cursor should stick to the end position of the field.
Screenshots
https://user-images.githubusercontent.com/62104757/225643988-45aa0c54-56b1-403a-874d-2beec2593324.mp4
Smartphone (please complete the following information):
- Device: emulator
- Android version: 11
- Build number: RSR1.201013.001
I can replicate this! Interesting bug for sure. Ill look into this some more
Found the issue. When we go to update the UI, we do a text comparison of the answer saved in the ViewModel vs what is on the screen. If they are different, we update the UI with the text from the ViewModel.
When a user types in "01", that is saved as "1" in the ViewModel, so when UI does the comparison, it sees these as different and updates the UI with 1. This happens here":
https://github.com/google/android-fhir/blob/master/datacapture/src/main/java/com/google/android/fhir/datacapture/views/factories/EditTextIntegerViewHolderFactory.kt#L68-L71
To fix that, we can do an int comparison instead:
if ((text?.toIntOrNull() != textInputEditText.text.toString().toIntOrNull())) {
textInputEditText.setText(text)
}
I tried this and it worked. I need to add test cases, and once I do, Ill push a PR out
This issue seems to be reoccurring again cc @omarismail94
@f-odhiambo please assign this to someone thanks!
@MJ1998 please find here a screen recording of the cursor skipping bug on emulator, along with the emulator bug report.
- Cursor skipping bug.webm
- bugreport-Pixel_2_API_30-2024-05-02-15-31-37-40356b20-1bad-437f-8110-81a8a5accccb.zip
Let me know if you require any further information or clarification?
@MJ1998 Screen recording of the bug on the SID Bunda app. Device: Emulator Pixel 2 API 29 Android Version: 10 Build Number: QSR1.190920.001
Thanks. Looking into this
The way I was able to consistently replicate the issue was by doing some intensive work on the main thread.
I simply created an infinite loop in the MainActivity.onCreate
that would work for some time and then sleep for sometime.
lifecycleScope.launch {
while(true) {
for(i in 0..100_000){
println("$i")
}
delay(100)
}
}