96

The structure of the app is fairly simple: A searchbar, a listview and react-native-tabs at the bottom. The problem: If I click on the searchbar on Android it pushes the whole app up, so I see the tabs directly over the keyboard. But on iOS the keyboard overlays the whole app, without pushing anything up. Is there any way to control that?
I'm happy to share code / screenshots if the question isn't clear.
Thanks

edit:

<View style={{flex:1, backgroundColor:'#f2f2f2'}}>
    <ListView
        dataSource={this.state.dataSource}
        renderRow={this.renderSearchResults.bind(this)}
        style={styles.listView}/>
    <KeyboardAvoidingView
        style={styles.addQuestionBar}
        behavior={'position'}>
        <Text>
            Don't see your question?
        </Text>
        <TouchableOpacity>
            <Text>
                Add it
            </Text>
        </TouchableOpacity>
    </KeyboardAvoidingView>
</View>
dv3
  • 4,369
  • 5
  • 28
  • 50

7 Answers7

161

Set android:windowSoftInputMode="adjustPan" in your manifest file, and it will work as you expect.

E.g.

<application
  android:name=".MainApplication"
  android:allowBackup="true"
  ...
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    ...
    android:windowSoftInputMode="adjustPan">
    ...
  </activity>
  ...
</application>
Jeph
  • 1,738
  • 1
  • 9
  • 9
  • I had to close the bundle window and re-run `react-native run-android`, after setting 'adjustPan'. – FirstOne Aug 13 '18 at 01:00
  • Worked like a charm. I thought I needed KeyboardAvoidingView, but this solution works perfect. – Sadman Muhib Samyo Dec 16 '18 at 10:49
  • 10
    Setting `android:windowSoftInputMode="adjustPan"` disables scrolling for me. The keyboard covers some components, and I can not see them, nor can I scroll the screen – Nikola Diklich Dec 02 '19 at 13:46
  • Thank you so much, adding android:windowSoftInputMode="adjustPan" will sort everything – Manoj Alwis May 14 '20 at 01:52
  • NO! Do not do this unless you know exactly what it's doing. I put this in my app to solve some problem and then lost a whole day trying to make my top app bar not be pushed out (panned) out of the screen! Use"adjustResize". Explanation here: https://stackoverflow.com/a/17410528/4345461 . – Filip Savic Feb 05 '21 at 11:21
  • I use `adjustResize` and i have to reinstall once to get my adjustment done, otherwise it overlap my forms. – Dimitri Kopriwa Feb 24 '21 at 12:21
  • Is there a way to do the reverse of this for iOS? I want the iOS keyboard to push up the layout like android – Ryker Aug 04 '21 at 21:48
  • `adjustPan` worked for me. (Please note you need to `./gradlew clean` in your android folder and then run `npx react-native run-android` to see the effect) – Awshaf Ishtiaque Feb 10 '22 at 22:05
68

For those using Expo

@J KW's answer is correct but if you're using Expo you will have to implement it differently.

Expo uses different configuration terms. In your app.json you have to set the configuration key "softwareKeyboardLayoutMode":"pan" in your android object. Your file might look something like:

{
  "expo": {
    "name": "App",
    ...
    "android":{"softwareKeyboardLayoutMode": "pan"},
    ...
  }
}

Note: If you are receiving a "should NOT have additional property" error, it's likely because you don't have the updated Expo SDK (v.038). Please update your Expo version.

Documentation: https://docs.expo.io/workflow/configuration/

