Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
*
|
2018-05-10 19:06:46 -07:00
|
|
|
* @format
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-10 19:06:46 -07:00
|
|
|
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-03 15:04:46 -08:00
|
|
|
const React = require('React');
|
|
|
|
const StyleSheet = require('StyleSheet');
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
|
2019-01-16 13:23:16 -08:00
|
|
|
const RCTSegmentedControlNativeComponent = require('RCTSegmentedControlNativeComponent');
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
|
2018-11-05 11:21:08 -08:00
|
|
|
import type {SyntheticEvent} from 'CoreEventTypes';
|
2018-05-14 00:09:28 -07:00
|
|
|
import type {ViewProps} from 'ViewPropTypes';
|
|
|
|
|
2018-11-05 11:21:08 -08:00
|
|
|
type Event = SyntheticEvent<
|
|
|
|
$ReadOnly<{|
|
|
|
|
value: number,
|
|
|
|
selectedSegmentIndex: number,
|
|
|
|
|}>,
|
|
|
|
>;
|
2018-06-01 12:37:22 -07:00
|
|
|
|
2018-11-05 11:21:08 -08:00
|
|
|
type SegmentedControlIOSProps = $ReadOnly<{|
|
2018-05-14 00:09:28 -07:00
|
|
|
...ViewProps,
|
2018-11-05 11:21:08 -08:00
|
|
|
/**
|
|
|
|
* The labels for the control's segment buttons, in order.
|
|
|
|
*/
|
|
|
|
values?: $ReadOnlyArray<string>,
|
|
|
|
/**
|
|
|
|
* The index in `props.values` of the segment to be (pre)selected.
|
|
|
|
*/
|
2018-05-14 00:09:28 -07:00
|
|
|
selectedIndex?: ?number,
|
2018-11-05 11:21:08 -08:00
|
|
|
/**
|
|
|
|
* Callback that is called when the user taps a segment;
|
|
|
|
* passes the segment's value as an argument
|
|
|
|
*/
|
|
|
|
onValueChange?: ?(value: number) => mixed,
|
|
|
|
/**
|
|
|
|
* Callback that is called when the user taps a segment;
|
|
|
|
* passes the event as an argument
|
|
|
|
*/
|
|
|
|
onChange?: ?(event: Event) => mixed,
|
|
|
|
/**
|
|
|
|
* If false the user won't be able to interact with the control.
|
|
|
|
* Default value is true.
|
|
|
|
*/
|
|
|
|
enabled?: boolean,
|
|
|
|
/**
|
|
|
|
* Accent color of the control.
|
|
|
|
*/
|
2018-05-14 00:09:28 -07:00
|
|
|
tintColor?: ?string,
|
2018-11-05 11:21:08 -08:00
|
|
|
/**
|
|
|
|
* If true, then selecting a segment won't persist visually.
|
|
|
|
* The `onValueChange` callback will still work as expected.
|
|
|
|
*/
|
2018-05-14 00:09:28 -07:00
|
|
|
momentary?: ?boolean,
|
|
|
|
|}>;
|
|
|
|
|
2018-11-05 11:21:08 -08:00
|
|
|
type Props = $ReadOnly<{|
|
|
|
|
...SegmentedControlIOSProps,
|
2019-01-16 13:23:16 -08:00
|
|
|
forwardedRef: ?React.Ref<typeof RCTSegmentedControlNativeComponent>,
|
2018-11-05 11:21:08 -08:00
|
|
|
|}>;
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use `SegmentedControlIOS` to render a UISegmentedControl iOS.
|
2016-03-20 18:06:33 -07:00
|
|
|
*
|
|
|
|
* #### Programmatically changing selected index
|
|
|
|
*
|
|
|
|
* The selected index can be changed on the fly by assigning the
|
2017-09-01 12:53:24 -07:00
|
|
|
* selectedIndex prop to a state variable, then changing that variable.
|
2016-03-20 18:06:33 -07:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* ````
|
|
|
|
* <SegmentedControlIOS
|
|
|
|
* values={['One', 'Two']}
|
|
|
|
* selectedIndex={this.state.selectedIndex}
|
|
|
|
* onChange={(event) => {
|
|
|
|
* this.setState({selectedIndex: event.nativeEvent.selectedSegmentIndex});
|
|
|
|
* }}
|
|
|
|
* />
|
|
|
|
* ````
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
*/
|
|
|
|
|
2018-11-05 11:21:08 -08:00
|
|
|
class SegmentedControlIOS extends React.Component<Props> {
|
|
|
|
static defaultProps = {
|
|
|
|
values: [],
|
|
|
|
enabled: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
_onChange = (event: Event) => {
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
this.props.onChange && this.props.onChange(event);
|
2018-05-10 19:06:46 -07:00
|
|
|
this.props.onValueChange &&
|
|
|
|
this.props.onValueChange(event.nativeEvent.value);
|
2018-11-05 11:21:08 -08:00
|
|
|
};
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
|
2018-11-05 11:21:08 -08:00
|
|
|
render() {
|
|
|
|
const {forwardedRef, ...props} = this.props;
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
return (
|
2019-01-16 13:23:16 -08:00
|
|
|
<RCTSegmentedControlNativeComponent
|
2018-11-05 11:21:08 -08:00
|
|
|
{...props}
|
|
|
|
ref={forwardedRef}
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
style={[styles.segmentedControl, this.props.style]}
|
|
|
|
onChange={this._onChange}
|
|
|
|
/>
|
|
|
|
);
|
2018-11-05 11:21:08 -08:00
|
|
|
}
|
|
|
|
}
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
|
2018-03-03 15:04:46 -08:00
|
|
|
const styles = StyleSheet.create({
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
segmentedControl: {
|
2016-04-26 04:20:56 -07:00
|
|
|
height: 28,
|
Add SegmentedControlIOS
Summary:
Fixes #534:

```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 08:15:28 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-11-05 11:21:08 -08:00
|
|
|
const SegmentedControlIOSWithRef = React.forwardRef(
|
|
|
|
(
|
|
|
|
props: SegmentedControlIOSProps,
|
2019-01-16 13:23:16 -08:00
|
|
|
forwardedRef: ?React.Ref<typeof RCTSegmentedControlNativeComponent>,
|
2018-11-05 11:21:08 -08:00
|
|
|
) => {
|
|
|
|
return <SegmentedControlIOS {...props} forwardedRef={forwardedRef} />;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2018-12-14 13:54:52 -08:00
|
|
|
/* $FlowFixMe(>=0.89.0 site=react_native_ios_fb) This comment suppresses an
|
|
|
|
* error found when Flow v0.89 was deployed. To see the error, delete this
|
|
|
|
* comment and run Flow. */
|
2018-11-05 11:21:08 -08:00
|
|
|
module.exports = (SegmentedControlIOSWithRef: NativeSegmentedControlIOS);
|