@momo-kits/date-picker 0.159.1-beta.4 → 0.160.1-beta.7

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