Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picker with dynamic options broke on Android #12829

Closed
danielfttorres opened this issue Mar 9, 2017 · 6 comments
Closed

Picker with dynamic options broke on Android #12829

danielfttorres opened this issue Mar 9, 2017 · 6 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@danielfttorres
Copy link

danielfttorres commented Mar 9, 2017

Description

I'm try to make a dynamic Picker. They are 02 Pickers and the second options appear according to the option selected in the first Picker.

In iOS everything works fine, but in Android I got the error Cannot read 'props' of null when I select any Picker at second time.

Reproduction

The code and reproduction of this bug is in this repository.

Additional Information

  • React Native version: 0.42.0
  • Platform: Android
  • Operating System: MacOS
  • Dev tools: Android SDK 23.0.1
@sibelius
Copy link

sibelius commented Mar 9, 2017

the error is in this line:

var value = this.props.children[position].props.value;

@danielfttorres
Copy link
Author

danielfttorres commented Mar 9, 2017

Thanks @sibelius. I found the solution.

Problem

At some point, the value passed to onValueChange method is undefined. The property this.props.children[position].props.value doesn't exist because this.props.children are an Array of Arrays. However, at beginning the same property is only an Array, and everything works fine.

Solution

I try to check if this.props.children is an Array of Arrays or only an Array. If is the first condition, I get the value of the second Array. If not, I get the value of the single Array and it works as expected.

I will working on this problem and I try to solve it in a better way. If anyone has a better solution, please comment here.

@tiago-marques
Copy link

Any news about that? Same error here !

@danielfttorres
Copy link
Author

@tiago-marques, for now the solution is:

  1. Go to this line:

    var value = this.props.children[position].props.value;

  2. Change to this:

var value;
if (this.props.children[0][0]) {
  value = this.props.children[0][position].props.value;
} else {
  value = this.props.children[position].props.value;
}

It should be work

@tiago-marques
Copy link

@danielfeelfine thank you !

@danielfttorres
Copy link
Author

Closed by: #8153

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants