From 6f0c481b86fee4987e4c0ea0e8dc6e5b137df819 Mon Sep 17 00:00:00 2001 From: ebragge Date: Mon, 21 Mar 2016 15:23:56 +0200 Subject: [PATCH] feat(ReactPickerView): Add ReactPickerView ReactPicker provides access to native selector UI components for React Native JavaScript applications. - PR comments #2 implemented Fixes #231 --- .../Views/Picker/ReactPickerManager.cs | 21 ++++++++----------- ...kerAndroid.js => PickerAndroid.windows.js} | 0 .../{PickerIOS.js => PickerIOS.windows.js} | 0 .../js/Components/Picker/PickerWindows.js | 17 ++++----------- 4 files changed, 13 insertions(+), 25 deletions(-) rename ReactWindows/js/Components/Picker/{PickerAndroid.js => PickerAndroid.windows.js} (100%) rename ReactWindows/js/Components/Picker/{PickerIOS.js => PickerIOS.windows.js} (100%) diff --git a/ReactWindows/ReactNative/Views/Picker/ReactPickerManager.cs b/ReactWindows/ReactNative/Views/Picker/ReactPickerManager.cs index 8e0b1467597..fbb74c46777 100644 --- a/ReactWindows/ReactNative/Views/Picker/ReactPickerManager.cs +++ b/ReactWindows/ReactNative/Views/Picker/ReactPickerManager.cs @@ -12,9 +12,7 @@ namespace ReactNative.Views.Picker /// A view manager responsible for rendering picker. /// public class ReactPickerManager : BaseViewManager - { - private int _selected; - + { /// /// The name of the view manager. /// @@ -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) { @@ -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("label"); + if (label != null) { var item = new ComboBoxItem(); - JToken color; + item.Content = label.Value(); - if ((color = items[index].Value("color")) != null) + var color = items[index].Value("color"); + if (color != null) { var rgb = color.Value(); item.Foreground = new SolidColorBrush(ColorHelpers.Parse(rgb)); } + view.Items.Add(item); } } - - view.SelectedIndex = view.Items.Count > _selected ? _selected : -1; - + view.SelectionChanged += OnSelectionChanged; } diff --git a/ReactWindows/js/Components/Picker/PickerAndroid.js b/ReactWindows/js/Components/Picker/PickerAndroid.windows.js similarity index 100% rename from ReactWindows/js/Components/Picker/PickerAndroid.js rename to ReactWindows/js/Components/Picker/PickerAndroid.windows.js diff --git a/ReactWindows/js/Components/Picker/PickerIOS.js b/ReactWindows/js/Components/Picker/PickerIOS.windows.js similarity index 100% rename from ReactWindows/js/Components/Picker/PickerIOS.js rename to ReactWindows/js/Components/Picker/PickerIOS.windows.js diff --git a/ReactWindows/js/Components/Picker/PickerWindows.js b/ReactWindows/js/Components/Picker/PickerWindows.js index ad7b13f745c..ecf93fbf7ba 100644 --- a/ReactWindows/js/Components/Picker/PickerWindows.js +++ b/ReactWindows/js/Components/Picker/PickerWindows.js @@ -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 ; @@ -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;