【发布时间】:2018-07-06 15:55:03
【问题描述】:
基本上我有一个组件的行为类似于TextInput,如下所示
//Input.js
import React from 'react';
import { Text, TextInput, View } from 'react-native';
const Input = ({ label, value, onChangeText }) => {
const { inputStyle, containerStyle, labelStyle } = styles;
return (
<View style={containerStyle}>
<Text style={labelStyle}>{ label }</Text>
<TextInput
style={inputStyle}
onChangeText={onChangeText}
value={value}
/>
</View>
);
};
我还有另一个组件利用上面Input 组件的输入
//InputForm.js
import React, { Component } from 'react';
import { Button, Card, CardSection, Input } from './common';
class LoginForm extends Component {
state = { text: '' };
render() {
return (
<Card>
<CardSection>
<Input
autoCorrect={false}
value={this.state.text}
onChangeText={text => this.setState({ text })}
label='Email'
/>
</CardSection>
<CardSection />
<CardSection>
<Button>
Login
</Button>
</CardSection>
</Card>
);
}
}
export default LoginForm;
正如第一个 Input.js 中清楚显示的那样,我们只接收 label, value, onChangeText 作为道具,而在我的 InputForm.js 中,我传递了一个额外的道具 autoCorrect。现在发生的事情是,自动建议确实被禁用了。
如果我错了,请纠正我,Input 组件是一个自定义组件,它不应该理解 autoCorrect 的含义,因为我从未定义 Input.js 中的行为。那么为什么它会起作用呢?
【问题讨论】:
-
也许我不明白这个问题,但默认情况下似乎禁用了自动建议。尝试设置 autoCorrect={true} (或者只是“autoCorrect”没有任何值,因为它是布尔值),看看会发生什么。
-
@DmitryBirin:在ios上,autoCorrect默认为true,因此只需将其设置为false就可以看到这里的效果。
标签: react-native components textinput prop