Astral Cloud
Astral Cloud

Reputation: 99

@react-native-picker/picker causes my app to crash (android)

I'm trying to use react-native-picker-select package. and @react-native-picker/picker is a dependency according to their docs. but..

After adding this package to my RN app, it builds without error but the app crashes.

Looked for issues on their repo, but i dont think there are resources for the fix. Already created an issue also on their repo.

Upvotes: 3

Views: 3288

Answers (4)

Shep Sims
Shep Sims

Reputation: 1560

From my testing it seems like if you're running on Expo 34 or previous, you are not required to provide the extra dependency in most cases, but the @react-native-community/picker package works as well.

If you have upgraded to Expo SDK 35 or beyond however, the additional dependency is required and only @react-native-picker/picker will work correctly and not crash.

Upvotes: 0

Prajwal Sadaphal
Prajwal Sadaphal

Reputation: 29

For me, the issue was caused because I was passing a label integer value in Picker.Item component. By passing a string value, the issue was fixed.

Upvotes: 2

Textbook
Textbook

Reputation: 117

Add a <Text></Text> component after the <Picker></Picker> component, inside the parent <View></View> component of the <Picker></Picker> component, just like in the code snippet below:

        <View style={{flex: 1, borderWidth: 1, borderColor: '#0f0'}}>
          <Picker
            style={{...styles.itemPicker, color: theme.TEXT}}
            mode="dropdown"
            selectedValue={unit_elevation}
            onValueChange={(value) => this.changeUserPreferences('unit_elevation', value)}
          >
            <Picker.Item label={messages.meters} value="M" />
            <Picker.Item label={messages.feet} value="FT" />
          </Picker>
          <Text style={{width: '100%', height: 60, position: 'absolute', bottom: 0, left: 0}}>{' '}</Text>
        </View>

Upvotes: 5

Astral Cloud
Astral Cloud

Reputation: 99

After hours of figuring out, instead of using @react-native-picker/picker... use @react-native-community/picker instead even tho they said it's already deprecated.

I've finally successfully run my app while using react-native-picker-select and @react-native-community/picker.

Upvotes: 0

Related Questions