分享

react-native 键盘遮挡输入框

 丹枫无迹 2020-09-26

Android上已经自动对键盘遮挡输入框做了处理,所以我们只需要关注ios。

1.首先引入 KeyboardAvoidingView

import { KeyboardAvoidingView } from 'react-native';

2.然后在页面的最外层加上 KeyboardAvoidingView

render(){
    return <KeyboardAvoidingView behavior={'padding'} style={{flex: 1}}>
        {/*具体页面内容*/}
    </KeyboardAvoidingView>
}

如果适配ios和Android,可以将页面提取出来

    getPageView = () => {
        //return 具体页面内容
    }
    getPlatformView = () => {
        if (Platform.OS === 'ios') {
            return <KeyboardAvoidingView behavior={'padding'} style={{flex: 1}}>
                    {this.getPageView()}
            </KeyboardAvoidingView>
        } else {
            return this.getPageView();
        }
    };

    render() {
        return this.getPlatformView();
    }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多