@momo-kits/date-picker 0.161.2-beta.6 → 0.161.2-beta.8
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/WheelPicker.tsx +8 -13
- package/WheelPickerItem.tsx +29 -37
- package/package.json +1 -1
- package/types.ts +3 -3
package/WheelPicker.tsx
CHANGED
|
@@ -7,16 +7,13 @@ import React, {
|
|
|
7
7
|
useRef,
|
|
8
8
|
} from 'react';
|
|
9
9
|
import {
|
|
10
|
+
Animated,
|
|
10
11
|
FlatList,
|
|
11
12
|
ListRenderItemInfo,
|
|
12
13
|
NativeScrollEvent,
|
|
13
14
|
NativeSyntheticEvent,
|
|
14
15
|
View,
|
|
15
16
|
} from 'react-native';
|
|
16
|
-
import Animated, {
|
|
17
|
-
useAnimatedScrollHandler,
|
|
18
|
-
useSharedValue,
|
|
19
|
-
} from 'react-native-reanimated';
|
|
20
17
|
import styles from './styles';
|
|
21
18
|
import { ApplicationContext } from '@momo-kits/foundation';
|
|
22
19
|
import { WheelPickerProps } from './types';
|
|
@@ -33,16 +30,10 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
33
30
|
}) => {
|
|
34
31
|
const { theme } = useContext(ApplicationContext);
|
|
35
32
|
const flatListRef = useRef<any>(null);
|
|
36
|
-
const scrollAnimatedValue =
|
|
33
|
+
const scrollAnimatedValue = useRef(new Animated.Value(0)).current;
|
|
37
34
|
const canMomentum = useRef(false);
|
|
38
35
|
const initItemNum = 15;
|
|
39
36
|
|
|
40
|
-
const onScroll = useAnimatedScrollHandler({
|
|
41
|
-
onScroll: (event) => {
|
|
42
|
-
scrollAnimatedValue.value = event.contentOffset.y;
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
37
|
useEffect(() => {
|
|
47
38
|
debouncedScrollEnd();
|
|
48
39
|
return () => {
|
|
@@ -153,8 +144,12 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
153
144
|
getItemLayout={getItemLayout}
|
|
154
145
|
onScrollToIndexFailed={onScrollToIndexFailed}
|
|
155
146
|
onMomentumScrollBegin={onMomentumScrollBegin}
|
|
156
|
-
onScroll={
|
|
157
|
-
|
|
147
|
+
onScroll={Animated.event(
|
|
148
|
+
[{ nativeEvent: { contentOffset: { y: scrollAnimatedValue } } }],
|
|
149
|
+
{
|
|
150
|
+
useNativeDriver: true,
|
|
151
|
+
},
|
|
152
|
+
)}
|
|
158
153
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
159
154
|
ref={flatListRef}
|
|
160
155
|
showsVerticalScrollIndicator={false}
|
package/WheelPickerItem.tsx
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import React, { FC, memo, useContext } from 'react';
|
|
2
|
-
import Animated
|
|
3
|
-
Extrapolation,
|
|
4
|
-
interpolate,
|
|
5
|
-
useAnimatedStyle,
|
|
6
|
-
} from 'react-native-reanimated';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
7
3
|
import styles from './styles';
|
|
8
4
|
import { ApplicationContext, useScaleSize } from '@momo-kits/foundation';
|
|
9
5
|
import { WheelPickerItemProps } from './types';
|
|
@@ -17,47 +13,43 @@ const WheelPickerItem: FC<WheelPickerItemProps> = ({
|
|
|
17
13
|
const { theme } = useContext(ApplicationContext);
|
|
18
14
|
const scaledFontSize = useScaleSize(16);
|
|
19
15
|
const scaledLineHeight = useScaleSize(22);
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[0,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const scale = interpolate(
|
|
35
|
-
distance,
|
|
36
|
-
[0, 1, 2, 3, 4],
|
|
37
|
-
[0.87, 0.87, 1, 0.87, 0.87],
|
|
38
|
-
Extrapolation.CLAMP,
|
|
39
|
-
);
|
|
40
|
-
return { transform: [{ scale }] };
|
|
41
|
-
});
|
|
16
|
+
const position = Animated.divide(scrollAnimatedValue, itemSize);
|
|
17
|
+
const distance = Animated.subtract(index, position);
|
|
18
|
+
const opacity =
|
|
19
|
+
distance.interpolate({
|
|
20
|
+
inputRange: [0, 1, 2, 3, 4],
|
|
21
|
+
outputRange: [0.4, 0.8, 1, 0.8, 0.4],
|
|
22
|
+
extrapolate: 'clamp',
|
|
23
|
+
}) || 1;
|
|
24
|
+
const scale =
|
|
25
|
+
distance.interpolate({
|
|
26
|
+
inputRange: [0, 1, 2, 3, 4],
|
|
27
|
+
outputRange: [0.87, 0.87, 1, 0.87, 0.87],
|
|
28
|
+
extrapolate: 'clamp',
|
|
29
|
+
}) || 1;
|
|
42
30
|
|
|
43
31
|
return (
|
|
44
32
|
<Animated.View
|
|
45
33
|
style={[
|
|
46
34
|
styles.wheelItem,
|
|
47
|
-
{
|
|
48
|
-
|
|
35
|
+
{
|
|
36
|
+
opacity,
|
|
37
|
+
height: itemSize,
|
|
38
|
+
},
|
|
49
39
|
]}
|
|
50
40
|
>
|
|
51
41
|
<Animated.Text
|
|
52
42
|
allowFontScaling={false}
|
|
53
|
-
style={
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
style={{
|
|
44
|
+
fontFamily: `${theme.font}-Semibold`,
|
|
45
|
+
transform: [
|
|
46
|
+
{
|
|
47
|
+
scale,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
fontSize: scaledFontSize,
|
|
51
|
+
lineHeight: scaledLineHeight,
|
|
52
|
+
}}
|
|
61
53
|
>
|
|
62
54
|
{item}
|
|
63
55
|
</Animated.Text>
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {ViewStyle} from 'react-native';
|
|
2
|
-
import
|
|
1
|
+
import {Animated, ViewStyle} from 'react-native';
|
|
2
|
+
import AnimatedValue = Animated.AnimatedValue;
|
|
3
3
|
|
|
4
4
|
export type DateTimePickerProps = {
|
|
5
5
|
/**
|
|
@@ -97,6 +97,6 @@ export type WheelPickerProps = {
|
|
|
97
97
|
export type WheelPickerItemProps = {
|
|
98
98
|
item: number;
|
|
99
99
|
index: number;
|
|
100
|
-
scrollAnimatedValue:
|
|
100
|
+
scrollAnimatedValue: AnimatedValue;
|
|
101
101
|
itemSize: number;
|
|
102
102
|
};
|