【发布时间】:2017-10-26 22:59:53
【问题描述】:
如果问题有点愚蠢,当然很抱歉。
在我正在开发的应用程序中,用户应该能够在 TextInput 上滑动。由于 TextInput 只听水龙头,我使用了这个要点:https://gist.github.com/MikeShi42/87b65984f0a31e38d553cc056fcda017 (顺便说一句 @Michael Shi 非常感谢)
但是,一旦我将 TextInput 更改为 SlideTextInput,清除按钮就停止工作。
clearInput() {
this.setState({text: ''});
}
render() {
return (
<Button name='clear' action={this.clearInput} />
<SlideTextInput
style={styles.input}
ref='input'
onChangeText={(text) => this.setState({text: text})}
placeholder={this.state.placeholder}
value={this.state.text}
multiline={true}
returnKeyType='done'
blurOnSubmit={true} />
)
}
我还尝试了this.refs.input.setNativeProps({text: ''});,而不是仅仅传递一个新的value 属性(这对于正常的TextInput 来说应该——而且已经足够了),然后调用forceUpdate(),但再次无济于事。与原始 TextInput 组件相比,SlideTextInput.js 没有太大变化,但我一定遗漏了一些可以解释这种不良行为的东西?
UPD:最后答案很简单。 SlideTextInput 没有像原始 TextInput 那样将组件链接到其本地对应项 (ref={this._setNativeRef}),而是将其引用到字符串 (ref="input")。我把它改回来了,瞧。
【问题讨论】:
标签: react-native