Skip to content

Instantly share code, notes, and snippets.

@ricexen
Created December 13, 2018 03:03
Show Gist options
  • Save ricexen/d951bf5fb8f0fd5eafe08d75720375b4 to your computer and use it in GitHub Desktop.
Save ricexen/d951bf5fb8f0fd5eafe08d75720375b4 to your computer and use it in GitHub Desktop.
import React from 'react';
import { View, Picker, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
const PickerExample = ({elements}) => (
<View>
<Picker
mode={Platform.OS === 'ios' ? 'dialog' : 'dropdown'}
style={styles.picker}
selectedValue={this.state.quantityType}
onValueChange={this.changeType}
itemStyle={styles.pickerItems}
>
{elements.map(element => <Picker.Item label={element.label} value={element.value}/>)}
</Picker>
</View>
)
PickerExample.propTypes = {
elements: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string,
value: PropTypes.string,
})
)
}
const styles = StyleSheet.create({
picker: {
flex: 2,
backgroundColor: '#E0E0E0',
height: 40,
},
pickerItems: {
height: 40,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment