Hi, I am trying to shorten the screen when the keyboard is active. But it always adjust it weirdly in android, it works fine in iOS.
Before keyboard is active:

After keyboard is active:

I am using RN 0.37, this also happens when i am starting from scratch:
This is my code:
import React from 'react';
import {
Keyboard,
Dimensions,
ScrollView,
StyleSheet,
Text,
TextInput,
AppRegistry
} from 'react-native';
var {height, width} = Dimensions.get('window');
var _keyboardWillShowSubscription;
var _keyboardWillHideSubscription;
height = height - 20;
class awesomeproject extends React.Component {
constructor(props) {
super(props);
this.state = {
height: height,
};
}
componentDidMount() {
_keyboardWillShowSubscription = Keyboard.addListener('keyboardDidShow', (e) => this._keyboardWillShow(e));
_keyboardWillHideSubscription = Keyboard.addListener('keyboardDidHide', (e) => this._keyboardWillHide(e));
}
componentWillUnmount() {
_keyboardWillShowSubscription.remove();
_keyboardWillHideSubscription.remove();
}
_keyboardWillShow(e) {
this.setState({height: height - e.endCoordinates.height});
}
_keyboardWillHide(e) {
this.setState({height: height});
}
render() {
return (
<View style={{height: this.state.height}}>
<View style={{backgroundColor: 'blue', flex: 1}} />
<View style={styles.fieldBox}>
<TextInput
style={styles.field}
placeholder={'hello'}
autoCapitalize={'none'}
placeholderTextColor={'#afbccc'}
blurOnSubmit={false}
autoCorrect={false}
ref={'textinput'}
onChangeText={(data) => this.setState({message: data})} />
</View>
</View>
);
}
}
const styles = StyleSheet.create({
field: {
color:'black',
fontWeight:'bold',
fontSize:18,
flex: 1,
marginHorizontal: 10
},
});
AppRegistry.registerComponent('awesomeproject', () => awesomeproject);
try the keyboardavoidingview
@vonovak I have tried using KeyboardAvoidingView, and it still failed. the problem is that the <View style={{backgroundColor: 'blue', flex: 1}} /> will be replaced with ScrollView component and I want the ScrollView container's height to be the one is adjusted, instead the whole main container to be shifted up. Can it be caused by my android sdk version? My build tools is v 23.0.3. Thanks.
I meet this problem too. It is not related to the android version.
please锛寉ou solved this problem?
@MingYe-dz try adding android:windowSoftInputMode="adjustResize" to your Android Manifest android/app/src/main/AndroidManifest.xml
Did you get any solution to this?
Did you try KeyboardSpacer ?
https://github.com/Andr3wHur5t/react-native-keyboard-spacer
Seeing the same behavior; there's a visible gap between the keyboard and the view. @vonovak KeyboardAvoidingView does not work for me either. There are numerous open issues describing the same bugs I'm having (padding not being removed after keyboard is dismissed, etc.)
It's quite frustrating when I can't build my own when the out-of-the-box solution doesn't work. You guys are really tying my hands here.
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
kelvinaliyanto's advice isn't too far off. If that doesn't work, try replacing
android:windowSoftInputMode="adjustResize"
with
android:windowSoftInputMode="adjustPan"
in your android/app/src/main/Android.Manifest.xml.
Most helpful comment
kelvinaliyanto's advice isn't too far off. If that doesn't work, try replacing
android:windowSoftInputMode="adjustResize"with
android:windowSoftInputMode="adjustPan"in your
android/app/src/main/Android.Manifest.xml.