From 06c2d959dace506806ec2ec9e297ab4fa2e23386 Mon Sep 17 00:00:00 2001 From: Clay Allsopp Date: Wed, 1 Apr 2015 12:34:28 -0700 Subject: [PATCH] update API for selectedSegmentIndex --- .../UIExplorer/SegmentedControlIOSExample.js | 36 ++++++++++++++----- .../SegmentedControlIOSSnapshotTest.js | 8 ++--- .../SegmentedControlIOS.js | 17 +++++---- React/Views/RCTSegmentedControl.h | 2 +- React/Views/RCTSegmentedControl.m | 22 +++++------- React/Views/RCTSegmentedControlManager.m | 2 +- 6 files changed, 50 insertions(+), 37 deletions(-) diff --git a/Examples/UIExplorer/SegmentedControlIOSExample.js b/Examples/UIExplorer/SegmentedControlIOSExample.js index 1459c35a1a037a..e3dc291e55d422 100644 --- a/Examples/UIExplorer/SegmentedControlIOSExample.js +++ b/Examples/UIExplorer/SegmentedControlIOSExample.js @@ -43,7 +43,7 @@ var PreSelectedSegmentedControlExample = React.createClass({ return ( - + ); @@ -67,7 +67,7 @@ var DisabledSegmentedControlExample = React.createClass({ return ( - + ); @@ -79,10 +79,10 @@ var ColorSegmentedControlExample = React.createClass({ return ( - + - + ); @@ -92,20 +92,40 @@ var ColorSegmentedControlExample = React.createClass({ var EventSegmentedControlExample = React.createClass({ getInitialState() { return { - value: 'Not selected' + values: ["One", "Two", "Three"], + value: 'Not selected', + selectedSegmentIndex: undefined }; }, + render() { return ( - {this.state.value} + Value: {this.state.value} + + + Index: {this.state.selectedSegmentIndex} this.setState({value: value})} /> + values={this.state.values} + selectedSegmentIndex={this.state.selectedSegmentIndex} + onChange={this._onChange} + onValueChange={this._onValueChange} /> ); + }, + + _onChange(event) { + this.setState({ + selectedSegmentIndex: event.nativeEvent.selectedSegmentIndex, + }); + }, + + _onValueChange(value) { + this.setState({ + value: value, + }); } }); diff --git a/IntegrationTests/SegmentedControlIOSSnapshotTest.js b/IntegrationTests/SegmentedControlIOSSnapshotTest.js index bb27e6e644407c..22164ad92ea4df 100644 --- a/IntegrationTests/SegmentedControlIOSSnapshotTest.js +++ b/IntegrationTests/SegmentedControlIOSSnapshotTest.js @@ -36,19 +36,19 @@ var SegmentedControlIOSSnapshotTest = React.createClass({ - + - + - + - + ); diff --git a/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.js b/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.js index fd5468bf1e6837..fc0c780d10e338 100644 --- a/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.js +++ b/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.js @@ -46,10 +46,9 @@ var SegmentedControlIOS = React.createClass({ values: PropTypes.arrayOf(PropTypes.string), /** - * The segmented to be pre-selected; if not in `props.values`, then - * has no effect. + * The index in `props.values` of the segment to be pre-selected */ - selectedValue: PropTypes.string, + selectedSegmentIndex: PropTypes.number, /** * Used to style and layout the `SegmentedControl`. See `StyleSheet.js` and @@ -100,16 +99,16 @@ var SegmentedControlIOS = React.createClass({ }, render: function() { - var valuesAndSelectedValue = { - selectedValue: this.props.selectedValue, + var valuesAndSelectedSegmentIndex = { + selectedSegmentIndex: this.props.selectedSegmentIndex, values: this.props.values - } + }; return (