Skip to content

Commit

Permalink
Fix iOS Picker Item Colors
Browse files Browse the repository at this point in the history
Summary:
I want to resolve #11170 by passing the `color` prop from `PickerIOS.Item` to its implementation.

In `RCTPicker.m`, the label.textColor was already being set and used, but there was nothing referencing the past prop. I passed the prop to the implementation, checked if it exists, and if not, set the default color, like before.

I visually tested the **Colorful Pickers** example in UIExplorer. Those picker `Item`s pass in a `color` prop.

![dec-01-2016 22-07-46](https://cloud.githubusercontent.com/assets/9259509/20821696/ae45d704-b812-11e6-9720-0045d6c0bcd4.gif)

The basic picker does not pass the color prop to the picker `Item`, and there are no errors. Basic functionality is still in tact:

![dec-01-2016 22-09-35](https://cloud.githubusercontent.com/assets/9259509/20821730/ee544f74-b812-11e6-9294-a1b45e78d9f7.gif)
Closes #11260

Differential Revision: D4272370

fbshipit-source-id: 5fa33c40526dda59ca2ab527c31351bcd27e5cf3
  • Loading branch information
JakeDawkins authored and Martin Konicek committed Dec 12, 2016
1 parent 6ffa235 commit 4dea892
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Libraries/Components/Picker/PickerIOS.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var StyleSheet = require('StyleSheet');
var StyleSheetPropType = require('StyleSheetPropType');
var TextStylePropTypes = require('TextStylePropTypes');
var View = require('View');
var processColor = require('processColor');

var itemStylePropType = StyleSheetPropType(TextStylePropTypes);
var requireNativeComponent = require('requireNativeComponent');
Expand Down Expand Up @@ -48,7 +49,11 @@ var PickerIOS = React.createClass({
if (child.props.value === props.selectedValue) {
selectedIndex = index;
}
items.push({value: child.props.value, label: child.props.label});
items.push({
value: child.props.value,
label: child.props.label,
textColor: processColor(child.props.color),
});
});
return {selectedIndex, items};
},
Expand Down Expand Up @@ -95,6 +100,7 @@ PickerIOS.Item = class extends React.Component {
static propTypes = {
value: React.PropTypes.any, // string or integer basically
label: React.PropTypes.string,
color: React.PropTypes.string,
};

render() {
Expand Down
4 changes: 3 additions & 1 deletion React/Views/RCTPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ - (UIView *)pickerView:(UIPickerView *)pickerView
}

label.font = _font;
label.textColor = _color;

label.textColor = [RCTConvert UIColor:_items[row][@"textColor"]] ?: _color;

label.textAlignment = _textAlign;
label.text = [self pickerView:pickerView titleForRow:row forComponent:component];
return label;
Expand Down

0 comments on commit 4dea892

Please sign in to comment.