Repository navigation
[KeyboardAvoidingView] Cannot handle several TextInputs at the same time? Question #8855
Description
react-native-cli: 0.2.0
react-native: 0.29.2
IOS, on Mac
Use KeyboardAvoidingView according to:
Source:
https://github.com/facebook/react-native/blob/0.29-stable/Libraries/Components/Keyboard/KeyboardAvoidingView.js
Example:
https://github.com/facebook/react-native/blob/0.29-stable/Examples/UIExplorer/KeyboardAvoidingViewExample.js
Problem:
I have a View which contains several TextInputs, so I added KeyboardAvoidingView on the root of the view, like this:
<KeyboardAvoidingView behavior="height" style={styles.container}>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="L"
/>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="O"
/>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="L"
/>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="LOL"
/>
</KeyboardAvoidingView>
I'v tried all three behaviors: position, height and padding, they all act strangely:
position
height
padding
Then I tried to just wrap the last TextInput with KeyboardAvoidingView, like this:
<View style={styles.container}>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="L"
/>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="O"
/>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="L"
/>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<KeyboardAvoidingView behavior="position" style={{alignSelf: 'stretch'}}>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="LOL"
/>
</KeyboardAvoidingView>
</View>
when I choose position for behavior, it's like this:
Seems like every TextInput can trigger the KeyboardAvoidingView's behavior.
Another problem:
When KeyboardAvoidingView is wrapped with a position: 'absolute' View, it doesn't work at all, like this:
<View style={styles.container}>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="L"
/>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="O"
/>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="L"
/>
<View style={{position: 'absolute', top: 470, right: 0, left: 0, bottom: 0}}>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<KeyboardAvoidingView behavior="position" style={{alignSelf: 'stretch'}} >
<TextInput
style={styles.textInput}
placeholder="lol"
defaultValue="LOL"
/>
</KeyboardAvoidingView>
</View>
</View>
Behavior:
Question:
Did I use KeyboardAvoidingView in a wrong way? Or it can not handle multiple TextInputs





Activity
Swordsman-Inaction commentedon Jul 22, 2016
https://github.com/APSL/react-native-keyboard-aware-scroll-view is a great one.
sibelius commentedon Jul 25, 2016
@nicklockwood
KeyboardAvoidindViewcan handle this scenario?inetfuture commentedon Jul 29, 2016
And why it's not documented? Is it because it's not production ready?
lprhodes commentedon Aug 25, 2016
I'm seeing the same thing - It'd be great to get some comment on whether we can use KeyboardAvoidindView and whether it supports multiple text fields
qualifyapp commentedon Sep 17, 2016
This issue should not have been closed with a link to a third party solution. The problem persists, and the problem lies within this repository. Using another repository is ultimately not the answer.
Swordsman-Inaction commentedon Sep 17, 2016
Reopen it since it still exists.
Thanks, @qualifyapp
jhack32 commentedon Sep 20, 2016
Try adjusting the style
For example,
<KeyboardAvoidingView behavior="position" style={{alignItems: 'center',}}>jrwm commentedon Dec 13, 2016
@Swordsman-Inaction I am encountering the same situation as you did. This problem persists in version 0.39.2 of React Native.
APSL/react-native-keyboard-aware-scroll-view works fine though. Thanks you for sharing it ;)
keeleycarrigan commentedon Dec 16, 2016
Yea it seems like
KeyboardAvoidingViewisn't working for me at all, and I think @Swordsman-Inaction pointed out why. The views they are in are absolutely positioned. This is (I believe) impossible to avoid when usingNavigationExperimentalbecause all the scenes are absolutely positioned to do the animations properly.otoinsa commentedon Jan 12, 2017
This component does not work in any expected way, it surely does some weird stuff;
It would be good to update documentation with multiple inputs/scroll view, if we are not using it right. However I tried (seemingly) all the possible scenarios, also setting contentContainerStyle; just got really tired of it after 3 hrs of no acceptable result...
Maybe you should implement keyboard-aware-scroll approach :D
anahitsk123 commentedon Mar 9, 2017
Is issue solved yet ? I still see it.
The keyboard is covering the TextInput.
buskerone commentedon Mar 9, 2017
cmon guys I think this is a very important feature in an mobile app! ESSENTIAL!
binzailani3136 commentedon Mar 14, 2017
Who solved this important problem?
https://github.com/APSL/react-native-keyboard-aware-scroll-view is working well on iOS as expected but it's not working on Android.
I've tried everything what I can do including
KeyboardAvoidingViewand other libraries.But none of them working well on Android.
Is there any library which supports Android very well?
5 remaining items
douglasjunior commentedon Jun 22, 2017
I got a good result using
android:windowSoftInputMode="adjustResize"for Android and IQKeyboardManager for iOS.I also created a library for ease of use.
Just install, no extra code needed:
shergin commentedon Jul 18, 2017
KeyboardAvoidingViewdoes NOT handleTextInputs at all (separately or not).The whole purpose of KeyboardAvoidingView is reacting on software keyboard appearance events and adjusting own layout accordingly. It can change own
position,size, andpadding(the most common use case).KeyboardAvoidingViewdoes NOT changeScrollViewpadding (aka insets).KeyboardAvoidingViewdoes NOT scrollScrollViews to focusedTextInputs.So, usually
KeyboardAvoidingViewshould be used as top-level view container.baijunjie commentedon Sep 10, 2017
https://github.com/baijunjie/react-native-input-scroll-view
Jp3rd commentedon Oct 13, 2017
@drblmb Hi, is there any example code for you implementation of the android side? Cos I have
android:windowSoftInputMode="adjustResize"in. But it still doesn't work. Or am I doing it wrong?`
stale commentedon Dec 12, 2017
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.
johnfdhartman commentedon Feb 1, 2018
This is still a problem. KeyboardAvoidingView is working fine for iOS but not at all for Android. I would like to use
new android:windowSoftInputMode="adjustResize", but I used create-react-native-app, and I would really prefer not to eject if I don't have to.jomla97 commentedon Apr 13, 2018
+1. This is still very much an issue. Not to even speak of the documentation, which is lacking in a lot of ways.
drblmb commentedon Apr 13, 2018
@Jp3rd - sorry for the late reply. You don't use KeyboardAvoidingView at all on Android. Just use the adjustResize setting.
CorinneKelly commentedon Apr 26, 2018
This is definitely still an issue. If there is a solution it has not been made clear here or in the documentation. I think the most common mobile behavior that developers AND users are looking for is to be able to have a user click on a textInput and have the screen slide up so that the active input box is on top of the keyboard. This is easy to accomplish when theres only one textinput on the screen but often there are multiple textInputs on the screen and all three "behaviors" of KeyboardAvoidingView are not useful at all. Please reopen this or at least share a solution if there is one.
drblmb commentedon Apr 26, 2018
@CorinneKelly - I think this issue was closed because there is no reason to use KeyboardAvoidingView for Android applications. So that is really the solution. I have had no problem on IOS using it with multiple text inputs.
For Android applications, add android:windowSoftInputMode="adjustResize" to your manifest XML file.
douglasjunior commentedon Apr 26, 2018
The problem exists in iOS because the OS itself does not offer a solution, even when we develop native solutions we suffer with it.
When I worked with native iOS apps, I used the
IQKeyboardManagerfor a long time. So, after migrate to RN, I created thereact-native-keyboard-managerand it has worked very well.I think the RN will not create a solution for this now, it's not a trivial thing to do.
turnipdabeets commentedon May 4, 2018
Thanks @douglasjunior for sharing your bridge, it's really helpful. Seems like the best solution I've seen so far!