Age*_*ger 12 react-native react-native-flatlist
当我在TextInput中输入内容时,我第一次触摸FlatList项目之一.应该是console.log('item press'),但事实并非如此.只有第二次触摸它控制台.有人知道原因吗?
这是我的代码.
<TextInput
placeholder='test'
value={this.state.inputText}
onChangeText={(inputText) => this.setState({inputText})}
style={{
marginBottom: 20,
fontSize: 17,
width: 300,
textAlign: 'center''
}}
/>
<FlatList
data={[{key: 'item 1'}, {key: 'item 2'}]}
renderItem={({item}) =>
<TouchableHighlight
onPress={() => console.log('item press')}
underlayColor='#dddddd'
>
<View style={{height: 40}}>
<Text style={{fontSize: 16, textAlign: 'center'}}>{item.key}</Text>
</View>
</TouchableHighlight>
}
/>
Run Code Online (Sandbox Code Playgroud)
Vah*_*iri 16
您应该使用FlatListwith keyboardShouldPersistTaps={'handled'}prop并在另一个函数中关闭键盘Keyboard.Dissmiss().你FlatList会是这样的:
<FlatList
keyboardShouldPersistTaps={'handled'}
data={[{key: 'item 1'}, {key: 'item 2'}]}
renderItem={({item}) =>
<TouchableHighlight onPress={() => console.log('item press')}
underlayColor='#dddddd'>
<View style={{height: 40}}>
<Text style={{fontSize: 16, textAlign: 'center'}}>{item.key}</Text>
</View>
</TouchableHighlight>
}
/>
Run Code Online (Sandbox Code Playgroud)
您可以在组件中的命令中使用prop中的Keyboard.dismiss()函数.onPressconsole.log('item press')TouchableHighlight
| 归档时间: |
|
| 查看次数: |
3548 次 |
| 最近记录: |