我有搜索输入结果列表。我想从列表中选择一个项目。但是当输入字段处于焦点时,我无法在第一次按下时选择项目。第一次按下被认为是关闭键盘。我想在关闭键盘的第一次按下时触发触摸事件。我的代码如下 -
<TextInput
placeholder='Destination'
underlineColorAndroid={'transparent'} style={[styles.input]}
value={this.state.destination}
onChangeText={(text) => this.saveDestination(text)}
/>
<View style={{ backgroundColor: WHITE, marginVertical:
(this.state.predictions.length === 0) ? 0 : 15 }}>
{this.destinationPredictation()}
</View>
destinationPredictation() {
const arr = this.state.predictions;
return arr.map((d, index) => {
return (
<TouchableOpacity
onPress={() => { this.setState({ destination: d.description });
}}
style={[{ flex: 1, paddingHorizontal: 5, paddingTop: 10,
paddingBottom: (index === this.state.predictions.length - 1)
? 10 : 0 }]}
key={d.id}
>
<View style={{ width: (WIDTH - 50), paddingHorizontal: 0,
flexDirection: 'row', alignItems: 'center' }}>
<Icon name='map-marker' size={30} color={REGULAR_OPTION}
style={{ marginHorizontal: 8 }} />
<Text style={[styles.destinationOptions, { flex: 1 }]}>
{d.description}
</Text>
</View>
</TouchableOpacity>
);
});
}