Height adjustment when keyboard appears is wrong
See original GitHub issueHi, 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);
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Height adjustment when keyboard appears is wrong in react ...
I am trying to shorten the screen when the keyboard is active. But it always adjust it weirdly in android, ...
Read more >Adjusting view for Keyboard Height… | Apple Developer Forums
When adjusting my view for the Keyboard Height there is additional space between the software keyboard and the view I am trying to...
Read more >Keyboard Avoidance for SwiftUI Views - Yet Another Swift Blog
Moving SwiftUI View Up When Keyboard Appears · Create keyboard height state. · Add padding to the bottom of the view, which will...
Read more >Android how to adjust for soft keyboard | by Yat Man, Wong
use adjustPan · change to a layout to that support resizing (wrap it in a ScrollView) · mark some views as GONE when...
Read more >Move view when keyboard is shown (guide)
Most likely you have worked on an app with multiple textfields, and when the keyboard show up, there's a chance that your text...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
try the keyboardavoidingview
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
.