|
2 | 2 |
|
3 | 3 | React Native Segmented Control for both iOS and Android |
4 | 4 |
|
5 | | -## Installation |
| 5 | +## :anchor: Installation |
6 | 6 |
|
7 | 7 | ```sh |
8 | 8 | npm install react-native-segmented-control |
9 | 9 | ``` |
10 | 10 |
|
11 | | -## Usage |
| 11 | +## :wrench: Props |
12 | 12 |
|
13 | | -```js |
14 | | -import SegmentedControl from "react-native-segmented-control"; |
| 13 | +| Name | Description | Required | Type | Default | |
| 14 | +| ------------------------------- | ---------------------------------------------- | -------- | -------------------- | --------------------- | |
| 15 | +| segments | An array of labels for segments | YES | Array | [] | |
| 16 | +| currentIndex | Index for the currently active segment | YES | Number | 0 | |
| 17 | +| onChange | A callback Function with pressed segment index | YES | Function | () => {} | |
| 18 | +| badgeCount | An array of badge value for segments. | NO | Array | [] | |
| 19 | +| isRTL | Controls the toggle animation direction | NO | Boolean | false | |
| 20 | +| containerMargin | The value used to determine the width | NO | Number | 16 | |
| 21 | +| activeTextStyle | active text styles | NO | TextStyle | {} | |
| 22 | +| inactiveTextStyle | inactive text styles. | NO | ViewStyle | {} | |
| 23 | +| segmentedControlWrapper | Style object for the Segmented Control. | NO | ViewStyle. | {} | |
| 24 | +| pressableWrapper | Style object for the Pressable Container | NO | ViewStyle. | {} | |
| 25 | +| tileStyle | Style object for the Absolute positioned tile | NO | ViewStyle | {} | |
15 | 26 |
|
16 | | -// ... |
17 | 27 |
|
18 | | -const result = await SegmentedControl.multiply(3, 7); |
| 28 | +> :warning: `segmentedControlWrapper` accepts all View styles and does override some default styles provided by the package. Make sure you use it properly :) |
| 29 | +
|
| 30 | +> :warning: `activeTextStyle` and `inactiveTextStyle` accepts all Text styles and overrides the defaults. Make sure you use it properly :) |
| 31 | +
|
| 32 | +> :warning: `tileStyle` accepts all View styles and does override some default styles provided by the package. Make sure you use it properly :) |
| 33 | +
|
| 34 | +> :information_source: To apply your own `shadowStyles` use the tileStyle prop |
| 35 | +
|
| 36 | + |
| 37 | + |
| 38 | +## :mag: Usage |
| 39 | + |
| 40 | +```tsx |
| 41 | +import SegmentedControl from 'react-native-segmented-control'; |
| 42 | + |
| 43 | +import * as React from 'react'; |
| 44 | +import { StyleSheet, View } from 'react-native'; |
| 45 | +import SegmentedControl from './SegmentedControl'; |
| 46 | + |
| 47 | +export default function App() { |
| 48 | + const [tabIndex, setTabIndex] = React.useState(0); |
| 49 | + const [tabIndex1, setTabIndex1] = React.useState(0); |
| 50 | + const [tabIndex2, setTabIndex2] = React.useState(0); |
| 51 | + const [tabIndex3, setTabIndex3] = React.useState(0); |
| 52 | + const [tabIndex4, setTabIndex4] = React.useState(0); |
| 53 | + const [tabIndex5, setTabIndex5] = React.useState(0); |
| 54 | + const [tabIndex6, setTabIndex6] = React.useState(0); |
| 55 | + |
| 56 | + return ( |
| 57 | + <View style={styles.container}> |
| 58 | + <View style={styles.box}> |
| 59 | + <SegmentedControl |
| 60 | + containerMargin={16} |
| 61 | + segments={['Label 1', 'Label 2']} |
| 62 | + onChange={(index) => setTabIndex(index)} |
| 63 | + currentIndex={tabIndex} |
| 64 | + /> |
| 65 | + </View> |
| 66 | + <View style={styles.box}> |
| 67 | + <SegmentedControl |
| 68 | + containerMargin={16} |
| 69 | + segments={['Label 1', 'Label 2', 'Label 3']} |
| 70 | + onChange={(index) => setTabIndex1(index)} |
| 71 | + currentIndex={tabIndex1} |
| 72 | + /> |
| 73 | + </View> |
| 74 | + <View style={styles.box}> |
| 75 | + <SegmentedControl |
| 76 | + containerMargin={16} |
| 77 | + segments={['Label 1', 'Label 2', 'Label 3', 'Label 4']} |
| 78 | + onChange={(index) => setTabIndex2(index)} |
| 79 | + currentIndex={tabIndex2} |
| 80 | + /> |
| 81 | + </View> |
| 82 | + <View style={styles.box}> |
| 83 | + <SegmentedControl |
| 84 | + containerMargin={16} |
| 85 | + segments={['Label 1', 'Label 2', 'Label 3']} |
| 86 | + onChange={(index) => setTabIndex3(index)} |
| 87 | + currentIndex={tabIndex3} |
| 88 | + segmentedControlWrapper={{ backgroundColor: '#4a5568' }} |
| 89 | + activeTextStyle={styles.customBlackColor} |
| 90 | + inactiveTextStyle={styles.customWhiteColor} |
| 91 | + /> |
| 92 | + </View> |
| 93 | + <View style={styles.box}> |
| 94 | + <SegmentedControl |
| 95 | + containerMargin={16} |
| 96 | + segments={['Label 1', 'Label 2', 'Label 3', 'Label 4']} |
| 97 | + onChange={(index) => setTabIndex4(index)} |
| 98 | + currentIndex={tabIndex4} |
| 99 | + segmentedControlWrapper={{ backgroundColor: '#a3e635' }} |
| 100 | + activeTextStyle={styles.customGreenColor} |
| 101 | + inactiveTextStyle={styles.customWhiteColor} |
| 102 | + /> |
| 103 | + </View> |
| 104 | + <View style={styles.box}> |
| 105 | + <SegmentedControl |
| 106 | + containerMargin={16} |
| 107 | + segments={['Label 1', 'Label 2', 'Label 3']} |
| 108 | + onChange={(index) => setTabIndex5(index)} |
| 109 | + currentIndex={tabIndex5} |
| 110 | + segmentedControlWrapper={{ backgroundColor: '#7dd3fc' }} |
| 111 | + activeTextStyle={styles.customBlueTextColor} |
| 112 | + inactiveTextStyle={styles.customWhiteColor} |
| 113 | + tileStyle={styles.customBlueColor} |
| 114 | + badgeCount={[2]} |
| 115 | + /> |
| 116 | + </View> |
| 117 | + <View style={styles.box}> |
| 118 | + <SegmentedControl |
| 119 | + containerMargin={16} |
| 120 | + segments={['Label 1', 'Label 2', 'Label 3']} |
| 121 | + onChange={(index) => setTabIndex6(index)} |
| 122 | + currentIndex={tabIndex6} |
| 123 | + badgeCount={[2, null, 1]} |
| 124 | + /> |
| 125 | + </View> |
| 126 | + </View> |
| 127 | + ); |
| 128 | +} |
| 129 | + |
| 130 | +const styles = StyleSheet.create({ |
| 131 | + container: { |
| 132 | + flex: 1, |
| 133 | + justifyContent: 'center', |
| 134 | + }, |
| 135 | + box: { |
| 136 | + marginHorizontal: 16, |
| 137 | + marginVertical: 16, |
| 138 | + }, |
| 139 | + customBlackColor: { |
| 140 | + color: 'black', |
| 141 | + }, |
| 142 | + customWhiteColor: { |
| 143 | + color: 'white', |
| 144 | + }, |
| 145 | + customGreenColor: { |
| 146 | + color: '#3f6212', |
| 147 | + }, |
| 148 | + customBlueColor: { |
| 149 | + backgroundColor: '#e0f2fe', |
| 150 | + }, |
| 151 | + customBlueTextColor: { |
| 152 | + color: '#0369a1', |
| 153 | + }, |
| 154 | +}); |
19 | 155 | ``` |
20 | 156 |
|
21 | | -## Contributing |
| 157 | +## :v: Contributing |
22 | 158 |
|
23 | 159 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. |
24 | 160 |
|
25 | | -## License |
| 161 | +## :man: Author |
| 162 | + |
| 163 | +[Karthik B](https://twitter.com/_iam_karthik) |
| 164 | + |
| 165 | +## :clipboard: License |
26 | 166 |
|
27 | 167 | MIT |
0 commit comments