Added support for styling the PickerIOS

Summary:
 - PickerIOS accepts now a new prop: style
 - this prop modifies the native style of the RCTPicker allowing to modify the font size of the items (fontSize), color of the items (color, only 6 char HEX values for now) and alignment of the items (textAlign)
Closes https://github.com/facebook/react-native/pull/4490

Reviewed By: svcscm

Differential Revision: D2723190

Pulled By: nicklockwood

fb-gh-sync-id: ab9188192f1d0d087787dfed8c128073bfaa3235
This commit is contained in:
Emilio Rodriguez
2015-12-08 07:44:56 -08:00
committed by facebook-github-bot-3
parent e7a4b20d75
commit e2c35dddba
5 changed files with 107 additions and 29 deletions

View File

@@ -17,8 +17,11 @@ var React = require('React');
var ReactChildren = require('ReactChildren');
var RCTPickerIOSConsts = require('NativeModules').UIManager.RCTPicker.Constants;
var StyleSheet = require('StyleSheet');
var StyleSheetPropType = require('StyleSheetPropType');
var TextStylePropTypes = require('TextStylePropTypes');
var View = require('View');
var itemStylePropType = StyleSheetPropType(TextStylePropTypes);
var requireNativeComponent = require('requireNativeComponent');
var PickerIOS = React.createClass({
@@ -26,6 +29,7 @@ var PickerIOS = React.createClass({
propTypes: {
...View.propTypes,
itemStyle: itemStylePropType,
onValueChange: React.PropTypes.func,
selectedValue: React.PropTypes.any, // string or integer basically
},
@@ -50,13 +54,13 @@ var PickerIOS = React.createClass({
});
return {selectedIndex, items};
},
render: function() {
return (
<View style={this.props.style}>
<RCTPickerIOS
ref={ picker => this._picker = picker }
style={styles.pickerIOS}
ref={picker => this._picker = picker}
style={[styles.pickerIOS, this.props.itemStyle]}
items={this.state.items}
selectedIndex={this.state.selectedIndex}
onChange={this._onChange}
@@ -108,7 +112,11 @@ var styles = StyleSheet.create({
},
});
var RCTPickerIOS = requireNativeComponent('RCTPicker', PickerIOS, {
var RCTPickerIOS = requireNativeComponent('RCTPicker', {
propTypes: {
style: itemStylePropType,
},
}, {
nativeOnly: {
items: true,
onChange: true,