【发布时间】:2017-06-27 23:28:09
【问题描述】:
我有一个 textInput,它下面有一个 ListView,它就像一个自动完成功能。我没有使用第三方库,只是对原生组件做出反应。但是,由于在 TextInput 中输入文本时,TextInput 具有焦点,而 ListView 没有,因此您只需点击 listView 一次以使其获得焦点,然后再次点击它以选择列表项。有没有一种方法可以让您点击 ListView 项目一次,并将其注册为 ListItem 上的点击,而不必点击两次?
代码:
const getDisplay = (shouldHideResults) => {
return shouldHideResults ? 'none' : 'flex'
}
var ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 })
let Location = (props) => {
return (
<View style={styles1.container}>
<TextInput
style={styles1.textinput}
onChangeText={text => changeText(props, text)}
placeholder="Location"
value={props.locationInput}
ref={input => locationInputElement = input} />
<ListView
dataSource={ds.cloneWithRows(props.autocompleteResults.predictions)}
renderRow={place => renderAutocompleteItem(props, place)}
style={{
display: getDisplay(shouldHideResults)
}} />
</View>
)
}
var styles1 = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#FFFFFF',
},
textinput: {
marginTop: 30,
backgroundColor: '#DDDDDD',
height: 40,
width: 200
}
})
【问题讨论】:
标签: javascript listview reactjs react-native