React Native - Redux Form焦点不是一个功能

时间:2017-05-07 08:07:01

标签: react-native redux-form native-base

这是我的代码:

componentDidMount = () => {
    console.log(this.refs.lastName.getRenderedComponent());
    this.refs.lastName.getRenderedComponent().focus();

}

render() {
    return (
        <Grid containerStyle={{backgroundColor: '#fff'}}>

            <Row size={3.5} containerStyle={styles.topContainer}>
                <View>
                    <Field type="text" returnKeyType={"next"} ref="firstName" withRef
                           name="firstName" label="First Name" component={RenderField}/>

                    <Field last type="text" name="lastName" label="Last Name"
                           ref="lastName" withRef component={RenderField}/>

                </View>
            </Row>

        </Grid>
    )
}

 // Render Field

import React from 'react';
import PropTypes from 'prop-types';
import {Text} from 'react-native';
import {Item, Input, Label} from 'native-base';

class RenderField extends React.Component {
    render() {
        const {input, label, type, meta: {touched, error, invalid, warning}, custom} = this.props;

        let hasError = false;
        if (error !== undefined) {
            hasError = true;
        }
        return (
            <Item floatingLabel error={hasError} style={{marginBottom: 20}}>
                <Label>{label}</Label>
                <Input {...input} {...custom}/>
                {hasError ? <Text>{error}</Text> : <Text />}
            </Item>
        )
    }
}

export default RenderField;

console.log正常返回,但在this.refs.lastName.getRenderedComponent().focus();它始终返回此错误_this.refs.lastName.getRenderedComponent().focus is not a function

如何将焦点设置在特定输入文本上?

我正在使用Redux Form v6和Native Base v2

感谢。

0 个答案:

没有答案