@momo-kits/slider 0.80.4 → 0.80.8-beta.10
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/Label.tsx +26 -20
- package/hooks.tsx +5 -5
- package/index.tsx +5 -4
- package/package.json +1 -1
package/Label.tsx
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
forwardRef,
|
|
3
|
+
ForwardRefRenderFunction,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useState,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import {View, ViewProps} from 'react-native';
|
|
3
8
|
import {Shadow, Text} from '@momo-kits/foundation';
|
|
4
9
|
import styles from './styles';
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
11
|
+
export type LabelRef = {
|
|
12
|
+
setValue: (value: number) => void;
|
|
13
|
+
};
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
15
|
+
const Label: ForwardRefRenderFunction<LabelRef, ViewProps> = (props, ref) => {
|
|
16
|
+
const [value, _setValue] = useState(Number.NaN);
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
useImperativeHandle(ref, () => ({
|
|
19
|
+
setValue,
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const setValue = (newValue: number) => {
|
|
23
|
+
_setValue(newValue);
|
|
24
|
+
};
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
return (
|
|
27
|
+
<View {...props} style={[styles.label, Shadow.Light]}>
|
|
28
|
+
<Text typography={'label_s'}>{value}</Text>
|
|
29
|
+
</View>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
26
32
|
|
|
27
|
-
export default Label;
|
|
33
|
+
export default forwardRef(Label);
|
package/hooks.tsx
CHANGED
|
@@ -5,10 +5,10 @@ import React, {
|
|
|
5
5
|
useRef,
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
|
-
import {Animated, I18nManager} from 'react-native';
|
|
8
|
+
import {Animated, I18nManager, ViewStyle} from 'react-native';
|
|
9
9
|
import {clamp} from './helpers';
|
|
10
10
|
import styles from './styles';
|
|
11
|
-
import FollowerContainer from './Label';
|
|
11
|
+
import FollowerContainer, {LabelRef} from './Label';
|
|
12
12
|
import {Spacing} from '@momo-kits/foundation';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -112,7 +112,7 @@ export const useThumbFollower = (
|
|
|
112
112
|
) => {
|
|
113
113
|
const xRef = useRef(new Animated.Value(0));
|
|
114
114
|
const widthRef = useRef(0);
|
|
115
|
-
const contentContainerRef = useRef<
|
|
115
|
+
const contentContainerRef = useRef<LabelRef>(null);
|
|
116
116
|
|
|
117
117
|
const {current: x} = xRef;
|
|
118
118
|
|
|
@@ -188,8 +188,8 @@ export const useSelectedRail = (
|
|
|
188
188
|
const styles = useMemo(
|
|
189
189
|
() => ({
|
|
190
190
|
position: 'absolute',
|
|
191
|
-
left:
|
|
192
|
-
right:
|
|
191
|
+
left: left,
|
|
192
|
+
right: right,
|
|
193
193
|
}),
|
|
194
194
|
[left, right],
|
|
195
195
|
);
|
package/index.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
memo,
|
|
3
|
-
ReactNode,
|
|
4
3
|
useCallback,
|
|
5
4
|
useContext,
|
|
6
5
|
useEffect,
|
|
@@ -15,6 +14,7 @@ import {
|
|
|
15
14
|
PanResponderGestureState,
|
|
16
15
|
View,
|
|
17
16
|
ViewProps,
|
|
17
|
+
ViewStyle,
|
|
18
18
|
} from 'react-native';
|
|
19
19
|
|
|
20
20
|
import styles from './styles';
|
|
@@ -176,7 +176,7 @@ const Slider: React.FC<SliderProps> = ({
|
|
|
176
176
|
const lowPosition =
|
|
177
177
|
((low - min) / (max - min)) * (containerWidth - thumbWidth);
|
|
178
178
|
lowThumbX.setValue(lowPosition);
|
|
179
|
-
updateSelectedRail();
|
|
179
|
+
typeof updateSelectedRail === 'function' && updateSelectedRail();
|
|
180
180
|
onValueChanged?.(low, high, false);
|
|
181
181
|
}, [
|
|
182
182
|
disableRange,
|
|
@@ -341,9 +341,10 @@ const Slider: React.FC<SliderProps> = ({
|
|
|
341
341
|
onValueChanged?.(isLow ? value : low, isLow ? high : value, true);
|
|
342
342
|
(isLow ? setLow : setHigh)(value);
|
|
343
343
|
labelUpdate &&
|
|
344
|
+
typeof labelUpdate === 'function' &&
|
|
344
345
|
labelUpdate(gestureStateRef.current.lastPosition, value);
|
|
345
346
|
|
|
346
|
-
updateSelectedRail();
|
|
347
|
+
typeof updateSelectedRail === 'function' && updateSelectedRail();
|
|
347
348
|
};
|
|
348
349
|
handlePositionChange(downX);
|
|
349
350
|
pointerX.removeAllListeners();
|
|
@@ -414,7 +415,7 @@ const Slider: React.FC<SliderProps> = ({
|
|
|
414
415
|
<View onLayout={handleContainerLayout} style={styles.controlsContainer}>
|
|
415
416
|
<View style={railContainerStyles}>
|
|
416
417
|
{renderTrack(theme.colors.background.default)}
|
|
417
|
-
<Animated.View style={selectedRailStyle}>
|
|
418
|
+
<Animated.View style={selectedRailStyle as ViewStyle}>
|
|
418
419
|
{renderTrack(trackColor)}
|
|
419
420
|
</Animated.View>
|
|
420
421
|
</View>
|