APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.24k stars 643 forks source link

extra bottom space #463

Open donmezemre opened 3 years ago

donmezemre commented 3 years ago

Reproduce 720p

Problem when we focused a text input and scroll to bottom, an extra space is added at the bottom. besides that, android and ios behaves different.

Questions why does this happen? how to avoid from this behave?

and thank you

**Code That I Used***

Screen Shot 2020-10-23 at 14 54 41
aleciogomes commented 3 years ago

Your Android issue might be related with your android:windowSoftInputMode in your AndroidManifest.xml. It seems to be adding double keyboard-height padding. Also, is there any reason to use enabledOnAndroid? Android seems to handle well these kind of situations without any configuration.

The iOS extra value seems to be the bottom SafeAreaInset. Not sure why, tho. (It seems the same height value os the pink bottom area).

image

donmezemre commented 3 years ago

for android: android:windowSoftInputMode was adjustResize by default. but if i use this default value the keyboard focus losing suddenly when the text input focused. I had to change adjustPan to avoid lose focus.

Soliman13 commented 3 years ago

Is this issue still being tracked? As I encounter the same issue.

donmezemre commented 3 years ago

i am telling with sadness, yes

devinjameson commented 3 years ago

Having the same issue on iOS.

devinjameson commented 3 years ago

This may be a safe area inset issue on iOS. You may be able to get the bottom safe area from a library like react-native-static-safe-area-insets and set the extraScrollHeight to the negative of that value.

WhidRubeld commented 3 years ago

At the moment disabling android insert will solve this problem enableOnAndroid={false}

galbenyosef commented 3 years ago

This may be a safe area inset issue on iOS. You may be able to get the bottom safe area from a library like react-native-static-safe-area-insets and set the extraScrollHeight to the negative of that value.

try import { useSafeAreaInsets } from 'react-native-safe-area-context'; let insets = useSafeAreaInsets();

<KeyboardAwareScrollView extraScrollHeight={-insets.bottom} contentContainerStyle={{ flexGrow: 1 }} .../>

occurs only on ios works for me.

devinjameson commented 3 years ago

This may be a safe area inset issue on iOS. You may be able to get the bottom safe area from a library like react-native-static-safe-area-insets and set the extraScrollHeight to the negative of that value.

try

import { useSafeAreaInsets } from 'react-native-safe-area-context';

let insets = useSafeAreaInsets();

<KeyboardAwareScrollView

extraScrollHeight={-insets.bottom}

contentContainerStyle={{ flexGrow: 1 }}

.../>

occurs only on ios

works for me.

@galbenyosef This looks great. If you want to avoid using a hook (no need for a hook in this case, it's just a static value), you can use react-native-static-safe-area-insets to grab the bottom inset.

lucasriondel commented 2 years ago

@devinjameson 's solution worked perfectly. thanks a lot !

svmszcck commented 2 years ago

On Android try to set extraHeight to 0(According to the docs Default is 75)

Chifaa-Bouzid commented 2 years ago

@devinjameson's solution worked perfectly fine for me, thanks a lot. I just modified it a bit to correspond to how I want it to look --> extraScrollHeight={-(insets.bottom)*2.3}

bombillazo commented 1 year ago

Adding to the solution provided previously, I use useBottomTabBarHeight() + a custom useKeyboardHeight() hook:

extraScrollHeight={-(keyboardHeight + bottomTabBarHeight)}
kitkatMielPineda commented 1 year ago

I got a solution on this.. Tested on iPhone 13, iPhone 13 Pro Max, iPhone 6s, iPhone SE (3rd generation) and android.

try:

import React, {useEffect, useState} from 'react';
import { useWindowDimensions} from 'react-native';
import useKeyboardHeight from 'react-native-use-keyboard-height'

  const [contentBottom, setContentBottom] = useState(0);
  const [keyboardActive, setKeyboardActive] = useState(false)

  const {height} = useWindowDimensions()
  const keyHeight = useKeyboardHeight()

  useEffect(()=>{  
    if (keyboardActive){
      const diff = (parseFloat((height - keyHeight)/2))
      setContentBottom(diff)
    } else{
      setContentBottom(0)
    }
  },[keyHeight, keyboardActive]

<KeyboardAwareScrollView
            keyboardOpeningTime={0}
            enableResetScrollToCoords
            onKeyboardWillHide={() => setKeyboardActive(false)}
            onKeyboardWillShow={()=>setKeyboardActive(true)}
            contentInset={{ bottom: contentBottom }}
            automaticallyAdjustKeyboardInsets={true}
            automaticallyAdjustContentInsets={false}
          >

Previous

with extra white space at the bottom of the background image and before the keyboard for iPhone 13

Screen Shot 2022-09-08 at 12 04 24 PM

Changes

no extra white space anymore

Screen Shot 2022-09-08 at 10 32 29 PM Screen Shot 2022-09-08 at 10 18 06 PM

goodnight everyone!

vishalrathod817 commented 1 year ago

extraScrollHeight={-insets.bottom} contentContainerStyle={{ flexGrow: 1 }}

this working for me.... thanks

Nidhi-Kayasth-RXO commented 1 year ago

You need to set these properties to remove extra spacing. This is working for me.

<KeyboardAwareScrollView automaticallyAdjustContentInsets={true} keyboardShouldPersistTaps='always' scrollEventThrottle={10} resetScrollToCoords={{ x: 0, y: 0 }} contentInset={{ top: 0, bottom: 0 }}