Skip to content

Commit

Permalink
feat(ReactPickerView): Add ReactPickerView
Browse files Browse the repository at this point in the history
ReactPicker provides access to native selector UI components for React Native JavaScript applications.
- PR comments #2 implemented

Fixes #231
  • Loading branch information
ebragge committed Mar 21, 2016
1 parent 35dcd57 commit d3a79b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
21 changes: 9 additions & 12 deletions ReactWindows/ReactNative/Views/Picker/ReactPickerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ namespace ReactNative.Views.Picker
/// A view manager responsible for rendering picker.
/// </summary>
public class ReactPickerManager : BaseViewManager<ComboBox, ReactPickerShadowNode>
{
private int _selected;

{
/// <summary>
/// The name of the view manager.
/// </summary>
Expand Down Expand Up @@ -51,8 +49,7 @@ public void SetSelected(ComboBox view, int selected)
// Temporarily disable selection changed event handler.
view.SelectionChanged -= OnSelectionChanged;

_selected = selected;
view.SelectedIndex = view.Items.Count > _selected ? _selected : -1;
view.SelectedIndex = view.Items.Count > selected ? selected : -1;

if (view.SelectedIndex != -1)
{
Expand All @@ -75,23 +72,23 @@ public void SetItems(ComboBox view, JArray items)

for (var index = 0; index < items.Count; index++)
{
JToken label;
if ((items[index] as JObject).TryGetValue("label", out label))
var label = items[index].Value<JToken>("label");
if (label != null)
{
var item = new ComboBoxItem();
JToken color;

item.Content = label.Value<string>();
if ((color = items[index].Value<JToken>("color")) != null)
var color = items[index].Value<JToken>("color");
if (color != null)
{
var rgb = color.Value<uint>();
item.Foreground = new SolidColorBrush(ColorHelpers.Parse(rgb));
}

view.Items.Add(item);
}
}

view.SelectedIndex = view.Items.Count > _selected ? _selected : -1;


view.SelectionChanged += OnSelectionChanged;
}

Expand Down
17 changes: 4 additions & 13 deletions ReactWindows/js/Components/Picker/PickerWindows.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var PickerWindows = React.createClass({
prompt: this.props.prompt,
selected: this.state.selectedIndex,
testID: this.props.testID,
style: [styles.pickerWindows, this.props.style],
style: [this.props.style],
};

return <Picker ref={REF_PICKER} {...nativeProps} />;
Expand Down Expand Up @@ -116,22 +116,13 @@ var PickerWindows = React.createClass({
},
});

var styles = StyleSheet.create({
pickerWindows: {
// The picker will conform to whatever width is given, but we do
// have to set the component's height explicitly on the
// surrounding view to ensure it gets rendered.
// TODO would be better to export a native constant for this,
// like in iOS the RCTDatePickerManager.m
height: 40,
},
});

var cfg = {
nativeOnly: {
items: true,
selected: true,
}
};

var ComboBoxPicker = requireNativeComponent('RCTPicker', PickerWindows, PickerWindows, cfg);
var ComboBoxPicker = requireNativeComponent('RCTPicker', PickerWindows, cfg);

module.exports = PickerWindows;

0 comments on commit d3a79b3

Please sign in to comment.