mateusz1913 / react-native-avoid-softinput

Native solution for common React Native problem of focused views being covered by soft input view.
https://mateusz1913.github.io/react-native-avoid-softinput/
MIT License
703 stars 20 forks source link

[WONT FIX] android: Can't scroll once keyboard shown #191

Closed johnf closed 11 months ago

johnf commented 1 year ago

Environment

Library version: 4.0.1 OS version: Android 14 in emulator

Affected platforms

Current behavior

Expected behavior

I should be able to scroll to the button

Reproduction

https://github.com/johnf/react-native-avoid-softinput/tree/main

johnf commented 1 year ago

If I move the input down, so enough of it is covered by the keyboard Which means that after the keyboard comes up, soft input initiates a scroll event Then I can scroll down to the button

For the demo, I've forked this repo and adjusted the FORM example.

saadi-ninjasCode commented 12 months ago

I am facing the same issue only on Android. Attaching video you reference. Follow the steps to reproduce it.

  1. Input on screen at top.

  2. No scroll on the initial screen (As mentioned above -> Fit data on screen)

  3. Focus on input and the keyboard will show up while some listing data is hidden behind the keyboard (Show in video)

  4. Now try to scroll down (To view the list data which is hidden behind the keyboard).

    Issue

    The scroll will not work. There will be two things that happen if you try to scroll.

  5. If you have added keyboardShouldPersistTaps='always' . Nothing will happen (Scroll will not work and the keyboard will shown as it is)

  6. Otherwise, keyboard will hide.

https://github.com/mateusz1913/react-native-avoid-softinput/assets/57723965/20032e0b-4c48-4a63-bf2a-40e33121e823

Expected Behaviour

Screen will be scrollable when Keyboard is shown as some data is hidden behind the Keyboard.

mateusz1913 commented 11 months ago

Hey @johnf @saadi-ninjasCode, thx for reporting the issue!

I managed to reproduce it and did some investigation in the library's Android code. It turned out that it has something to do with the library, but rather with how Android's ScrollView class works.

The issue

When the scrollview's content has height less or equal to scrollview's height and the scrollY position is equal 0, then the scrollview is not scrollable even when bottom padding is applied.

It turned out that canScrollVertically helper, which is used internally in ScrollView, returns false even when bottom padding is applied. I tried to hack it with scrolling by 1dp and it helped partially - I was able to scroll to the bottom of the scrollview, but then when I scrolled to the top, the scrollview was stuck again (above helper again returned false)

I don't think, it should be responsibility of the library to fix weird/broken behavior of stock ScrollView and I don't see any other way apart from creating custom class that extends ScrollView, which I don't want to do and later maintain.

So at the end, I think that will be a won't fix 😕

WORKAROUND

As a workaround for use cases when the scrollview's content has smaller or equal height to the scrollview's height, you can manually apply the padding to some Animated.View like described in Sticky Footer recipe - put the empty Animated.View inside your ScrollView at the bottom as a last child view and apply the padding to that Animated.View with useSoftInputHeightChanged hook