@fountain-ui/lab 1.21.1 → 2.0.0-beta.11

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 (191) hide show
  1. package/build/commonjs/AnimatedY/AnimatedY.js +10 -14
  2. package/build/commonjs/AnimatedY/AnimatedY.js.map +1 -1
  3. package/build/commonjs/AnimatedY/AnimatedYProps.js.map +1 -1
  4. package/build/commonjs/AnimatedY/index.js.map +1 -1
  5. package/build/commonjs/BottomSheet/BottomSheetNative.js +8 -2
  6. package/build/commonjs/BottomSheet/BottomSheetNative.js.map +1 -1
  7. package/build/commonjs/BottomSheet/BottomSheetProps.js.map +1 -1
  8. package/build/commonjs/BottomSheet/BottomSheetWeb.js +2 -6
  9. package/build/commonjs/BottomSheet/BottomSheetWeb.js.map +1 -1
  10. package/build/commonjs/BottomSheet/TransparentBackdrop.js +1 -1
  11. package/build/commonjs/BottomSheet/TransparentBackdrop.js.map +1 -1
  12. package/build/commonjs/BottomSheet/index.js.map +1 -1
  13. package/build/commonjs/BottomSheet/index.native.js.map +1 -1
  14. package/build/commonjs/Carousel/CarouselNative.js.map +1 -1
  15. package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
  16. package/build/commonjs/Carousel/CarouselWeb.js +1 -1
  17. package/build/commonjs/Carousel/CarouselWeb.js.map +1 -1
  18. package/build/commonjs/Carousel/index.js.map +1 -1
  19. package/build/commonjs/Carousel/index.native.js.map +1 -1
  20. package/build/commonjs/Carousel/utils.js +1 -1
  21. package/build/commonjs/Carousel/utils.js.map +1 -1
  22. package/build/commonjs/ComicViewer/ComicViewer.js +168 -0
  23. package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -0
  24. package/build/commonjs/ComicViewer/ComicViewerItemProps.js +6 -0
  25. package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +1 -0
  26. package/build/commonjs/ComicViewer/ComicViewerProps.js +2 -0
  27. package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -0
  28. package/build/commonjs/ComicViewer/ViewerItem.js +88 -0
  29. package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -0
  30. package/build/commonjs/ComicViewer/index.js +16 -0
  31. package/build/commonjs/ComicViewer/index.js.map +1 -0
  32. package/build/commonjs/DateTimePicker/DateTimePicker.js +7 -1
  33. package/build/commonjs/DateTimePicker/DateTimePicker.js.map +1 -1
  34. package/build/commonjs/DateTimePicker/DateTimePickerProps.js.map +1 -1
  35. package/build/commonjs/DateTimePicker/DateTimePickerProvider.js.map +1 -1
  36. package/build/commonjs/DateTimePicker/YearPicker.js +22 -17
  37. package/build/commonjs/DateTimePicker/YearPicker.js.map +1 -1
  38. package/build/commonjs/DateTimePicker/index.js +4 -4
  39. package/build/commonjs/DateTimePicker/index.js.map +1 -1
  40. package/build/commonjs/DateTimePicker/utils.js +2 -1
  41. package/build/commonjs/DateTimePicker/utils.js.map +1 -1
  42. package/build/commonjs/FlipCard/FlipCard.js +7 -13
  43. package/build/commonjs/FlipCard/FlipCard.js.map +1 -1
  44. package/build/commonjs/FlipCard/FlipCardProps.js.map +1 -1
  45. package/build/commonjs/FlipCard/index.js.map +1 -1
  46. package/build/commonjs/StatusBarProvider/Provider.js +1 -1
  47. package/build/commonjs/StatusBarProvider/Provider.js.map +1 -1
  48. package/build/commonjs/StatusBarProvider/StatusBarProvider.js.map +1 -1
  49. package/build/commonjs/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
  50. package/build/commonjs/StatusBarProvider/index.js.map +1 -1
  51. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +90 -22
  52. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  53. package/build/commonjs/ViewPager/ViewPagerNative.js +46 -36
  54. package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
  55. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  56. package/build/commonjs/ViewPager/ViewPagerWeb.js +32 -25
  57. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
  58. package/build/commonjs/ViewPager/index.js.map +1 -1
  59. package/build/commonjs/ViewPager/index.native.js.map +1 -1
  60. package/build/commonjs/ViewPager/utils.js +3 -39
  61. package/build/commonjs/ViewPager/utils.js.map +1 -1
  62. package/build/commonjs/hooks/index.js.map +1 -1
  63. package/build/commonjs/hooks/useAppbarStyles.js.map +1 -1
  64. package/build/commonjs/hooks/useElevationStyle.js.map +1 -1
  65. package/build/commonjs/hooks/useHeight.js +5 -4
  66. package/build/commonjs/hooks/useHeight.js.map +1 -1
  67. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +56 -57
  68. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  69. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js +9 -11
  70. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  71. package/build/commonjs/index.js +25 -4
  72. package/build/commonjs/index.js.map +1 -1
  73. package/build/module/AnimatedY/AnimatedY.js +11 -10
  74. package/build/module/AnimatedY/AnimatedY.js.map +1 -1
  75. package/build/module/AnimatedY/AnimatedYProps.js.map +1 -1
  76. package/build/module/AnimatedY/index.js.map +1 -1
  77. package/build/module/BottomSheet/BottomSheetNative.js +8 -2
  78. package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
  79. package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
  80. package/build/module/BottomSheet/BottomSheetWeb.js +2 -6
  81. package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
  82. package/build/module/BottomSheet/TransparentBackdrop.js +1 -1
  83. package/build/module/BottomSheet/TransparentBackdrop.js.map +1 -1
  84. package/build/module/BottomSheet/index.js.map +1 -1
  85. package/build/module/BottomSheet/index.native.js.map +1 -1
  86. package/build/module/Carousel/CarouselNative.js.map +1 -1
  87. package/build/module/Carousel/CarouselProps.js.map +1 -1
  88. package/build/module/Carousel/CarouselWeb.js +1 -1
  89. package/build/module/Carousel/CarouselWeb.js.map +1 -1
  90. package/build/module/Carousel/index.js.map +1 -1
  91. package/build/module/Carousel/index.native.js.map +1 -1
  92. package/build/module/Carousel/utils.js.map +1 -1
  93. package/build/module/ComicViewer/ComicViewer.js +151 -0
  94. package/build/module/ComicViewer/ComicViewer.js.map +1 -0
  95. package/build/module/ComicViewer/ComicViewerItemProps.js +2 -0
  96. package/build/module/ComicViewer/ComicViewerItemProps.js.map +1 -0
  97. package/build/module/ComicViewer/ComicViewerProps.js +2 -0
  98. package/build/module/ComicViewer/ComicViewerProps.js.map +1 -0
  99. package/build/module/ComicViewer/ViewerItem.js +72 -0
  100. package/build/module/ComicViewer/ViewerItem.js.map +1 -0
  101. package/build/module/ComicViewer/index.js +2 -0
  102. package/build/module/ComicViewer/index.js.map +1 -0
  103. package/build/module/DateTimePicker/DateTimePicker.js +7 -1
  104. package/build/module/DateTimePicker/DateTimePicker.js.map +1 -1
  105. package/build/module/DateTimePicker/DateTimePickerProps.js.map +1 -1
  106. package/build/module/DateTimePicker/DateTimePickerProvider.js.map +1 -1
  107. package/build/module/DateTimePicker/YearPicker.js +22 -17
  108. package/build/module/DateTimePicker/YearPicker.js.map +1 -1
  109. package/build/module/DateTimePicker/index.js.map +1 -1
  110. package/build/module/DateTimePicker/utils.js +2 -1
  111. package/build/module/DateTimePicker/utils.js.map +1 -1
  112. package/build/module/FlipCard/FlipCard.js +7 -7
  113. package/build/module/FlipCard/FlipCard.js.map +1 -1
  114. package/build/module/FlipCard/FlipCardProps.js.map +1 -1
  115. package/build/module/FlipCard/index.js.map +1 -1
  116. package/build/module/StatusBarProvider/Provider.js.map +1 -1
  117. package/build/module/StatusBarProvider/StatusBarProvider.js.map +1 -1
  118. package/build/module/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
  119. package/build/module/StatusBarProvider/index.js.map +1 -1
  120. package/build/module/ViewPager/ChildrenMemoizedPage.js +85 -23
  121. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  122. package/build/module/ViewPager/ViewPagerNative.js +43 -32
  123. package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
  124. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  125. package/build/module/ViewPager/ViewPagerWeb.js +26 -23
  126. package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
  127. package/build/module/ViewPager/index.js.map +1 -1
  128. package/build/module/ViewPager/index.native.js.map +1 -1
  129. package/build/module/ViewPager/utils.js +1 -31
  130. package/build/module/ViewPager/utils.js.map +1 -1
  131. package/build/module/hooks/index.js.map +1 -1
  132. package/build/module/hooks/useAppbarStyles.js.map +1 -1
  133. package/build/module/hooks/useElevationStyle.js.map +1 -1
  134. package/build/module/hooks/useHeight.js +4 -3
  135. package/build/module/hooks/useHeight.js.map +1 -1
  136. package/build/module/hooks/useUnstableCollapsibleAppBar.js +58 -43
  137. package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  138. package/build/module/hooks/useUnstableToggleDisplayStyle.js +9 -7
  139. package/build/module/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  140. package/build/module/index.js +2 -0
  141. package/build/module/index.js.map +1 -1
  142. package/build/typescript/AnimatedY/AnimatedY.d.ts +0 -1
  143. package/build/typescript/BottomSheet/BottomSheetNative.d.ts +0 -1
  144. package/build/typescript/BottomSheet/BottomSheetWeb.d.ts +0 -1
  145. package/build/typescript/BottomSheet/TransparentBackdrop.d.ts +0 -1
  146. package/build/typescript/Carousel/CarouselNative.d.ts +0 -1
  147. package/build/typescript/ComicViewer/ComicViewer.d.ts +2 -0
  148. package/build/typescript/ComicViewer/ComicViewerItemProps.d.ts +12 -0
  149. package/build/typescript/ComicViewer/ComicViewerProps.d.ts +76 -0
  150. package/build/typescript/ComicViewer/ViewerItem.d.ts +7 -0
  151. package/build/typescript/ComicViewer/index.d.ts +3 -0
  152. package/build/typescript/DateTimePicker/DateTimePicker.d.ts +0 -1
  153. package/build/typescript/DateTimePicker/YearPicker.d.ts +0 -1
  154. package/build/typescript/FlipCard/FlipCard.d.ts +0 -1
  155. package/build/typescript/StatusBarProvider/StatusBarProvider.d.ts +0 -1
  156. package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +2 -1
  157. package/build/typescript/ViewPager/ViewPagerNative.d.ts +4 -2
  158. package/build/typescript/ViewPager/ViewPagerProps.d.ts +20 -19
  159. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +4 -2
  160. package/build/typescript/ViewPager/index.d.ts +1 -1
  161. package/build/typescript/ViewPager/utils.d.ts +2 -19
  162. package/build/typescript/hooks/useUnstableCollapsibleAppBar.d.ts +2 -3
  163. package/build/typescript/hooks/useUnstableToggleDisplayStyle.d.ts +2 -2
  164. package/build/typescript/index.d.ts +2 -0
  165. package/package.json +13 -13
  166. package/src/AnimatedY/AnimatedY.tsx +13 -10
  167. package/src/BottomSheet/BottomSheetNative.tsx +6 -0
  168. package/src/ComicViewer/ComicViewer.tsx +162 -0
  169. package/src/ComicViewer/ComicViewerItemProps.ts +15 -0
  170. package/src/ComicViewer/ComicViewerProps.ts +90 -0
  171. package/src/ComicViewer/ViewerItem.tsx +76 -0
  172. package/src/ComicViewer/index.ts +3 -0
  173. package/src/DateTimePicker/DateTimePicker.tsx +6 -0
  174. package/src/DateTimePicker/YearPicker.tsx +2 -1
  175. package/src/FlipCard/FlipCard.tsx +8 -8
  176. package/src/ViewPager/ChildrenMemoizedPage.tsx +91 -22
  177. package/src/ViewPager/ViewPagerNative.tsx +47 -35
  178. package/src/ViewPager/ViewPagerProps.ts +20 -19
  179. package/src/ViewPager/ViewPagerWeb.tsx +34 -29
  180. package/src/ViewPager/index.ts +1 -1
  181. package/src/ViewPager/utils.tsx +2 -55
  182. package/src/hooks/useHeight.ts +2 -2
  183. package/src/hooks/useUnstableCollapsibleAppBar.ts +59 -42
  184. package/src/hooks/useUnstableToggleDisplayStyle.ts +8 -6
  185. package/src/index.ts +3 -0
  186. package/build/commonjs/hooks/useWidth.js +0 -29
  187. package/build/commonjs/hooks/useWidth.js.map +0 -1
  188. package/build/module/hooks/useWidth.js +0 -15
  189. package/build/module/hooks/useWidth.js.map +0 -1
  190. package/build/typescript/hooks/useWidth.d.ts +0 -2
  191. package/src/hooks/useWidth.ts +0 -17
