From b85f0ac74fb7d037a3e96365fa6d5eba5350086e Mon Sep 17 00:00:00 2001 From: pedramsaleh Date: Sun, 20 Mar 2016 18:06:33 -0700 Subject: [PATCH] Update SegmentedControlIOS.ios.js Summary:Updating the comments to clarify that the selectedIndex prop is not just for pre-selecting an index, but that it can also be used to programmatically change the value of the selected index. Closes https://github.com/facebook/react-native/pull/6519 Differential Revision: D3075199 Pulled By: mkonicek fb-gh-sync-id: 8ce336ad491bb2fed13df15ebddb1b24535c50ff shipit-source-id: 8ce336ad491bb2fed13df15ebddb1b24535c50ff --- .../SegmentedControlIOS.ios.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js b/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js index 6393e89da4cfe5..34ef75a8a7ec06 100644 --- a/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js +++ b/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js @@ -31,6 +31,23 @@ type Event = Object; /** * Use `SegmentedControlIOS` to render a UISegmentedControl iOS. + * + * #### Programmatically changing selected index + * + * The selected index can be changed on the fly by assigning the + * selectIndex prop to a state variable, then changing that variable. + * Note that the state variable would need to be updated as the user + * selects a value and changes the index, as shown in the example below. + * + * ```` + * { + * this.setState({selectedIndex: event.nativeEvent.selectedSegmentIndex}); + * }} + * /> + * ```` */ var SegmentedControlIOS = React.createClass({ mixins: [NativeMethodsMixin], @@ -43,7 +60,7 @@ var SegmentedControlIOS = React.createClass({ values: PropTypes.arrayOf(PropTypes.string), /** - * The index in `props.values` of the segment to be pre-selected + * The index in `props.values` of the segment to be (pre)selected. */ selectedIndex: PropTypes.number,