@fountain-ui/lab 3.0.0-alpha.20 → 3.0.0-alpha.22

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.
Files changed (42) hide show
  1. package/build/commonjs/AnimatedY/AnimatedY.js +1 -1
  2. package/build/commonjs/AnimatedY/AnimatedY.js.map +1 -1
  3. package/build/commonjs/BottomSheet/BottomSheetNative.js +1 -1
  4. package/build/commonjs/BottomSheet/BottomSheetNative.js.map +1 -1
  5. package/build/commonjs/BottomSheet/BottomSheetWeb.js +1 -1
  6. package/build/commonjs/BottomSheet/BottomSheetWeb.js.map +1 -1
  7. package/build/commonjs/Carousel/components/ScrollViewGesture.js +22 -45
  8. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -1
  9. package/build/commonjs/ComicViewer/FastScroll.js +1 -1
  10. package/build/commonjs/ComicViewer/FastScroll.js.map +1 -1
  11. package/build/commonjs/FlipCard/FlipCard.js +2 -2
  12. package/build/commonjs/FlipCard/FlipCard.js.map +1 -1
  13. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +1 -5
  14. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  15. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js +1 -1
  16. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  17. package/build/module/AnimatedY/AnimatedY.js +1 -1
  18. package/build/module/AnimatedY/AnimatedY.js.map +1 -1
  19. package/build/module/BottomSheet/BottomSheetNative.js +1 -1
  20. package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
  21. package/build/module/BottomSheet/BottomSheetWeb.js +1 -1
  22. package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
  23. package/build/module/Carousel/components/ScrollViewGesture.js +20 -41
  24. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -1
  25. package/build/module/ComicViewer/FastScroll.js +1 -1
  26. package/build/module/ComicViewer/FastScroll.js.map +1 -1
  27. package/build/module/FlipCard/FlipCard.js +2 -2
  28. package/build/module/FlipCard/FlipCard.js.map +1 -1
  29. package/build/module/hooks/useUnstableCollapsibleAppBar.js +1 -5
  30. package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  31. package/build/module/hooks/useUnstableToggleDisplayStyle.js +1 -1
  32. package/build/module/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  33. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +1 -1
  34. package/package.json +3 -3
  35. package/src/AnimatedY/AnimatedY.tsx +1 -1
  36. package/src/BottomSheet/BottomSheetNative.tsx +1 -1
  37. package/src/BottomSheet/BottomSheetWeb.tsx +1 -1
  38. package/src/Carousel/components/ScrollViewGesture.tsx +30 -41
  39. package/src/ComicViewer/FastScroll.tsx +1 -1
  40. package/src/FlipCard/FlipCard.tsx +2 -2
  41. package/src/hooks/useUnstableCollapsibleAppBar.ts +1 -5
  42. package/src/hooks/useUnstableToggleDisplayStyle.ts +1 -1
@@ -1,9 +1,7 @@
1
- import type { ReactNode } from 'react';
2
- import React, { useCallback } from 'react';
3
- import { Animated, Platform } from 'react-native';
4
- import type { PanGestureHandlerStateChangeEvent } from 'react-native-gesture-handler';
5
- import { PanGestureHandler, State as GestureHandlerState } from 'react-native-gesture-handler';
6
- import * as R from 'ramda';
1
+ import { ReactNode } from 'react';
2
+ import React from 'react';
3
+ import { Animated } from 'react-native';
4
+ import { GestureDetector, Gesture } from 'react-native-gesture-handler';
7
5
  import type { AutoplayController, PagingDirection, StartPagingAnimation } from '../types';
8
6
 