@@ -1,12 +1,11 @@
1
- import React, { useRef } from 'react';
1
+ import { useRef } from 'react';
2
2
  import { Platform } from 'react-native';
3
- import Animated from 'react-native-reanimated';
3
+ import { useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated';
4
4
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
5
5
  import useAppbarStyles from './useAppbarStyles';
6
6
  import useElevationStyle from './useElevationStyle';
7
7
  import useHeight from './useHeight';
8
8
  const defaultOptions = {
9
- translucent: false,
10
9
  shouldTranslateYReset: false
11
10
  };
12
11
  const ANIMATION_DURATION_MILLIS = 100;
@@ -19,9 +18,9 @@ function useLargerValueOfLastTwoValues(value) {
19
18
  return Math.max(...refLatestTwoValues.current);
20
19
  }
21
20
 
22
- export default function useUnstableCollapsibleAppBar(userOptions = defaultOptions) {
21
+ export default function useUnstableCollapsibleAppBar() {
22
+ let userOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultOptions;
23
23
  const {
24
- translucent,
25
24
  shouldTranslateYReset
26
25
  } = { ...defaultOptions,
27
26
  ...userOptions
@@ -31,42 +30,58 @@ export default function useUnstableCollapsibleAppBar(userOptions = defaultOption
31
30
  const [appBarHeight, onAppBarLayout] = useHeight();
32
31
  const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);
33
32
  const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();
34
- const maxTranslateY = Animated.useDerivedValue(() => -collapsibleToolbarHeight);
35
- const translateY = Animated.useSharedValue(0);
36
- const lastTranslateY = Animated.useSharedValue(0);
37
- const lastOffsetY = Animated.useSharedValue(0);
38
- const prevOffsetY = Animated.useSharedValue(0);
39
- const overlapped = Animated.useSharedValue(false);
40
- const vectorY = Animated.useSharedValue(0);
33
+ const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);
34
+ const translateY = useSharedValue(0);
35
+ const lastTranslateY = useSharedValue(0);
36
+ const lastOffsetY = useSharedValue(0);
37
+ const prevOffsetY = useSharedValue(0);
38
+ const overlapped = useSharedValue(false);
39
+ const vectorY = useSharedValue(0);
41
40
  const elevationStyle = useElevationStyle(4);
42
- const animatedStyle = Animated.useAnimatedStyle(() => {
43
- return Platform.OS === 'web' ? {
44
- transform: [{
45
- translateY: translateY.value
46
- }],
47
- boxShadow: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.boxShadow : 0
48
- } : {
49
- transform: [{
50
- translateY: translateY.value
51
- }],
52
- elevation: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.elevation : 0,
53
- shadowColor: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowColor,
54
- shadowOffset: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowOffset,
55
- shadowRadius: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowRadius,
56
- shadowOpacity: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowOpacity : 0
57
- };
58
- });
59
- const indexRef = React.useRef(0);
60
- const offsetsRef = React.useRef([]);
41
+ const animatedStyle = useAnimatedStyle(() => {
42
+ const transform = [{
43
+ translateY: translateY.value
44
+ }];
61
45
 
62
- const onScrollViewChanged = nextIndex => {
63
- var _offsetsRef$current$n;
46
+ if (Platform.OS === 'web') {
47
+ return {
48
+ transform,
49
+ boxShadow: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.boxShadow : 0
50
+ };
51
+ }
52
+
53
+ if (Platform.OS === 'android') {
54
+ return {
55
+ transform,
56
+ elevation: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.elevation : 0
57
+ };
58
+ }
64
59
 
60
+ if (Platform.OS === 'ios') {
61
+ return {
62
+ transform,
63
+ shadowColor: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowColor,
64
+ shadowOffset: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowOffset,
65
+ shadowRadius: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowRadius,
66
+ shadowOpacity: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowOpacity : 0
67
+ };
68
+ }
69
+
70
+ return {};
71
+ }, [
72
+ /**
73
+ * FIXME: Consider add `elevationStyle` to dependencies.
74
+ */
75
+ ]);
76
+ const indexRef = useRef(0);
77
+ const offsetsRef = useRef([]);
78
+
79
+ const onScrollViewChanged = nextIndex => {
65
80
  const prevIndex = indexRef.current;
66
81
 
67
82
  if (prevIndex === nextIndex) {
68
83
  if (shouldTranslateYReset) {
69
- translateY.value = Animated.withTiming(0, {
84
+ translateY.value = withTiming(0, {
70
85
  duration: ANIMATION_DURATION_MILLIS
71
86
  });
72
87
  vectorY.value = 0;
@@ -78,21 +93,21 @@ export default function useUnstableCollapsibleAppBar(userOptions = defaultOption
78
93
  }
79
94
 
80
95
  offsetsRef.current[prevIndex] = lastOffsetY.value;
81
- const savedOffsetY = (_offsetsRef$current$n = offsetsRef.current[nextIndex]) !== null && _offsetsRef$current$n !== void 0 ? _offsetsRef$current$n : 0;
96
+ const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;
82
97
  lastOffsetY.value = savedOffsetY;
83
98
  indexRef.current = nextIndex; // Determine whether to overlap every time index is changed.
84
99
 
85
100
  overlapped.value = savedOffsetY > 0; // If next ScrollView's offset is too short, expand app bar.
86
101
 
87
102
  if (translateY.value < 0 && savedOffsetY < appBarHeight) {
88
- translateY.value = Animated.withTiming(0, {
103
+ translateY.value = withTiming(0, {
89
104
  duration: ANIMATION_DURATION_MILLIS
90
105
  });
91
106
  vectorY.value = 0;
92
107
  }
93
108
  };
94
109
 
95
- const scrollHandler = Animated.useAnimatedScrollHandler({
110
+ const scrollHandler = useAnimatedScrollHandler({
96
111
  onBeginDrag: () => {
97
112
  lastTranslateY.value = translateY.value;
98
113
  },
@@ -114,13 +129,13 @@ export default function useUnstableCollapsibleAppBar(userOptions = defaultOption
114
129
  } else {
115
130
  if (offsetY > -maxTy) {
116
131
  if (ty === 0) {
117
- translateY.value = Animated.withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {
132
+ translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {
118
133
  duration: ANIMATION_DURATION_MILLIS
119
134
  });
120
135
  }
121
136
  } else {
122
137
  if (ty === maxTy) {
123
- translateY.value = Animated.withTiming(0, {
138
+ translateY.value = withTiming(0, {
124
139
  duration: ANIMATION_DURATION_MILLIS
125
140
  });
126
141
  }
@@ -146,15 +161,15 @@ export default function useUnstableCollapsibleAppBar(userOptions = defaultOption
146
161
  const threshold = maxTy * 0.5;
147
162
  const nextTranslateY = ty > threshold || offsetY < appBarHeight ? 0 : maxTy;
148
163
  overlapped.value = offsetY + nextTranslateY > 0;
149
- translateY.value = Animated.withTiming(nextTranslateY, {
164
+ translateY.value = withTiming(nextTranslateY, {
150
165
  duration: ANIMATION_DURATION_MILLIS
151
166
  });
152
167
  }
153
- });
168
+ }, []);
154
169
  const hasCollapsible = collapsibleToolbarHeight > 0;
155
- const appBarStyle = [animatedStyle, translucent ? {
170
+ const appBarStyle = [animatedStyle, {
156
171
  paddingTop: safeAreaInsets.top
157
- } : undefined, hasCollapsible ? styles.floating : undefined];
172
+ }, hasCollapsible ? styles.floating : undefined];
158
173
  return {
159
174
  appBarStyle,
160
175
  vectorY,
@@ -1 +1 @@
1
- {"version":3,"sources":["useUnstableCollapsibleAppBar.ts"],"names":["React","useRef","Platform","Animated","useSafeAreaInsets","useAppbarStyles","useElevationStyle","useHeight","defaultOptions","translucent","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","safeAreaInsets","appBarHeight","onAppBarLayout","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","useDerivedValue","translateY","useSharedValue","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","animatedStyle","useAnimatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","withTiming","duration","savedOffsetY","scrollHandler","useAnimatedScrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","undefined","floating","scrollContentInsets"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,MAAhB,QAA8B,OAA9B;AACA,SAAgBC,QAAhB,QAAwF,cAAxF;AACA,OAAOC,QAAP,MAAqB,yBAArB;AACA,SAASC,iBAAT,QAAkC,gCAAlC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,SAAP,MAAsB,aAAtB;AAgCA,MAAMC,cAAiC,GAAG;AACtCC,EAAAA,WAAW,EAAE,KADyB;AAEtCC,EAAAA,qBAAqB,EAAE;AAFe,CAA1C;AAKA,MAAMC,yBAAyB,GAAG,GAAlC;AAEA,MAAMC,uBAAuB,GAAGV,QAAQ,CAACW,EAAT,KAAgB,KAAhD;;AAGA,SAASC,6BAAT,CAAuCC,KAAvC,EAAsD;AAClD,QAAMC,kBAAkB,GAAGf,MAAM,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,CAAjC;AAEAe,EAAAA,kBAAkB,CAACC,OAAnB,CAA2BC,KAA3B;AACAF,EAAAA,kBAAkB,CAACC,OAAnB,CAA2BE,IAA3B,CAAgCJ,KAAhC;AAEA,SAAOK,IAAI,CA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EAGhBJ,cAAc,GAAGpD,MAAM,CAACyD,QAAV,GAAqBD,SAHnB,CAApB;AAMA,SAAO;AACHH,IAAAA,WADG;AAEHtC,IAAAA,OAFG;AAGHZ,IAAAA,cAHG;AAIHG,IAAAA,0BAJG;AAKHgC,IAAAA,QAAQ,EAAEJ,aALP;AAMHN,IAAAA,mBANG;AAOH8B,IAAAA,mBAAmB,EAAE;AAAEH,MAAAA,GAAG,EAAEH,cAAc,GAAGhD,eAAH,GAAqB;AAA1C;AAPlB,GAAP;AASH;AAAA","sourcesContent":["import React, { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport Animated from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n translucent?: boolean;\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: Animated.SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n translucent: false,\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const {\n translucent,\n shouldTranslateYReset,\n }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = Animated.useDerivedValue(() => -collapsibleToolbarHeight);\n\n const translateY = Animated.useSharedValue<number>(0);\n const lastTranslateY = Animated.useSharedValue<number>(0);\n const lastOffsetY = Animated.useSharedValue<number>(0);\n const prevOffsetY = Animated.useSharedValue<number>(0);\n const overlapped = Animated.useSharedValue<boolean>(false);\n const vectorY = Animated.useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = Animated.useAnimatedStyle(() => {\n return Platform.OS === 'web' ? ({\n transform: [{ translateY: translateY.value }],\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n }) : ({\n transform: [{ translateY: translateY.value }],\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n });\n });\n\n const indexRef = React.useRef<number>(0);\n const offsetsRef = React.useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = Animated.withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = Animated.withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = Animated.useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = Animated.withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = Animated.withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = Animated.withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n });\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n translucent ? { paddingTop: safeAreaInsets.top } : undefined,\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarMaxHeight : 0 },\n };\n};\n"]}
1
+ {"version":3,"names":["useRef","Platform","useAnimatedScrollHandler","useAnimatedStyle","useDerivedValue","useSharedValue","withTiming","useSafeAreaInsets","useAppbarStyles","useElevationStyle","useHeight","defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","safeAreaInsets","appBarHeight","onAppBarLayout","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","translateY","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","animatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","duration","savedOffsetY","scrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useUnstableCollapsibleAppBar.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport {\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { shouldTranslateYReset }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const prevOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n const vectorY = useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n const transform = [{ translateY: translateY.value }];\n\n if (Platform.OS === 'web') {\n return {\n transform,\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform,\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n }, [\n /**\n * FIXME: Consider add `elevationStyle` to dependencies.\n */\n ]);\n\n const indexRef = useRef<number>(0);\n const offsetsRef = useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n }, []);\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarMaxHeight : 0 },\n };\n};\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,OAAvB;AACA,SAAgBC,QAAhB,QAAwF,cAAxF;AAEA,SACIC,wBADJ,EAEIC,gBAFJ,EAGIC,eAHJ,EAIIC,cAJJ,EAKIC,UALJ,QAMO,yBANP;AAOA,SAASC,iBAAT,QAAkC,gCAAlC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,SAAP,MAAsB,aAAtB;AA+BA,MAAMC,cAAiC,GAAG;EACtCC,qBAAqB,EAAE;AADe,CAA1C;AAIA,MAAMC,yBAAyB,GAAG,GAAlC;AAEA,MAAMC,uBAAuB,GAAGb,QAAQ,CAACc,EAAT,KAAgB,KAAhD;;AAEA,SAASC,6BAAT,CAAuCC,KAAvC,EAAsD;EAClD,MAAMC,kBAAkB,GAAGlB,MAAM,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,CAAjC;EAEAkB,kBAAkB,CAACC,OAAnB,CAA2BC,KAA3B;EACAF,kBAAkB,CAACC,OAAnB,CAA2BE,IAA3B,CAAgCJ,KAAhC;EAEA,OAAOK,IAAI,CAACC,GAAL,CAAS,GAAGL,kBAAkB,CAACC,OAA/B,CAAP;AACH;;AAED,eAAe,SAASK,4BAAT,GAAgG;EAAA,IAA1DC,WAA0D,uEAAnCd,cAAmC;EAC3G,MAAM;IAAEC;EAAF,IAA+C,EACjD,GAAGD,cAD8C;IAEjD,GAAGc;EAF8C,CAArD;EAKA,MAAMC,MAAM,GAAGlB,eAAe,EAA9B;EAEA,MAAMmB,cAAc,GAAGpB,iBAAiB,EAAxC;EAEA,MAAM,CAACqB,YAAD,EAAeC,cAAf,IAAiCnB,SAAS,EAAhD;EACA,MAAMoB,eAAe,GAAGd,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AAE,GAAGO,SAAL,IAAkBV,OAAO,GAAGjC,YAA7B,GAA6C,CAA7C,GAAiDqC,KAAxE;MAEA3B,UAAU,CAACrB,KAAX,GAAmB4C,OAAO,GAAGW,cAAV,GAA2B,CAA9C;MAEAtC,UAAU,CAACjB,KAAX,GAAmBX,UAAU,CAACkE,cAAD,EAAiB;QAC1ClB,QAAQ,EAAEzC;MADgC,CAAjB,CAA7B;IAGH;EApE0C,CAAD,EAqE3C,EArE2C,CAA9C;EAuEA,MAAM4D,cAAc,GAAG1C,wBAAwB,GAAG,CAAlD;EAEA,MAAM2C,WAAW,GAAG,CAChBjC,aADgB,EAEhB;IAAEkC,UAAU,EAAEhD,cAAc,CAACiD;EAA7B,CAFgB,EAGhBH,cAAc,GAAG/C,MAAM,CAACmD,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHnC,OAFG;IAGHV,cAHG;IAIHG,0BAJG;IAKH2B,QAAQ,EAAEH,aALP;IAMHL,mBANG;IAOH4B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAG3C,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;AAAA"}
@@ -1,16 +1,18 @@
1
- import Animated from 'react-native-reanimated';
2
- export default function useAnimatedDisplayStyle(vectorY, threshold = 200, defaultDisplay = 'flex') {
3
- const display = Animated.useSharedValue(defaultDisplay);
4
- Animated.useAnimatedReaction(() => vectorY.value, vy => {
1
+ import { useAnimatedReaction, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
2
+ export default function useAnimatedDisplayStyle(vectorY) {
3
+ let threshold = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
4
+ let defaultDisplay = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'flex';
5
+ const display = useSharedValue(defaultDisplay);
6
+ useAnimatedReaction(() => vectorY.value, vy => {
5
7
  if (vy >= threshold) {
6
8
  display.value = 'none';
7
9
  } else if (vy < threshold) {
8
10
  display.value = 'flex';
9
11
  }
10
- });
11
- return Animated.useAnimatedStyle(() => ({
12
+ }, [threshold]);
13
+ return useAnimatedStyle(() => ({
12
14
  display: display.value
13
- }));
15
+ }), []);
14
16
  }
15
17
  ;
16
18
  //# sourceMappingURL=useUnstableToggleDisplayStyle.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useUnstableToggleDisplayStyle.ts"],"names":["Animated","useAnimatedDisplayStyle","vectorY","threshold","defaultDisplay","display","useSharedValue","useAnimatedReaction","value","vy","useAnimatedStyle"],"mappings":"AAAA,OAAOA,QAAP,MAAqB,yBAArB;AAEA,eAAe,SAASC,uBAAT,CACXC,OADW,EAEXC,SAAiB,GAAG,GAFT,EAGXC,cAA+B,GAAG,MAHvB,EAIb;AACE,QAAMC,OAAO,GAAGL,QAAQ,CAACM,cAAT,CAAwBF,cAAxB,CAAhB;AAEAJ,EAAAA,QAAQ,CAACO,mBAAT,CACI,MAAML,OAAO,CAACM,KADlB,EAEKC,EAAD,IAAQ;AACJ,QAAIA,EAAE,IAAIN,SAAV,EAAqB;AACjBE,MAAAA,OAAO,CAACG,KAAR,GAAgB,MAAhB;AACH,KAFD,MAEO,IAAIC,EAAE,GAAGN,SAAT,EAAoB;AACvBE,MAAAA,OAAO,CAACG,KAAR,GAAgB,MAAhB;AACH;AACJ,GARL;AAWA,SAAOR,QAAQ,CAACU,gBAAT,CAA0B,OAAO;AACpCL,IAAAA,OAAO,EAAEA,OAAO,CAACG;AADmB,GAAP,CAA1B,CAAP;AAGH;AAAA","sourcesContent":["import Animated from 'react-native-reanimated';\n\nexport default function useAnimatedDisplayStyle(\n vectorY: Animated.SharedValue<number>,\n threshold: number = 200,\n defaultDisplay: 'flex' | 'none' = 'flex',\n) {\n const display = Animated.useSharedValue(defaultDisplay);\n\n Animated.useAnimatedReaction(\n () => vectorY.value,\n (vy) => {\n if (vy >= threshold) {\n display.value = 'none';\n } else if (vy < threshold) {\n display.value = 'flex';\n }\n },\n );\n\n return Animated.useAnimatedStyle(() => ({\n display: display.value,\n }));\n};\n"]}
1
+ {"version":3,"names":["useAnimatedReaction","useAnimatedStyle","useSharedValue","useAnimatedDisplayStyle","vectorY","threshold","defaultDisplay","display","value","vy"],"sources":["useUnstableToggleDisplayStyle.ts"],"sourcesContent":["import type { SharedValue } from 'react-native-reanimated';\nimport { useAnimatedReaction, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';\n\nexport default function useAnimatedDisplayStyle(\n vectorY: SharedValue<number>,\n threshold: number = 200,\n defaultDisplay: 'flex' | 'none' = 'flex',\n) {\n const display = useSharedValue(defaultDisplay);\n\n useAnimatedReaction(\n () => vectorY.value,\n (vy) => {\n if (vy >= threshold) {\n display.value = 'none';\n } else if (vy < threshold) {\n display.value = 'flex';\n }\n },\n [threshold],\n );\n\n return useAnimatedStyle(() => ({\n display: display.value,\n }), []);\n};\n"],"mappings":"AACA,SAASA,mBAAT,EAA8BC,gBAA9B,EAAgDC,cAAhD,QAAsE,yBAAtE;AAEA,eAAe,SAASC,uBAAT,CACXC,OADW,EAIb;EAAA,IAFEC,SAEF,uEAFsB,GAEtB;EAAA,IADEC,cACF,uEADoC,MACpC;EACE,MAAMC,OAAO,GAAGL,cAAc,CAACI,cAAD,CAA9B;EAEAN,mBAAmB,CACf,MAAMI,OAAO,CAACI,KADC,EAEdC,EAAD,IAAQ;IACJ,IAAIA,EAAE,IAAIJ,SAAV,EAAqB;MACjBE,OAAO,CAACC,KAAR,GAAgB,MAAhB;IACH,CAFD,MAEO,IAAIC,EAAE,GAAGJ,SAAT,EAAoB;MACvBE,OAAO,CAACC,KAAR,GAAgB,MAAhB;IACH;EACJ,CARc,EASf,CAACH,SAAD,CATe,CAAnB;EAYA,OAAOJ,gBAAgB,CAAC,OAAO;IAC3BM,OAAO,EAAEA,OAAO,CAACC;EADU,CAAP,CAAD,EAEnB,EAFmB,CAAvB;AAGH;AAAA"}
@@ -8,6 +8,8 @@ export { default as FlipCard } from './FlipCard';
8
8
  export * from './FlipCard';
9
9
  export { default as ViewPager } from './ViewPager';
10
10
  export * from './ViewPager';
11
+ export { default as ComicViewer } from './ComicViewer';
12
+ export * from './ComicViewer';
11
13
  export { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';
12
14
  export * from './StatusBarProvider';
13
15
  export * from './hooks';
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["default","BottomSheet","Carousel","DateTimePicker","FlipCard","ViewPager","StatusBarProvider","useStatusBarContext"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAApB,QAAuC,eAAvC;AACA,cAAc,eAAd;AAEA,SAASD,OAAO,IAAIE,QAApB,QAAoC,YAApC;AACA,cAAc,YAAd;AAEA,SAASF,OAAO,IAAIG,cAApB,QAA0C,kBAA1C;AACA,cAAc,kBAAd;AAEA,SAASH,OAAO,IAAII,QAApB,QAAoC,YAApC;AACA,cAAc,YAAd;AAEA,SAASJ,OAAO,IAAIK,SAApB,QAAqC,aAArC;AACA,cAAc,aAAd;AAEA,SAASL,OAAO,IAAIM,iBAApB,EAAuCC,mBAAvC,QAAkE,qBAAlE;AACA,cAAc,qBAAd;AAEA,cAAc,SAAd","sourcesContent":["export { default as BottomSheet } from './BottomSheet';\nexport * from './BottomSheet';\n\nexport { default as Carousel } from './Carousel';\nexport * from './Carousel';\n\nexport { default as DateTimePicker } from './DateTimePicker';\nexport * from './DateTimePicker';\n\nexport { default as FlipCard } from './FlipCard';\nexport * from './FlipCard';\n\nexport { default as ViewPager } from './ViewPager';\nexport * from './ViewPager';\n\nexport { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';\nexport * from './StatusBarProvider';\n\nexport * from './hooks';\n"]}
1
+ {"version":3,"names":["default","BottomSheet","Carousel","DateTimePicker","FlipCard","ViewPager","ComicViewer","StatusBarProvider","useStatusBarContext"],"sources":["index.ts"],"sourcesContent":["export { default as BottomSheet } from './BottomSheet';\nexport * from './BottomSheet';\n\nexport { default as Carousel } from './Carousel';\nexport * from './Carousel';\n\nexport { default as DateTimePicker } from './DateTimePicker';\nexport * from './DateTimePicker';\n\nexport { default as FlipCard } from './FlipCard';\nexport * from './FlipCard';\n\nexport { default as ViewPager } from './ViewPager';\nexport * from './ViewPager';\n\nexport { default as ComicViewer } from './ComicViewer';\nexport * from './ComicViewer';\n\nexport { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';\nexport * from './StatusBarProvider';\n\nexport * from './hooks';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAApB,QAAuC,eAAvC;AACA,cAAc,eAAd;AAEA,SAASD,OAAO,IAAIE,QAApB,QAAoC,YAApC;AACA,cAAc,YAAd;AAEA,SAASF,OAAO,IAAIG,cAApB,QAA0C,kBAA1C;AACA,cAAc,kBAAd;AAEA,SAASH,OAAO,IAAII,QAApB,QAAoC,YAApC;AACA,cAAc,YAAd;AAEA,SAASJ,OAAO,IAAIK,SAApB,QAAqC,aAArC;AACA,cAAc,aAAd;AAEA,SAASL,OAAO,IAAIM,WAApB,QAAuC,eAAvC;AACA,cAAc,eAAd;AAEA,SAASN,OAAO,IAAIO,iBAApB,EAAuCC,mBAAvC,QAAkE,qBAAlE;AACA,cAAc,qBAAd;AAEA,cAAc,SAAd"}
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import type AnimatedYProps from './AnimatedYProps';
3
2
  export default function AnimatedY(props: AnimatedYProps): JSX.Element;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import type BottomSheetProps from './BottomSheetProps';
3
2
  export default function BottomSheet(props: BottomSheetProps): JSX.Element;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import type BottomSheetProps from './BottomSheetProps';
3
2
  export default function BottomSheet(props: BottomSheetProps): JSX.Element;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import { BottomSheetBackdropProps } from '@gorhom/bottom-sheet';
3
2
  export default function TransparentBackdrop(props: BottomSheetBackdropProps): JSX.Element;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import type CarouselProps from './CarouselProps';
3
2
  export default function Carousel<ItemT>(props: CarouselProps<ItemT>): JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { default as ComicViewerProps } from './ComicViewerProps';
2
+ export default function ComicViewer<T>(props: ComicViewerProps<T>): JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { ComicViewerItemData, ErrorInfo } from './ComicViewerProps';
2
+ declare type ComicViewerItemProps<T> = ComicViewerItemData<T> & {
3
+ /**
4
+ * FlatListItem is viewable in screen.
5
+ */
6
+ isViewable: boolean;
7
+ /**
8
+ * Error handler
9
+ */
10
+ onError?: (errorInfo: ErrorInfo) => void;
11
+ };
12
+ export default ComicViewerItemProps;
@@ -0,0 +1,76 @@
1
+ import { ComponentProps } from '@fountain-ui/core';
2
+ export interface ErrorInfo {
3
+ /**
4
+ * ComicViewerItemData.id.
5
+ */
6
+ id: string;
7
+ /**
8
+ * Number of times an error occurred.
9
+ */
10
+ count: number;
11
+ }
12
+ export declare type ComicViewerItemData<T = {}> = T & {
13
+ /**
14
+ * Image height.
15
+ */
16
+ height: number;
17
+ /**
18
+ * Unique value for identifying.
19
+ */
20
+ id: string;
21
+ /**
22
+ * Image sourceUrl for displaying.
23
+ */
24
+ sourceUrl: string;
25
+ /**
26
+ * Image width.
27
+ */
28
+ width: number;
29
+ };
30
+ export default interface ComicViewerProps<T> extends ComponentProps<{
31
+ /**
32
+ * Data for render.
33
+ */
34
+ data: ComicViewerItemData<T>[];
35
+ /**
36
+ * Delay Time to call the error handler.
37
+ * @default 500
38
+ */
39
+ errorDebounceMillis?: number;
40
+ /**
41
+ * How many times retry onError when same item error occur
42
+ * @default 3
43
+ */
44
+ errorRetryCount?: number;
45
+ /**
46
+ * How many items to render in the initial batch.
47
+ * @default 1
48
+ */
49
+ initialNumToRender?: number;
50
+ /**
51
+ * Start at initialScrollPercentage.
52
+ * If over 100, scroll to end.
53
+ * @default 0
54
+ */
55
+ initialScrollPercentage?: number;
56
+ /**
57
+ * The value for FlatList viewabilityConfig.itemVisiblePercentThreshold.
58
+ * @default 0
59
+ */
60
+ itemVisiblePercentThreshold?: number;
61
+ /**
62
+ * Handling all viewerItem errors at once.
63
+ * @param errors Array of ViewerItems errorInfo.
64
+ */
65
+ onError?: (errors: ErrorInfo[]) => void;
66
+ /**
67
+ * Comic viewer width.
68
+ */
69
+ viewerWidth: number;
70
+ /**
71
+ * The value for FlatList windowSize.
72
+ * @default 3
73
+ */
74
+ windowSize?: number;
75
+ }> {
76
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import ComicViewerItemProps from './ComicViewerItemProps';
3
+ declare function ViewerItem<T>({ props }: {
4
+ props: ComicViewerItemProps<T>;
5
+ }): JSX.Element;
6
+ declare const _default: React.MemoExoticComponent<typeof ViewerItem>;
7
+ export default _default;
@@ -0,0 +1,3 @@
1
+ export { default } from './ComicViewer';
2
+ export type { ComicViewerItemData, default as ComicViewerProps, ErrorInfo } from './ComicViewerProps';
3
+ export type { default as ComicViewerItemProps } from './ComicViewerItemProps';
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import type DateTimePickerProps from './DateTimePickerProps';
3
2
  export default function DateTimePicker(props: DateTimePickerProps): JSX.Element;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  interface YearPickerProps {
3
2
  date: Date;
4
3
  locale?: string;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import type FlipCardProps from './FlipCardProps';
3
2
  export default function FlipCard(props: FlipCardProps): JSX.Element;
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import type StatusBarProviderProps from './StatusBarProviderProps';
3
2
  export default function StatusBarProvider(props: StatusBarProviderProps): JSX.Element;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
2
  import type { PageProps } from './ViewPagerProps';
3
- declare const _default: React.MemoExoticComponent<(props: PageProps) => JSX.Element>;
3
+ declare function Page(props: PageProps): JSX.Element;
4
+ declare const _default: React.MemoExoticComponent<typeof Page>;
4
5
  export default _default;
@@ -1,3 +1,5 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import type ViewPagerProps from './ViewPagerProps';
3
- export default function ViewPager(props: ViewPagerProps): JSX.Element;
3
+ import type { ViewPagerInstance } from './ViewPagerProps';
4
+ declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "keyboardDismissMode" | "scrollEnabled" | "loading" | "initialPage" | "pageComponent" | "pageForceRerenderKey"> & React.RefAttributes<ViewPagerInstance>>;
5
+ export default ViewPager;
@@ -1,33 +1,34 @@
1
- import React from 'react';
1
+ import type { ComponentType, PropsWithChildren, ReactNode, Ref } from 'react';
2
2
  import type { ViewProps } from 'react-native';
3
+ import type { SharedValue } from 'react-native-reanimated';
3
4
  import type { ComponentProps } from '@fountain-ui/core';
4
5
  export declare type KeyboardDismissMode = 'none' | 'on-drag';
5
- export declare type PageProps = React.PropsWithChildren<ViewProps> & {
6
- isNeighbor: boolean;
7
- isVisible: boolean;
8
- rerenderKey?: any;
6
+ export declare type PageProps = PropsWithChildren<ViewProps> & {
7
+ index: number;
8
+ loading: ViewPagerProps['loading'];
9
+ sharedIndex: SharedValue<number>;
10
+ rerenderKey?: ViewPagerProps['pageForceRerenderKey'];
9
11
  };
10
- export declare type PageComponent = React.ComponentType<PageProps>;
12
+ export declare type PageComponent = ComponentType<PageProps>;
11
13
  export declare type Loading = 'lazy' | 'eager';
12
- export default interface ViewPagerProps extends ComponentProps<{
13
- /**
14
- * Collection of ViewPager components.
15
- */
16
- children?: React.ReactNode;
14
+ export interface ViewPagerInstance {
17
15
  /**
18
- * If `true`, enable page visible hint.
19
- * @default false
16
+ * Function to scroll to a specific page in the ViewPager. Invalid index is ignored.
17
+ * @param index
20
18
  */
21
- enableVisibleHint?: boolean;
19
+ setPage: (index: number) => void;
20
+ }
21
+ export default interface ViewPagerProps extends ComponentProps<{
22
+ ref?: Ref<ViewPagerInstance>;
22
23
  /**
23
- * If `true`, Based on the current index, the pages on the left and right are also rerender.
24
- * @default false
24
+ * Collection of ViewPager components.
25
25
  */
26
- enableNeighborPageRerender?: boolean;
26
+ children?: ReactNode;
27
27
  /**
28
- * A number representing the index of the active page.
28
+ * Index of initial page that should be selected.
29
+ * @default 0
29
30
  */
30
- index: number;
31
+ initialPage?: number;
31
32
  /**
32
33
  * Whether to load the page immediately (`eager`) or on an as-needed basis (`lazy`).
33
34
  * @default 'lazy'
@@ -1,3 +1,5 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import type ViewPagerProps from './ViewPagerProps';
3
- export default function ViewPager(props: ViewPagerProps): JSX.Element;
3
+ import type { ViewPagerInstance } from './ViewPagerProps';
4
+ declare const ViewPager: React.ForwardRefExoticComponent<Pick<ViewPagerProps, "style" | "children" | "onChange" | "keyboardDismissMode" | "scrollEnabled" | "loading" | "initialPage" | "pageComponent" | "pageForceRerenderKey"> & React.RefAttributes<ViewPagerInstance>>;
5
+ export default ViewPager;
@@ -1,2 +1,2 @@
1
1
  export { default } from './ViewPagerWeb';
2
- export type { default as ViewPagerProps } from './ViewPagerProps';
2
+ export type { default as ViewPagerProps, ViewPagerInstance } from './ViewPagerProps';
@@ -1,21 +1,4 @@
1
- import React from 'react';
2
- import ViewPagerProps, { Loading, PageComponent } from './ViewPagerProps';
3
- export interface PageState {
4
- visited?: boolean;
5
- }
6
- export interface PageRenderOption {
7
- enableVisibleHint: boolean;
8
- enableNeighborPageRerender: boolean;
9
- index: number;
10
- loading: Loading;
11
- pageComponent: PageComponent;
12
- pageForceRerenderKey?: any;
13
- }
14
- export interface PageRenderer {
15
- (children: ViewPagerProps['children']): React.ReactNode;
16
- }
17
- export declare const defaultEnableVisibleHint: boolean;
18
- export declare const defaultEnableNeighborPageRerender: boolean;
1
+ import { Loading, PageComponent } from './ViewPagerProps';
2
+ export declare const defaultInitialPage: number;
19
3
  export declare const defaultLoading: Loading;
20
4
  export declare const defaultPageComponent: PageComponent;
21
- export declare const usePageRenderer: ({ enableVisibleHint, index: currentIndex, loading, pageComponent: PageComponent, pageForceRerenderKey, enableNeighborPageRerender, }: PageRenderOption) => PageRenderer;
@@ -1,5 +1,5 @@
1
1
  import { Falsy, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';
2
- import Animated from 'react-native-reanimated';
2
+ import type { SharedValue } from 'react-native-reanimated';
3
3
  declare type WebOnlyStyle = {
4
4
  boxShadow: any;
5
5
  };
@@ -13,12 +13,11 @@ export interface ContentInsets {
13
13
  right?: number;
14
14
  }
15
15
  export interface Options {
16
- translucent?: boolean;
17
16
  shouldTranslateYReset?: boolean;
18
17
  }
19
18
  export interface CollapsibleAppBar {
20
19
  appBarStyle: ViewStyleProp;
21
- vectorY: Animated.SharedValue<number>;
20
+ vectorY: SharedValue<number>;
22
21
  onAppBarLayout: OnLayoutCallback;
23
22
  onCollapsibleToolbarLayout: OnLayoutCallback;
24
23
  onScroll: OnScroll;
@@ -1,4 +1,4 @@
1
- import Animated from 'react-native-reanimated';
2
- export default function useAnimatedDisplayStyle(vectorY: Animated.SharedValue<number>, threshold?: number, defaultDisplay?: 'flex' | 'none'): {
1
+ import type { SharedValue } from 'react-native-reanimated';
2
+ export default function useAnimatedDisplayStyle(vectorY: SharedValue<number>, threshold?: number, defaultDisplay?: 'flex' | 'none'): {
3
3
  display: "flex" | "none";
4
4
  };
@@ -8,6 +8,8 @@ export { default as FlipCard } from './FlipCard';
8
8
  export * from './FlipCard';
9
9
  export { default as ViewPager } from './ViewPager';
10
10
  export * from './ViewPager';
11
+ export { default as ComicViewer } from './ComicViewer';
12
+ export * from './ComicViewer';
11
13
  export { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';
12
14
  export * from './StatusBarProvider';
13
15
  export * from './hooks';