页面包含scrollView和TextInput,当键盘弹起来的

2022-09-28  本文已影响0人  sunny635533

android的手机,页面包含scrollView和TextInput,当键盘弹起来的时候会挡住TextInput。
原生键盘模式是“ android:windowSoftInputMode="adjustResize"”。
用了如下方法解决这个问题,虽然不够完美:

componentDidMount() {
       this.keyboardDidShow = Keyboard.addListener("keyboardDidShow", e => {
           console.log("====== e.endCoordinates.height:" + e.endCoordinates.height)
           this.setState({ KeyboardHeight: e.endCoordinates.height })
       });
       this.keyboardDidHide = Keyboard.addListener("keyboardDidHide", e => {
           this.setState({ KeyboardHeight: 0 })
       });
   }

   componentWillUnmount() {
       this.keyboardDidShow.remove();
       this.keyboardDidHide.remove();
   }

render() {
       return (<View style={styles.container}>
           {Platform.OS == "android" && <View style={{
               height: this.state.KeyboardHeight,
               backgroundColor: "rgba(0,0,0,0.5)"
           }} />}
           ....
           </View>

希望有更好的方法,欢迎指点。

上一篇下一篇

猜你喜欢

热点阅读