React native 表单输入中的文本组件
我的目标是在输入中包含一个组件。这些是我的选项,我将从“tcomb form native”中的React native 表单输入中的文本组件,react-native,tcomb-form-native,React Native,Tcomb Form Native,我的目标是在输入中包含一个组件。这些是我的选项,我将从“tcomb form native”中的import t传递给表单 commentFormOptions = { fields: { comment: { label: 'What do you think?', placeholder: 'Type your reply', stylesheet: InputStylesheet, returnKeyType: 'done',
import t传递给表单代码>
commentFormOptions = {
fields: {
comment: {
label: 'What do you think?',
placeholder: 'Type your reply',
stylesheet: InputStylesheet,
returnKeyType: 'done',
onSubmitEditing: () => {
this.postComment();
},
},
},
}
在这里,您可以看到视图的位置:
<View style={styles.container}>
<KeyboardAvoidingView
style={styles.commentForm}
<Form
ref={ref => this.form = ref}
type={CommentModel}
options={this.commentFormOptions} />
/>
<TouchableHighlight>
<Text style={{ padding: 10, fontSize: 42 }}>Post</Text>
</TouchableHighlight>
</KeyboardAvoidingView>
</View>
/>
邮递
我不确定我是否完全理解为什么我不能进入并传递TouchableHighlight和文本
我错过了什么?我该怎么做
编辑
你可以在这里看到:但是我试图在输入的右侧获得帖子文本,这样我就可以有一个onPress来提交它。然而由于某些原因,我无法获取输入中的文本。您需要使用自定义的注释组件覆盖默认的文本框组件。看
如果需要将Post
按钮包装在TextInput
边框内,则需要创建自己的TextInput
(在包含TextInput
和TouchableHighlight
的整个容器周围放置边框)
const{Form,Textbox}=t.Form;
const Comment=props=>(
邮递
);
导出默认类应用程序扩展组件{
静态导航选项={
标题:“评论”,
};
commentFormOptions={
字段:{
评论:{
标签:“你觉得怎么样?”,
占位符:“键入您的答复”,
returnKeyType:“完成”,
工厂:道具=>(
console.log('pressed')}/>
),
样式表:{
…Form.stylesheet,
文本框:{
…Form.stylesheet.textbox,
正常:{
…Form.stylesheet.textbox.normal,
宽度:尺寸。获取(“窗口”)。宽度-70,
},
},
},
},
},
};
发生了什么错误?为什么您的键盘上有
“AvoidingView”
道具声明?它应该是键盘avoidingview
的子对象吗?是否希望触摸式突出显示显示在表单的下方
?没有错误。当我把它包装起来的时候,我就是看不见Post这个词。现在我的目标是得到一个单词Post,我可以在评论中添加一个点击处理程序。我想你没有粘贴正确的代码。这无法编译。你能在上创建一个吗?@riwu当然-我在等待这个让我运行它,但它看起来像这样:
const { Form, Textbox } = t.form;
const Comment = props => (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
}}>
<Textbox {...props} />
<TouchableHighlight style={styles.postButton} onPress={props.onPress}>
<Text style={{ padding: 10, fontSize: 20 }}>Post</Text>
</TouchableHighlight>
</View>
);
export default class App extends Component {
static navigationOptions = {
title: 'Comments',
};
commentFormOptions = {
fields: {
comment: {
label: 'What do you think?',
placeholder: 'Type your reply',
returnKeyType: 'done',
factory: props => (
<Comment {...props} onPress={() => console.log('pressed')} />
),
stylesheet: {
...Form.stylesheet,
textbox: {
...Form.stylesheet.textbox,
normal: {
...Form.stylesheet.textbox.normal,
width: Dimensions.get('window').width - 70,
},
},
},
},
},
};