google / android-fhir

The Android FHIR SDK is a set of Kotlin libraries for building offline-capable, mobile-first healthcare applications using the HL7® FHIR® standard on Android.
https://google.github.io/android-fhir/
Apache License 2.0
465 stars 246 forks source link

Cursor skipping back while start typing a value in numeric field #1914

Open owais-vd opened 1 year ago

owais-vd commented 1 year ago

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

omarismail94 commented 1 year ago

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

omarismail94 commented 1 year ago

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

f-odhiambo commented 8 months ago

This issue seems to be reoccurring again cc @omarismail94

jingtang10 commented 8 months ago

@f-odhiambo please assign this to someone thanks!

AngelaKabari commented 1 month ago

@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?

karina4050 commented 1 month ago

@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

MJ1998 commented 1 month ago

Thanks. Looking into this

aditya-07 commented 1 week ago

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