@react-native-segmented-control/segmented-control 2.5.7 → 2.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/RNCSegmentedControlNativeComponent.js +4 -5
- package/js/SegmentedControl.ios.js +16 -14
- package/js/SegmentedControl.js +11 -3
- package/js/SegmentedControlTab.js +6 -5
- package/js/SegmentsSeparators.js +2 -2
- package/js/types.js +20 -13
- package/package.json +41 -30
|
@@ -9,11 +9,10 @@
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
11
|
import {requireNativeComponent} from 'react-native';
|
|
12
|
-
import type {HostComponent} from 'react-native
|
|
12
|
+
import type {HostComponent} from 'react-native';
|
|
13
13
|
import type {SegmentedControlProps} from './types';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const RNCSegmentedControlNativeComponent: HostComponent<SegmentedControlProps> =
|
|
16
|
+
requireNativeComponent<SegmentedControlProps>('RNCSegmentedControl');
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
'RNCSegmentedControl',
|
|
19
|
-
): any): NativeSegmentedControlIOS);
|
|
18
|
+
export default RNCSegmentedControlNativeComponent;
|
|
@@ -16,9 +16,11 @@ import {Image, StyleSheet, processColor} from 'react-native';
|
|
|
16
16
|
|
|
17
17
|
import RNCSegmentedControlNativeComponent from './RNCSegmentedControlNativeComponent';
|
|
18
18
|
|
|
19
|
-
type
|
|
19
|
+
type NativeRef = React.ElementRef<typeof RNCSegmentedControlNativeComponent>;
|
|
20
|
+
|
|
21
|
+
type Props = Readonly<{|
|
|
20
22
|
...SegmentedControlProps,
|
|
21
|
-
forwardedRef: ?React.
|
|
23
|
+
forwardedRef: ?React.RefSetter<NativeRef>,
|
|
22
24
|
|}>;
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -43,7 +45,10 @@ type Props = $ReadOnly<{|
|
|
|
43
45
|
*/
|
|
44
46
|
|
|
45
47
|
class SegmentedControlIOS extends React.Component<Props> {
|
|
46
|
-
static defaultProps
|
|
48
|
+
static defaultProps: {|
|
|
49
|
+
values: ReadonlyArray<string | number>,
|
|
50
|
+
enabled: boolean,
|
|
51
|
+
|} = {
|
|
47
52
|
values: [],
|
|
48
53
|
enabled: true,
|
|
49
54
|
};
|
|
@@ -54,7 +59,7 @@ class SegmentedControlIOS extends React.Component<Props> {
|
|
|
54
59
|
this.props.onValueChange(event.nativeEvent.value);
|
|
55
60
|
};
|
|
56
61
|
|
|
57
|
-
render() {
|
|
62
|
+
render(): React.Node {
|
|
58
63
|
const {forwardedRef, fontStyle, activeFontStyle, values, ...props} =
|
|
59
64
|
this.props;
|
|
60
65
|
return (
|
|
@@ -64,8 +69,7 @@ class SegmentedControlIOS extends React.Component<Props> {
|
|
|
64
69
|
? {
|
|
65
70
|
...fontStyle,
|
|
66
71
|
color: fontStyle.color
|
|
67
|
-
?
|
|
68
|
-
processColor(fontStyle.color)
|
|
72
|
+
? processColor(fontStyle.color)
|
|
69
73
|
: undefined,
|
|
70
74
|
}
|
|
71
75
|
: undefined
|
|
@@ -75,8 +79,7 @@ class SegmentedControlIOS extends React.Component<Props> {
|
|
|
75
79
|
? {
|
|
76
80
|
...activeFontStyle,
|
|
77
81
|
color: activeFontStyle.color
|
|
78
|
-
?
|
|
79
|
-
processColor(activeFontStyle.color)
|
|
82
|
+
? processColor(activeFontStyle.color)
|
|
80
83
|
: undefined,
|
|
81
84
|
}
|
|
82
85
|
: undefined
|
|
@@ -99,12 +102,11 @@ const styles = StyleSheet.create({
|
|
|
99
102
|
},
|
|
100
103
|
});
|
|
101
104
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
) => {
|
|
105
|
+
const SegmentedControlIOSWithRef: React.ComponentType<{
|
|
106
|
+
...SegmentedControlProps,
|
|
107
|
+
ref?: React.RefSetter<NativeRef>,
|
|
108
|
+
}> = React.forwardRef(
|
|
109
|
+
(props: SegmentedControlProps, forwardedRef: ?React.RefSetter<NativeRef>) => {
|
|
108
110
|
return <SegmentedControlIOS {...props} forwardedRef={forwardedRef} />;
|
|
109
111
|
},
|
|
110
112
|
);
|
package/js/SegmentedControl.js
CHANGED
|
@@ -44,9 +44,13 @@ const SegmentedControl = ({
|
|
|
44
44
|
const colorScheme = appearance || colorSchemeHook;
|
|
45
45
|
const [segmentWidth, setSegmentWidth] = React.useState(0);
|
|
46
46
|
const animation = React.useRef(new Animated.Value(0)).current;
|
|
47
|
-
const ref = React.useRef();
|
|
47
|
+
const ref = React.useRef<?React.ElementRef<typeof View>>(null);
|
|
48
48
|
|
|
49
49
|
const handleChange = (index: number) => {
|
|
50
|
+
if (index === selectedIndex) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
// mocks iOS's nativeEvent
|
|
51
55
|
const event: any = {
|
|
52
56
|
nativeEvent: {
|
|
@@ -75,7 +79,7 @@ const SegmentedControl = ({
|
|
|
75
79
|
Animated.timing(animation, {
|
|
76
80
|
toValue: isRTL * (selectedIndex || 0),
|
|
77
81
|
duration: 300,
|
|
78
|
-
easing: Easing.out(Easing.quad),
|
|
82
|
+
easing: Easing.out(Easing.quad.bind(Easing)),
|
|
79
83
|
useNativeDriver: true,
|
|
80
84
|
}).start();
|
|
81
85
|
}
|
|
@@ -83,7 +87,11 @@ const SegmentedControl = ({
|
|
|
83
87
|
|
|
84
88
|
React.useEffect(() => {
|
|
85
89
|
if (ref.current) {
|
|
86
|
-
ref.current.measure((_x, _y, width) =>
|
|
90
|
+
ref.current.measure((_x: number, _y: number, width?: number) => {
|
|
91
|
+
if (width !== undefined) {
|
|
92
|
+
updateSegmentWidth(width);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
87
95
|
}
|
|
88
96
|
}, [values, updateSegmentWidth]);
|
|
89
97
|
|
|
@@ -16,9 +16,10 @@ import {
|
|
|
16
16
|
Platform,
|
|
17
17
|
} from 'react-native';
|
|
18
18
|
|
|
19
|
+
import type {TextStyle} from 'react-native';
|
|
19
20
|
import type {FontStyle, ViewStyle} from './types';
|
|
20
21
|
|
|
21
|
-
type Props =
|
|
22
|
+
type Props = Readonly<{|
|
|
22
23
|
value: string | number | Object,
|
|
23
24
|
tintColor?: ?string,
|
|
24
25
|
onSelect: () => void,
|
|
@@ -32,10 +33,10 @@ type Props = $ReadOnly<{|
|
|
|
32
33
|
testID?: string,
|
|
33
34
|
|}>;
|
|
34
35
|
|
|
35
|
-
function isBase64(str) {
|
|
36
|
+
function isBase64(str: unknown): boolean {
|
|
36
37
|
const regex =
|
|
37
38
|
/^data:image\/(?:gif|png|jpeg|bmp|webp)(?:;charset=utf-8)?;base64,(?:[A-Za-z0-9]|[+/])+={0,2}/;
|
|
38
|
-
return str && regex.test(str);
|
|
39
|
+
return typeof str === 'string' && regex.test(str);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
export const SegmentedControlTab = ({
|
|
@@ -73,7 +74,7 @@ export const SegmentedControlTab = ({
|
|
|
73
74
|
};
|
|
74
75
|
const color = getColor();
|
|
75
76
|
|
|
76
|
-
const activeStyle = {
|
|
77
|
+
const activeStyle: TextStyle = {
|
|
77
78
|
...styles.activeText,
|
|
78
79
|
fontFamily: activeFontFamily || fontFamily,
|
|
79
80
|
fontSize: activeFontSize || fontSize,
|
|
@@ -81,7 +82,7 @@ export const SegmentedControlTab = ({
|
|
|
81
82
|
fontWeight: activeFontWeight || fontWeight || styles.activeText.fontWeight,
|
|
82
83
|
};
|
|
83
84
|
|
|
84
|
-
const idleStyle = {
|
|
85
|
+
const idleStyle: TextStyle = {
|
|
85
86
|
color,
|
|
86
87
|
fontSize: fontSize,
|
|
87
88
|
fontFamily: fontFamily,
|
package/js/SegmentsSeparators.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as React from 'react';
|
|
|
8
8
|
|
|
9
9
|
import {StyleSheet, View, useColorScheme} from 'react-native';
|
|
10
10
|
|
|
11
|
-
type Props =
|
|
11
|
+
type Props = Readonly<{|
|
|
12
12
|
values: number,
|
|
13
13
|
selectedIndex: ?number,
|
|
14
14
|
|}>;
|
|
@@ -18,7 +18,7 @@ export const SegmentsSeparators = ({
|
|
|
18
18
|
selectedIndex,
|
|
19
19
|
}: Props): React.Node => {
|
|
20
20
|
const colorScheme = useColorScheme();
|
|
21
|
-
const hide = (val) => {
|
|
21
|
+
const hide = (val: number) => {
|
|
22
22
|
return selectedIndex === val || selectedIndex === val + 1;
|
|
23
23
|
};
|
|
24
24
|
|
package/js/types.js
CHANGED
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
* @flow
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import type {
|
|
6
|
+
ColorValue,
|
|
7
|
+
NativeSyntheticEvent,
|
|
8
|
+
StyleProp,
|
|
9
|
+
ViewProps,
|
|
10
|
+
ViewStyle as RNViewStyle,
|
|
11
|
+
} from 'react-native';
|
|
9
12
|
|
|
10
|
-
export type Event =
|
|
11
|
-
|
|
13
|
+
export type Event = NativeSyntheticEvent<
|
|
14
|
+
Readonly<{|
|
|
12
15
|
value: string,
|
|
13
16
|
selectedSegmentIndex: number,
|
|
14
17
|
|}>,
|
|
15
18
|
>;
|
|
16
19
|
|
|
17
|
-
export type ViewStyle =
|
|
20
|
+
export type ViewStyle = StyleProp<RNViewStyle>;
|
|
18
21
|
|
|
19
|
-
export type FontStyle =
|
|
22
|
+
export type FontStyle = Readonly<{|
|
|
20
23
|
/**
|
|
21
24
|
* Font Color of Segmented Control
|
|
22
25
|
*/
|
|
@@ -46,12 +49,12 @@ export type FontStyle = $ReadOnly<{|
|
|
|
46
49
|
| '900',
|
|
47
50
|
|}>;
|
|
48
51
|
|
|
49
|
-
export type SegmentedControlProps =
|
|
52
|
+
export type SegmentedControlProps = Readonly<{|
|
|
50
53
|
...ViewProps,
|
|
51
54
|
/**
|
|
52
55
|
* The labels for the control's segment buttons, in order.
|
|
53
56
|
*/
|
|
54
|
-
values:
|
|
57
|
+
values: ReadonlyArray<string | number | Object>,
|
|
55
58
|
/**
|
|
56
59
|
* The index in `props.values` of the segment to be (pre)selected.
|
|
57
60
|
*/
|
|
@@ -60,12 +63,12 @@ export type SegmentedControlProps = $ReadOnly<{|
|
|
|
60
63
|
* Callback that is called when the user taps a segment;
|
|
61
64
|
* passes the segment's value as an argument
|
|
62
65
|
*/
|
|
63
|
-
onValueChange?: ?(value: string | number | Object) =>
|
|
66
|
+
onValueChange?: ?(value: string | number | Object) => unknown,
|
|
64
67
|
/**
|
|
65
68
|
* Callback that is called when the user taps a segment;
|
|
66
69
|
* passes the event as an argument
|
|
67
70
|
*/
|
|
68
|
-
onChange?: ?(event: Event) =>
|
|
71
|
+
onChange?: ?(event: Event) => unknown,
|
|
69
72
|
/**
|
|
70
73
|
* If false the user won't be able to interact with the control.
|
|
71
74
|
* Default value is true.
|
|
@@ -111,9 +114,13 @@ export type SegmentedControlProps = $ReadOnly<{|
|
|
|
111
114
|
/**
|
|
112
115
|
* array testID to each segment button
|
|
113
116
|
*/
|
|
114
|
-
testIDS:
|
|
117
|
+
testIDS: ReadonlyArray<string>,
|
|
115
118
|
/**
|
|
116
119
|
* Style properties for the slider component (Animated.View)
|
|
117
120
|
*/
|
|
118
121
|
sliderStyle?: ViewStyle,
|
|
122
|
+
/**
|
|
123
|
+
* Accessibility hint separator text
|
|
124
|
+
*/
|
|
125
|
+
accessibilityHintSeperator?: string,
|
|
119
126
|
|}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-segmented-control/segmented-control",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.9",
|
|
4
4
|
"description": "React Native SegmentedControlIOS library",
|
|
5
5
|
"main": "js/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,57 +8,68 @@
|
|
|
8
8
|
"index.d.ts",
|
|
9
9
|
"ios",
|
|
10
10
|
"js",
|
|
11
|
+
"!js/__tests__",
|
|
11
12
|
"react-native-segmented-control.podspec"
|
|
12
13
|
],
|
|
13
14
|
"scripts": {
|
|
14
15
|
"start": "react-native start",
|
|
15
16
|
"test": "pnpm flow && pnpm lint",
|
|
16
17
|
"ios": "cd example && react-native run-ios",
|
|
17
|
-
"web": "expo web",
|
|
18
18
|
"android": "react-native run-android",
|
|
19
|
+
"web": "pnpm --filter SegmentedControlExampleWeb start",
|
|
19
20
|
"flow": "flow",
|
|
20
21
|
"lint": "eslint . --cache",
|
|
21
22
|
"tsc": "tsc --noEmit",
|
|
22
|
-
"
|
|
23
|
+
"release": "release-it"
|
|
23
24
|
},
|
|
24
25
|
"peerDependencies": {
|
|
25
26
|
"react": ">=16.0",
|
|
26
27
|
"react-native": ">=0.62"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@babel/core": "^7.
|
|
30
|
-
"@babel/
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
30
|
+
"@babel/core": "^7.29.13",
|
|
31
|
+
"@babel/preset-env": "^7.29.0",
|
|
32
|
+
"@babel/preset-flow": "^7.27.0",
|
|
33
|
+
"@babel/preset-react": "^7.27.0",
|
|
34
|
+
"@babel/runtime": "^7.29.14",
|
|
35
|
+
"@react-native/babel-preset": "0.88.1",
|
|
36
|
+
"@react-native/eslint-config": "0.88.1",
|
|
37
|
+
"@react-native/jest-preset": "0.88.1",
|
|
38
|
+
"@release-it/conventional-changelog": "^12.0.2",
|
|
39
|
+
"@types/react": "^19.3.0",
|
|
40
|
+
"babel-jest": "^30.2.0",
|
|
39
41
|
"eslint": "8",
|
|
40
|
-
"
|
|
42
|
+
"flow-bin": "^0.331.0",
|
|
43
|
+
"husky": "^9.1.7",
|
|
44
|
+
"jest": "^30.5.2",
|
|
41
45
|
"prettier": "^3.0.0",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"metro-react-native-babel-preset": "0.77.0",
|
|
47
|
-
"react": "17.0.2",
|
|
48
|
-
"react-dom": "17.0.2",
|
|
49
|
-
"react-native": "0.63.4",
|
|
50
|
-
"react-native-test-app": "1.4.6",
|
|
51
|
-
"react-native-web": "^0.14.10",
|
|
52
|
-
"react-test-renderer": "17.0.2",
|
|
46
|
+
"react": "19.3.0",
|
|
47
|
+
"react-native": "0.88.1",
|
|
48
|
+
"react-test-renderer": "19.3.0",
|
|
49
|
+
"release-it": "^21.1.2",
|
|
53
50
|
"rimraf": "^3.0.2",
|
|
54
|
-
"
|
|
55
|
-
"typescript": "^4"
|
|
51
|
+
"typescript": "^5.9.2"
|
|
56
52
|
},
|
|
57
|
-
"
|
|
58
|
-
"
|
|
53
|
+
"release-it": {
|
|
54
|
+
"git": {
|
|
55
|
+
"commitMessage": "chore: release ${version}",
|
|
56
|
+
"tagName": "v${version}"
|
|
57
|
+
},
|
|
58
|
+
"npm": {
|
|
59
|
+
"publish": true,
|
|
60
|
+
"skipChecks": true
|
|
61
|
+
},
|
|
62
|
+
"github": {
|
|
63
|
+
"release": true
|
|
64
|
+
},
|
|
65
|
+
"plugins": {
|
|
66
|
+
"@release-it/conventional-changelog": {
|
|
67
|
+
"preset": "conventionalcommits"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
59
70
|
},
|
|
60
71
|
"jest": {
|
|
61
|
-
"preset": "react-native",
|
|
72
|
+
"preset": "@react-native/jest-preset",
|
|
62
73
|
"setupFilesAfterEnv": [
|
|
63
74
|
"<rootDir>/jest.setup.js"
|
|
64
75
|
]
|