React-Native学习之 防止键盘遮挡TextInput

import React,{Component} from 'react';
import ReactNative,{
    AppRegistry,    StyleSheet,    Text,    View,    Image,    TextInput,    Dimensions,    Platform,    TouchableOpacity,    ScrollView,   


} from 'react-native';


import Icon from 'react-native-vector-icons/FontAwesome'


var {width,height}=Dimensions.get('window')


export default class Login extends Component {

   
    _reset() {

        this.refs.scrollView.scrollTo({y: 0});

    }

    _onFocus(refName) {

        setTimeout(() => {
            let scrollResponder = this.refs.scrollView.getScrollResponder();
            scrollResponder.scrollResponderScrollNativeHandletoKeyboard(
                ReactNative.findNodeHandle(this.refs[refName]),10,true);
        },100);
    }
  
   
    render() {
        return (

            <ScrollView
                scrollEnabled={false}     //防止滑动
                contentContainerStyle={{flex:1}}
                ref="scrollView">
                <View style={styles.container}>
                        
                   
                        <TextInput
                            ref="textInput"
                            onBlur={this._reset.bind(this)}
                            onFocus={this._onFocus.bind(this,'textInput')}
                            keyboardType={'numeric'}
                            placeholder='站点地址(URL)'
                            style={styles.username}/>
                                   
                </View>
            </ScrollView>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,        justifyContent: 'center',        alignItems: 'center',        backgroundColor: '#4396d3',    },   
    username: {
        width: width - 40,        height: 40,        backgroundColor: 'white',
    }


});

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...