android-fhir icon indicating copy to clipboard operation
android-fhir copied to clipboard

Cursor skipping back while start typing a value in numeric field

Open owais-vd opened this issue 1 year ago • 7 comments

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:

  1. Go to any questionnaire.
  2. Click on any field that has a support number only.
  3. Type a 0 first.
  4. Then type any number like 100 after 0.
  5. 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

owais-vd avatar Mar 16 '23 14:03 owais-vd

I can replicate this! Interesting bug for sure. Ill look into this some more

omarismail94 avatar Mar 20 '23 10:03 omarismail94

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

omarismail94 avatar Mar 20 '23 11:03 omarismail94

This issue seems to be reoccurring again cc @omarismail94

f-odhiambo avatar Oct 05 '23 07:10 f-odhiambo

@f-odhiambo please assign this to someone thanks!

jingtang10 avatar Oct 05 '23 13:10 jingtang10

@MJ1998 please find here a screen recording of the cursor skipping bug on emulator, along with the emulator bug report.

Let me know if you require any further information or clarification?

AngelaKabari avatar May 02 '24 13:05 AngelaKabari

@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

Screen_recording_20240503_125603.webm

karina4050 avatar May 03 '24 09:05 karina4050

Thanks. Looking into this

MJ1998 avatar May 06 '24 03:05 MJ1998

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)
    }
}

aditya-07 avatar Jun 07 '24 10:06 aditya-07