9
7
  export interface ScrollViewGestureProps {
@@ -19,13 +17,7 @@ const SCROLL_TO_ADJACENT_TX_THRESHOLD = 80;
19
17
  const SCROLL_TO_ADJACENT_VX_THRESHOLD = 1000;
20
18
 
21
19
  const ACTIVE_OFFSET_ABS_X = 5;
22
- const activeOffsetX: number[] = [-ACTIVE_OFFSET_ABS_X, ACTIVE_OFFSET_ABS_X];
23
-
24
- const endAnimationStates: Readonly<GestureHandlerState[]> = [
25
- GestureHandlerState.CANCELLED,
26
- GestureHandlerState.END,
27
- GestureHandlerState.FAILED,
28
- ];
20
+ const WEB_TOUCH_ACTION = 'pan-y';
29
21
 
30
22
  function shouldScrollToAdjacent(translationX: number, velocityX: number): boolean {
31
23
  const isSameDirection = translationX * velocityX > 0;
@@ -48,23 +40,20 @@ export default function ScrollViewGesture(props: ScrollViewGestureProps) {
48
40
 
49
41
  const { pause: pauseAutoplay, resume: resumeAutoplay } = autoplayController;
50
42
 
51
- const handleGestureBegin = useCallback(() => {
52
- pauseAutoplay();
53
-
54
- interruptAnimation();
55
- }, [interruptAnimation, pauseAutoplay]);
56
-
57
- const handleGestureEvent = useCallback(Animated.event(
58
- [{ nativeEvent: { translationX: gestureTranslationX } }],
59
- { useNativeDriver: R.not(Platform.OS === 'android' && Platform.Version === 31) },
60
- ), []);
61
-
62
- const handleHandlerStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {
63
- const { nativeEvent: { translationX, velocityX, state } } = event;
64
-
65
- if (endAnimationStates.includes(state)) {
66
- const direction: PagingDirection = shouldScrollToAdjacent(translationX, velocityX)
67
- ? (translationX < 0 ? 'next' : 'prev')
43
+ const panGesture = Gesture.Pan()
44
+ .runOnJS(true)
45
+ .activeOffsetX([-ACTIVE_OFFSET_ABS_X, ACTIVE_OFFSET_ABS_X])
46
+ .enabled(scrollEnabled)
47
+ .onBegin(() => {
48
+ pauseAutoplay();
49
+ interruptAnimation();
50
+ })
51
+ .onUpdate((event) => {
52
+ gestureTranslationX.setValue(event.translationX);
53
+ })
54
+ .onEnd((event) => {
55
+ const direction: PagingDirection = shouldScrollToAdjacent(event.translationX, event.velocityX)
56
+ ? (event.translationX < 0 ? 'next' : 'prev')
68
57
  : 'stay';
69
58
 
70
59
  startPagingAnimation(
@@ -72,22 +61,22 @@ export default function ScrollViewGesture(props: ScrollViewGestureProps) {
72
61
  {
73
62
  direction: direction,
74
63
  isOriginatedFromGesture: true,
75
- lastGestureTranslationX: translationX,
64
+ lastGestureTranslationX: event.translationX,
76
65
  },
77
66
  );
78
67
 
79
68
  resumeAutoplay();
80
- }
81
- }, [startPagingAnimation, resumeAutoplay]);
69
+ })
70
+ .onFinalize(() => {
71
+ resumeAutoplay();
72
+ });
82
73
 
83
74
  return (
84
- <PanGestureHandler
85
- activeOffsetX={activeOffsetX}
86
- children={children}
87
- enabled={scrollEnabled}
88
- onBegan={handleGestureBegin}
89
- onGestureEvent={handleGestureEvent}
90
- onHandlerStateChange={handleHandlerStateChange}
91
- />
75
+ <GestureDetector
76
+ touchAction={WEB_TOUCH_ACTION}
77
+ gesture={panGesture}
78
+ >
79
+ {children}
80
+ </GestureDetector>
92
81
  );
93
82
  }
@@ -55,7 +55,7 @@ const FastScroll = React.forwardRef((props: FastScrollProps, ref) => {
55
55
  const animatedStyle = useAnimatedStyle(() => ({
56
56
  transform: [{ translateY: indicatorOffset.value }],
57
57
  opacity: indicatorOpacity.value,
58
- }));
58
+ }), [indicatorOffset, indicatorOpacity]);
59
59
 
60
60
  const position = {
61
61
  ...absolutePosition,
@@ -37,7 +37,7 @@ export default function FlipCard(props: FlipCardProps) {
37
37
  { rotateX: `${sharedAngle.value}deg` },
38
38
  ],
39
39
  };
40
- }, []);
40
+ }, [sharedAngle]);
41
41
 
42
42
  const animatedBackCardStyle = useAnimatedStyle(() => {
43
43
  return {
@@ -47,7 +47,7 @@ export default function FlipCard(props: FlipCardProps) {
47
47
  { rotateX: `${(sharedAngle.value + 180)}deg` },
48
48
  ],
49
49
  };
50
- }, []);
50
+ }, [sharedAngle]);
51
51
 
52
52
  useEffect(() => {
53
53
  sharedAngle.value = 0;
@@ -108,11 +108,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
108
108
  };
109
109
  }
110
110
  return {};
111
- }, [
112
- /**
113
- * FIXME: Consider add `elevationStyle` to dependencies.
114
- */
115
- ]);
111
+ }, [translateY, overlapped, elevationStyle]);
116
112
 
117
113
  const indexRef = useRef<number>(0);
118
114
  const offsetsRef = useRef<Array<number>>([]);
@@ -22,5 +22,5 @@ export default function useAnimatedDisplayStyle(
22
22
 
23
23
  return useAnimatedStyle(() => ({
24
24
  display: display.value,
25
- }), []);
25
+ }), [display]);
26
26
  };