Skip to content

Commit d2dd022

Browse files
committed
feat: selectedTabStyle is available with the 1.0.0 version
1 parent ce37d82 commit d2dd022

File tree

4 files changed

+3615
-583
lines changed

4 files changed

+3615
-583
lines changed

README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ import SegmentedControl from "react-native-segmented-control-2";
3636
## Fundamental Usage
3737

3838
```jsx
39-
<SegmentedControl
40-
tabs={["Label 1", "Label 2", "Label 3"]}
41-
onChange={(index: number) => console.log("Index: ", index)}
39+
<SegmentedControl
40+
tabs={["Label 1", "Label 2", "Label 3"]}
41+
onChange={(index: number) => console.log("Index: ", index)}
4242
/>
4343
```
4444

4545
## Customized Usage
4646

4747
```jsx
4848
<SegmentedControl
49-
style={{ marginTop: 32, backgroundColor: "#ffe0e0" }}
50-
activeTabColor="#ff2929"
51-
activeTextColor="#fff"
52-
tabs={["Label 1", "Label 2", "Label 3"]}
53-
onChange={(index: number) => console.log("Index: ", index)}
49+
style={{ marginTop: 32, backgroundColor: "#ffe0e0" }}
50+
activeTabColor="#ff2929"
51+
activeTextColor="#fff"
52+
tabs={["Label 1", "Label 2", "Label 3"]}
53+
onChange={(index: number) => console.log("Index: ", index)}
5454
/>
5555
```
5656

5757
### Any Component Usage
5858

59-
You can use the segmented control with any component.
60-
All you need to do is that put any component into the `tabs` props.
59+
You can use the segmented control with any component.
60+
All you need to do is that put any component into the `tabs` props.
6161
Please check out the `example` for its usage
6262

6363
## Example Project 😍
@@ -75,23 +75,23 @@ should work of the example project.
7575

7676
## Fundamentals
7777

78-
79-
| Property | Type | Default | Description |
80-
|----------|:--------:| :-------: |------------------------------------------------|
81-
| tabs | any[] | undefined | set the array for tabs |
82-
| onChange | function | undefined | set your own logic when the tab is pressed / changed |
78+
| Property | Type | Default | Description |
79+
| -------- | :------: | :-------: | ---------------------------------------------------- |
80+
| tabs | any[] | undefined | set the array for tabs |
81+
| onChange | function | undefined | set your own logic when the tab is pressed / changed |
8382

8483
## Customization (Optionals)
8584

86-
| Property | Type | Default | Description |
87-
|-----------------|:---------:|:-----------------:|---------------------------------------------------------|
88-
| style | ViewStyle | default | set or override the style object for the main container |
89-
| width | number | ScreenWidth * 0.9 | change the width of the main segmented control |
90-
| initialIndex | number | 0 | set the initial index |
91-
| activeTextColor | string | #000 | change the active tab's text color |
92-
| activeTabColor | string | #FFF | change the active tab's color |
93-
| tabStyle | ViewStyle | default | set or override the style object for the tab |
94-
| textStyle | TextStyle | default | set or override the style object for tab's text |
85+
| Property | Type | Default | Description |
86+
| ---------------- | :-------: | :----------------: | ------------------------------------------------------- |
87+
| style | ViewStyle | default | set or override the style object for the main container |
88+
| width | number | ScreenWidth \* 0.9 | change the width of the main segmented control |
89+
| initialIndex | number | 0 | set the initial index |
90+
| activeTextColor | string | #000 | change the active tab's text color |
91+
| activeTabColor | string | #FFF | change the active tab's color |
92+
| tabStyle | ViewStyle | default | set or override the style object for the tab |
93+
| selectedTabStyle | ViewStyle | default | set or override the style object for the selected tab |
94+
| textStyle | TextStyle | default | set or override the style object for tab's text |
9595

9696
## Future Plans
9797

@@ -100,7 +100,8 @@ should work of the example project.
100100

101101
## Credits
102102

103-
Heavily inspired by these libraries:
103+
Heavily inspired by these libraries:
104+
104105
- [react-native-segmented-control/segmented-control](https://github.com/react-native-segmented-control/segmented-control)
105106
- [Karthik-B-06/react-native-segmented-control](https://github.com/Karthik-B-06/react-native-segmented-control)
106107

lib/SegmentedControl.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ export type CustomStyleProp =
2525
type CustomTextStyleProp = StyleProp<TextStyle> | Array<StyleProp<TextStyle>>;
2626

2727
interface SegmentedControlProps {
28-
style?: CustomStyleProp;
2928
tabs: any[];
3029
width?: number;
3130
initialIndex?: number;
3231
activeTextColor?: string;
3332
activeTabColor?: string;
33+
style?: CustomStyleProp;
3434
tabStyle?: CustomStyleProp;
3535
textStyle?: CustomTextStyleProp;
36+
selectedTabStyle?: CustomStyleProp;
3637
onChange: (index: number) => void;
3738
}
3839

@@ -41,9 +42,10 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
4142
tabs,
4243
width,
4344
onChange,
44-
initialIndex = 0,
4545
tabStyle,
4646
textStyle,
47+
selectedTabStyle,
48+
initialIndex = 0,
4749
activeTextColor = "#000",
4850
activeTabColor = "#fff",
4951
}) => {
@@ -68,7 +70,10 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
6870

6971
const renderSelectedTab = () => (
7072
<Animated.View
71-
style={[_selectedTabStyle(tabs, activeTabColor, slideAnimation, width)]}
73+
style={[
74+
_selectedTabStyle(tabs, activeTabColor, slideAnimation, width),
75+
selectedTabStyle,
76+
]}
7277
/>
7378
);
7479

0 commit comments

Comments
 (0)