gpt4 book ai didi

javascript - 选择选项时 react-native-autocomplete-input 列表不关闭

转载 作者:行者123 更新时间:2023-11-29 19:04:44 29 4
gpt4 key购买 nike

我的 react-native-autocomplete-input当我从列表中选择一个元素时,列表似乎没有关闭。

let Location = (props) => (

<View style={styles.formItem}>

<Autocomplete
data={props.autocompleteResults.predictions}
defaultValue={props.locationInput.toString()}
onChangeText={
text => {
props.updateLocationInput(text)
props.getAutocompleteResults(text)
}
}
renderItem={place => (
<TouchableOpacity
style={{
height: 44,
flex: 1,
justifyContent: 'center',
...styles.label,
borderRadius: 8
}}
onPress={() => {
console.log(place)
props.updatePlace(place)
props.updateLocationInput(place.description)
}}>
<Text numberOfLines={1}>{place.description}</Text>
</TouchableOpacity>
)}
inputContainerStyle={{ borderWidth: 0 }}
style={{
height: 44,
borderRadius: 8,
backgroundColor: '#FFFFFF',
alignSelf: 'stretch',
paddingLeft: 10,
position: 'relative',
...styles.label
}}
/>
</View>
)
Location.propTypes = {
locationInput: React.PropTypes.string.isRequired,
updateLocationInput: React.PropTypes.func.isRequired,
getAutocompleteResults: React.PropTypes.func.isRequired,
autocompleteResults: React.PropTypes.object.isRequired,
updatePlace: React.PropTypes.func.isRequired
}

Location = connect(
mapStateToProps,
mapDispatchToProps
)(Location)

这就是 Location 的方式组件被使用。容器是一个原生组件:

<Container style={styles.container}>
<ScrollView keyboardShouldPersistTaps={true}>
<Categories />
<View style={{ zIndex: 2, position: 'relative' }}>
<Location />
</View>
<Keywords />
<Button block style={styles.wideButton} onPress={() => props.toggleMenu()}>
<Text>GO</Text>
</Button>
</ScrollView>
</Container>

Location 组件位于 ScrollView 中但是,当我取出 ScrollView 时,问题仍然存在。我还完成了 ScrollView 修复 <ScrollView keyboardShouldPersistTaps={true}>是什么让列表永远不会关闭?

最佳答案

我们可以试试这个:-

//if data is not available then there would be nothing to show..
data={(!props.autocompleteResults.predictions.length || props.clicked)? [] : props.autocompleteResults.predictions }

onChangeText={
text => {
props.updateLocationInput(text)
props.getAutocompleteResults(text)
props.changeClick(false)
}
}

onPress={() => {
console.log(place)
props.updatePlace(place)
props.updateLocationInput(place.description)
props.changeClick(true)
}}

Inside the component:

constructor(props)
{
super(props);
this.state={ clicked : false }
}

<Location clicked = {this.state.clicked} changeClick={(isClicked) => this.setState({clicked: isClicked})} />

干杯:)

关于javascript - 选择选项时 react-native-autocomplete-input 列表不关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43818905/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com