简体   繁体   中英

ReactNative picker value resets on selection

I am working on a react native component where it has a listview with different listitems. ListItems have button on click of which it should show a reactnative pickerview . Now everything works fine except the picker resets its value when i try to select anything from picker.

Not sure if its is because of Listview,renderRow or soemthing else .

Any help will be much appreciated . Thanks

Code Snippet:-

render() {
    console.log('*** Rendeer called ***');
    return (
        <View style={styles.containerFullScreen}>
          <ListView dataSource={this.state.dataSource}
            renderRow={this.renderRow}
            renderSectionHeader={this.renderSectionHeader}>
          </ListView>

        <Picker
         mode="dropdown">
          <Picker.Item label="Java" value="java" />
          <Picker.Item label="JavaScript" value="js" />
          <Picker.Item label="Swift" value="swift" />
        </Picker>


          <TouchableHighlight
            activeOpacity={0.6}
            underlayColor={'transparent'}
            style = {styles.continueBtn}
            onPress={() => this.continueBtnAction()}>
            <Text style={styles.continueBtnText}>CONTINUE</Text>
         </TouchableHighlight>
        </View>
    );

You need to listen to onValueChange and pass the selectedValue props.

Check the Picker documentationhttps://facebook.github.io/react-native/docs/picker.html#picker

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM