Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// These types are derived from @types/react-native.
// All credit goes to amazing people who made the react-native typings.

import * as React from 'react';
import {
ViewProps,
NativeSyntheticEvent,
NativeSegmentedControlIOSChangeEvent,
NativeMethodsMixin,
Constructor
} from 'react-native'

export interface SegmentedControlIOSProps extends ViewProps {
/**
* If false the user won't be able to interact with the control. Default value is true.
*/
enabled?: boolean;

/**
* If true, then selecting a segment won't persist visually.
* The onValueChange callback will still work as expected.
*/
momentary?: boolean;

/**
* Callback that is called when the user taps a segment;
* passes the event as an argument
*/
onChange?: (event: NativeSyntheticEvent<NativeSegmentedControlIOSChangeEvent>) => void;

/**
* Callback that is called when the user taps a segment; passes the segment's value as an argument
*/
onValueChange?: (value: string) => void;

/**
* The index in props.values of the segment to be (pre)selected.
*/
selectedIndex?: number;

/**
* Accent color of the control.
*/
tintColor?: string;

/**
* The labels for the control's segment buttons, in order.
*/
values?: string[];
}

/**
* 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.
*
* ````
* <SegmentedControlIOS
* values={['One', 'Two']}
* selectedIndex={this.state.selectedIndex}
* onChange={(event) => {
* this.setState({selectedIndex: event.nativeEvent.selectedSegmentIndex});
* }}
* />
* ````
*/
declare class SegmentedControlIOSComponent extends React.Component<SegmentedControlIOSProps> {}
declare const SegmentedControlIOSBase: Constructor<NativeMethodsMixin> & typeof SegmentedControlIOSComponent;
export default class SegmentedControlIOS extends SegmentedControlIOSBase {}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.2",
"description": "React Native SegmentedControlIOS library",
"main": "js/index.js",
"types": "index.d.ts",
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"flow": "flow",
Expand Down Expand Up @@ -37,7 +38,9 @@
"react-test-renderer": "16.8.3",
"rimraf": "^2.6.3",
"semantic-release": "15.10.3",
"typescript": "^3.3.3"
"typescript": "^3.3.3",
"@types/react": "^16.9.17",
"@types/react-native": "0.60.26"
},
"jest": {
"preset": "react-native",
Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,27 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-11.11.7.tgz#f1c35a906b82adae76ede5ab0d2088e58fa37843"
integrity sha512-bHbRcyD6XpXVLg42QYaQCjvDXaCFkvb3WbCIxSDmhGbJYVroxvYzekk9QGg1beeIawfvSLkdZpP0h7jxE4ihnA==

"@types/prop-types@*":
version "15.7.3"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==

"@types/react-native@0.60.26":
version "0.60.26"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.60.26.tgz#cfbb02c39cd162240d59f4922b5bdeb0c212f90d"
integrity sha512-M2ZE5/65Z+cmnP0hz/ImsR4eeqgHenLPWIxhJiaWsTuIMYlTfOxSIqkJQ0SFm4BdklxDS1aaH4+3d8ve+0LHMQ==
dependencies:
"@types/prop-types" "*"
"@types/react" "*"

"@types/react@*", "@types/react@^16.9.17":
version "16.9.17"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.17.tgz#58f0cc0e9ec2425d1441dd7b623421a867aa253e"
integrity sha512-UP27In4fp4sWF5JgyV6pwVPAQM83Fj76JOcg02X5BZcpSu5Wx+fP9RMqc2v0ssBoQIFvD5JdKY41gjJJKmw6Bg==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
Expand Down Expand Up @@ -2361,6 +2382,11 @@ cssstyle@^1.0.0:
dependencies:
cssom "0.3.x"

csstype@^2.2.0:
version "2.6.8"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.8.tgz#0fb6fc2417ffd2816a418c9336da74d7f07db431"
integrity sha512-msVS9qTuMT5zwAGCVm4mxfrZ18BNc6Csd0oJAtiFMZ1FAx1CCvy2+5MDmYoix63LM/6NDbNtodCiGYGmFgO0dA==

currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"
Expand Down