Search code examples
react-nativepicker

refs working on iOS but undefined on Android - React Native


So I have two components

    <TouchableInput
      onPress={() => this.interestedInPicker.togglePicker()}
    />
    <RNPickerSelect
      placeholder={{}}
      items={[
        {
          label: 'text',
          value: 'value`,
        },
        {
          label: 'text'
          value: 'value',
        },
        {
          label: 'text',
          value: 'value',
        },
      ]}
      onValueChange={restInput.onChange}
      style={styles.interestedInPicker}
      value={restInput.value}
      ref={ref => (this.interestedInPicker = ref)}
    />

RNPickerSelect has height of 0 so it is hidden. When I press on the TouchableInput I want the function togglePicker to trigger. This works on iOS but logs undefined on Android. When I console.log this.interestedInPicker I can see the method I need but when I log the whole expression it is undefined. Any idea what is going on ?


Solution

  • I opened this as an issue for library RNPickerSelect about a month ago.

    It is a known problem. The issue is that they need a way to trigger the picker programatically. You might be able to find a temporary solution HERE