我試圖在鍵盤處於活動狀態時縮短屏幕。但它總是在Android中進行奇怪的調整,它在iOS中工作正常。 鍵盤之前被激活:鍵盤是活動鍵盤出現時的高度調整在反應原生android中是錯誤的
後:
此:
我使用RN 0.37,這當我從頭開始也恰好是我的代碼:
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);
沒有ü找到一個解決方案?我認爲鍵盤的高度更多。我遇到了同樣的問題 – Vicky