binkie
  • 865
  • 6
  • 9
  • 1
    For those interested, the documentation is [here](https://docs.expo.io/versions/latest/config/app/#softwarekeyboardlayoutmode) and you can also see the [PR](https://github.com/expo/expo/pull/8842) – Rafael Tavares Aug 25 '20 at 19:10
  • 1
    this still isnt working for me...i can still see a white background when i open and close the keyboard? can you tell me how to fix this pls? – Aldor Apr 13 '21 at 12:05
  • 3
    Make sure you restart the Expo CLI after this change as the config is only read during startup. – markb Jul 22 '21 at 14:06
15

There is new Component called KeyboardAvoidingView from React Native not documented yet but i already use it in my project and its very useful

Code Example:

'use strict'
import { ... , KeyboardAvoidingView } from 'react-native'

class Test extends Component {
  constructor () {
    super()
    this.state = {
      behavior: 'position' 
      // there is three ways to adjust (position , height , padding ) 
    }
  }
    


  render(){
    return (
        <View>
          <KeyboardAvoidingView behavior={this.state.behavior}>
            <TextInput
              style={style.PhoneNumberInput}
              onChangeText={(text) => this.setState({text})}
              value={this.state.text}
              />
          </KeyboardAvoidingView>
        </View>
    )
  }

}


module.exports = Test

and for more details you can check KeyboardAvoidingViewExample

EDIT:

Sorry i just got the wrong idea from the question i think what you are trying to do is stop the android keyboard from pushing the application up here is component that allow you to choose between (Pan, Resize, Nothing) in android

react-native-android-keyboard-adjust

Gregoire Ducharme
  • 1,095
  • 12
  • 24
Abdulaziz Alkharashi
  • 1,286
  • 12
  • 13
  • ah no way this is genius...how do I know which RN version this requires? – dv3 Sep 06 '16 at 10:52
  • @dv3 its in react native since v0.29 and above but it will be official i think on 33.0 , you can use it now instead. – Abdulaziz Alkharashi Sep 06 '16 at 10:59
  • Lol I've no idea how I could debug this since it's under the keyboard. I want the tabs to remain under the keyboard, but right over the keyboard I want to display a simple "add button". behaviour={'position'} doesn't achieve this though... :-/ – dv3 Sep 06 '16 at 11:12
  • @dv3 okay put the close component under the inputText and use padding – Abdulaziz Alkharashi Sep 06 '16 at 11:16
  • hm, thanks, but I have the TextInput in the NavigationBar, in the view I display the results... I've inserted some code in the question – dv3 Sep 06 '16 at 11:19
2

Use android:windowSoftInputMode="adjustResize".

KeyboardAvoidingView and other keyboard-related components don't work quite well if you have "adjustPan" set for your android:windowSoftInputMode in AndroidManifest.xml.

Instead, you should use "adjustResize" and have a wonderful life.

I had "adjustPan" and tried using KeyboardAvoidingView and KeyboardAwareScrollView... nothing worked.

Now, with "adjustResize", i'm not using any keyboard-related component and my android app works. (I might have to use KeyboardAvoiding view on iOS, but it will work out of the box.)

Filip Savic
  • 2,737
  • 1
  • 29
  • 34
  • Error: Problem validating fields in app.json. Learn more: https://docs.expo.dev/workflow/configuration/ • Field: android.softwareKeyboardLayoutMode - should be equal to one of the allowed values. – Cory Jun 17 '22 at 18:00
  • @Cory Looks like you mistyped the value of `softwareKeyboardLayoutMode`. https://docs.expo.dev/versions/latest/config/app/#softwarekeyboardlayoutmode Check that link out. It says that the possible values for `android.softwareKeyboardLayoutMode` are only "resize" and "pan". – Filip Savic Jun 20 '22 at 16:13
0

@binkie's answer worked for my expo (Version 44.0.0) app with a slight change. In app.json,

"android":{"softwareKeyboardLayoutMode": "pan"}

In the screen, margin bottom value equal to height of the bottom tab like so

<ScrollView mb="70px">...</ScrollView>
Shri ram
  • 61
  • 5
0

****1) modify the AndroidMainfest.xml in android/src/main/AndroidMainfest.xml u can solve the issue by changing the

       $ android:windowSoftInputMode="adjustResize";
                       to  
       $ android:windowSoftInputMode="adjustPan";


          the problem will be resolvede****
kalyanrai
  • 21
  • 5
0

I had the same issue while React Native - Javascript, SafeAreaView and ScrollView fix the problem

<SafeAreaView style={styles.container}>
    <ScrollView  > 
      <View style={styles.body}>
....

 container: {
    flex: 1,
    backgroundColor: 'white' 
  },
Samir
  • 6,405
  • 5
  • 39
  • 42