@fountain-ui/lab 2.0.0-beta.10 → 2.0.0-beta.13

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 (266) hide show
  1. package/build/commonjs/Carousel/Carousel.js +142 -0
  2. package/build/commonjs/Carousel/Carousel.js.map +1 -0
  3. package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
  4. package/build/commonjs/Carousel/animation/animationUtils.js +9 -0
  5. package/build/commonjs/Carousel/animation/animationUtils.js.map +1 -0
  6. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js +15 -0
  7. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  8. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +20 -0
  9. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  10. package/build/commonjs/Carousel/animation/index.js +40 -0
  11. package/build/commonjs/Carousel/animation/index.js.map +1 -0
  12. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js +27 -0
  13. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  14. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +65 -0
  15. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  16. package/build/commonjs/Carousel/components/InternalContext.js +29 -0
  17. package/build/commonjs/Carousel/components/InternalContext.js.map +1 -0
  18. package/build/commonjs/Carousel/components/ItemView.js +66 -0
  19. package/build/commonjs/Carousel/components/ItemView.js.map +1 -0
  20. package/build/commonjs/Carousel/components/RootView.js +86 -0
  21. package/build/commonjs/Carousel/components/RootView.js.map +1 -0
  22. package/build/commonjs/Carousel/components/ScrollViewGesture.js +81 -0
  23. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -0
  24. package/build/commonjs/Carousel/components/index.js +40 -0
  25. package/build/commonjs/Carousel/components/index.js.map +1 -0
  26. package/build/commonjs/Carousel/hooks/index.js +64 -0
  27. package/build/commonjs/Carousel/hooks/index.js.map +1 -0
  28. package/build/commonjs/Carousel/hooks/useAutoplayController.js +58 -0
  29. package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -0
  30. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js +23 -0
  31. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
  32. package/build/commonjs/Carousel/hooks/useIndexController.js +70 -0
  33. package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -0
  34. package/build/commonjs/Carousel/hooks/useItemInterpolation.js +63 -0
  35. package/build/commonjs/Carousel/hooks/useItemInterpolation.js.map +1 -0
  36. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +95 -0
  37. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  38. package/build/commonjs/Carousel/hooks/useLoopedData.js +33 -0
  39. package/build/commonjs/Carousel/hooks/useLoopedData.js.map +1 -0
  40. package/build/commonjs/Carousel/hooks/usePagingAnimation.js +162 -0
  41. package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -0
  42. package/build/commonjs/Carousel/index.js +16 -2
  43. package/build/commonjs/Carousel/index.js.map +1 -1
  44. package/build/commonjs/Carousel/types.js +7 -0
  45. package/build/commonjs/Carousel/types.js.map +1 -0
  46. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +86 -21
  47. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  48. package/build/commonjs/ViewPager/PageStateContext.js +22 -0
  49. package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
  50. package/build/commonjs/ViewPager/ViewPagerNative.js +82 -34
  51. package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
  52. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  53. package/build/commonjs/ViewPager/ViewPagerWeb.js +35 -26
  54. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
  55. package/build/commonjs/ViewPager/index.js +8 -0
  56. package/build/commonjs/ViewPager/index.js.map +1 -1
  57. package/build/commonjs/ViewPager/index.native.js +8 -0
  58. package/build/commonjs/ViewPager/index.native.js.map +1 -1
  59. package/build/commonjs/ViewPager/utils.js +5 -41
  60. package/build/commonjs/ViewPager/utils.js.map +1 -1
  61. package/build/commonjs/ViewabilityTrackerView/Viewability.js +2 -0
  62. package/build/commonjs/ViewabilityTrackerView/Viewability.js.map +1 -0
  63. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js +45 -0
  64. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  65. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  66. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  67. package/build/commonjs/{Carousel/index.native.js → ViewabilityTrackerView/index.js} +3 -3
  68. package/build/commonjs/ViewabilityTrackerView/index.js.map +1 -0
  69. package/build/commonjs/ViewabilityTrackerView/measureViewability.js +42 -0
  70. package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -0
  71. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js +88 -0
  72. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  73. package/build/commonjs/hooks/index.js +16 -0
  74. package/build/commonjs/hooks/index.js.map +1 -1
  75. package/build/commonjs/hooks/useDeferredExecutor.js +45 -0
  76. package/build/commonjs/hooks/useDeferredExecutor.js.map +1 -0
  77. package/build/commonjs/hooks/useIsMounted.js +22 -0
  78. package/build/commonjs/hooks/useIsMounted.js.map +1 -0
  79. package/build/commonjs/index.js +22 -1
  80. package/build/commonjs/index.js.map +1 -1
  81. package/build/module/Carousel/Carousel.js +120 -0
  82. package/build/module/Carousel/Carousel.js.map +1 -0
  83. package/build/module/Carousel/CarouselProps.js.map +1 -1
  84. package/build/module/Carousel/animation/animationUtils.js +2 -0
  85. package/build/module/Carousel/animation/animationUtils.js.map +1 -0
  86. package/build/module/Carousel/animation/createDefaultItemStyle.js +3 -0
  87. package/build/module/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  88. package/build/module/Carousel/animation/createDefaultScrollAnimation.js +11 -0
  89. package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  90. package/build/module/Carousel/animation/index.js +5 -0
  91. package/build/module/Carousel/animation/index.js.map +1 -0
  92. package/build/module/Carousel/animation/normalItemStyleFactory.js +18 -0
  93. package/build/module/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  94. package/build/module/Carousel/animation/parallaxItemStyleFactory.js +55 -0
  95. package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  96. package/build/module/Carousel/components/InternalContext.js +19 -0
  97. package/build/module/Carousel/components/InternalContext.js.map +1 -0
  98. package/build/module/Carousel/components/ItemView.js +46 -0
  99. package/build/module/Carousel/components/ItemView.js.map +1 -0
  100. package/build/module/Carousel/components/RootView.js +65 -0
  101. package/build/module/Carousel/components/RootView.js.map +1 -0
  102. package/build/module/Carousel/components/ScrollViewGesture.js +67 -0
  103. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -0
  104. package/build/module/Carousel/components/index.js +5 -0
  105. package/build/module/Carousel/components/index.js.map +1 -0
  106. package/build/module/Carousel/hooks/index.js +8 -0
  107. package/build/module/Carousel/hooks/index.js.map +1 -0
  108. package/build/module/Carousel/hooks/useAutoplayController.js +48 -0
  109. package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -0
  110. package/build/module/Carousel/hooks/useDimensionChangeReaction.js +14 -0
  111. package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
  112. package/build/module/Carousel/hooks/useIndexController.js +54 -0
  113. package/build/module/Carousel/hooks/useIndexController.js.map +1 -0
  114. package/build/module/Carousel/hooks/useItemInterpolation.js +51 -0
  115. package/build/module/Carousel/hooks/useItemInterpolation.js.map +1 -0
  116. package/build/module/Carousel/hooks/useItemVisibilityStore.js +87 -0
  117. package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  118. package/build/module/Carousel/hooks/useLoopedData.js +24 -0
  119. package/build/module/Carousel/hooks/useLoopedData.js.map +1 -0
  120. package/build/module/Carousel/hooks/usePagingAnimation.js +153 -0
  121. package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -0
  122. package/build/module/Carousel/index.js +2 -1
  123. package/build/module/Carousel/index.js.map +1 -1
  124. package/build/module/Carousel/types.js +3 -0
  125. package/build/module/Carousel/types.js.map +1 -0
  126. package/build/module/ViewPager/ChildrenMemoizedPage.js +80 -23
  127. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  128. package/build/module/ViewPager/PageStateContext.js +10 -0
  129. package/build/module/ViewPager/PageStateContext.js.map +1 -0
  130. package/build/module/ViewPager/ViewPagerNative.js +81 -34
  131. package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
  132. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  133. package/build/module/ViewPager/ViewPagerWeb.js +29 -24
  134. package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
  135. package/build/module/ViewPager/index.js +1 -0
  136. package/build/module/ViewPager/index.js.map +1 -1
  137. package/build/module/ViewPager/index.native.js +1 -0
  138. package/build/module/ViewPager/index.native.js.map +1 -1
  139. package/build/module/ViewPager/utils.js +2 -32
  140. package/build/module/ViewPager/utils.js.map +1 -1
  141. package/build/module/ViewabilityTrackerView/Viewability.js +2 -0
  142. package/build/module/ViewabilityTrackerView/Viewability.js.map +1 -0
  143. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js +28 -0
  144. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  145. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  146. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  147. package/build/module/ViewabilityTrackerView/index.js +2 -0
  148. package/build/module/ViewabilityTrackerView/index.js.map +1 -0
  149. package/build/module/ViewabilityTrackerView/measureViewability.js +34 -0
  150. package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -0
  151. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js +73 -0
  152. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  153. package/build/module/hooks/index.js +2 -0
  154. package/build/module/hooks/index.js.map +1 -1
  155. package/build/module/hooks/useDeferredExecutor.js +33 -0
  156. package/build/module/hooks/useDeferredExecutor.js.map +1 -0
  157. package/build/module/hooks/useIsMounted.js +13 -0
  158. package/build/module/hooks/useIsMounted.js.map +1 -0
  159. package/build/module/index.js +2 -0
  160. package/build/module/index.js.map +1 -1
  161. package/build/typescript/Carousel/Carousel.d.ts +5 -0
  162. package/build/typescript/Carousel/CarouselProps.d.ts +33 -48
  163. package/build/typescript/Carousel/animation/animationUtils.d.ts +1 -0
  164. package/build/typescript/Carousel/animation/createDefaultItemStyle.d.ts +2 -0
  165. package/build/typescript/Carousel/animation/createDefaultScrollAnimation.d.ts +2 -0
  166. package/build/typescript/Carousel/animation/index.d.ts +4 -0
  167. package/build/typescript/Carousel/animation/normalItemStyleFactory.d.ts +2 -0
  168. package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +9 -0
  169. package/build/typescript/Carousel/components/InternalContext.d.ts +14 -0
  170. package/build/typescript/Carousel/components/ItemView.d.ts +9 -0
  171. package/build/typescript/Carousel/components/RootView.d.ts +16 -0
  172. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +12 -0
  173. package/build/typescript/Carousel/components/index.d.ts +4 -0
  174. package/build/typescript/Carousel/hooks/index.d.ts +7 -0
  175. package/build/typescript/Carousel/hooks/useAutoplayController.d.ts +7 -0
  176. package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +7 -0
  177. package/build/typescript/Carousel/hooks/useIndexController.d.ts +10 -0
  178. package/build/typescript/Carousel/hooks/useItemInterpolation.d.ts +2 -0
  179. package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +7 -0
  180. package/build/typescript/Carousel/hooks/useLoopedData.d.ts +1 -0
  181. package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +18 -0
  182. package/build/typescript/Carousel/index.d.ts +3 -1
  183. package/build/typescript/Carousel/types.d.ts +79 -0
  184. package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +2 -1
  185. package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
  186. package/build/typescript/ViewPager/ViewPagerNative.d.ts +4 -1
  187. package/build/typescript/ViewPager/ViewPagerProps.d.ts +31 -19
  188. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +4 -1
  189. package/build/typescript/ViewPager/index.d.ts +2 -1
  190. package/build/typescript/ViewPager/index.native.d.ts +1 -0
  191. package/build/typescript/ViewPager/utils.d.ts +3 -19
  192. package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
  193. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +2 -0
  194. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
  195. package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
  196. package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
  197. package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
  198. package/build/typescript/hooks/index.d.ts +2 -0
  199. package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
  200. package/build/typescript/hooks/useIsMounted.d.ts +4 -0
  201. package/build/typescript/index.d.ts +2 -0
  202. package/package.json +4 -19
  203. package/src/Carousel/Carousel.tsx +152 -0
  204. package/src/Carousel/CarouselProps.ts +35 -53
  205. package/src/Carousel/animation/animationUtils.ts +1 -0
  206. package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
  207. package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
  208. package/src/Carousel/animation/index.ts +4 -0
  209. package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
  210. package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
  211. package/src/Carousel/components/InternalContext.ts +33 -0
  212. package/src/Carousel/components/ItemView.tsx +66 -0
  213. package/src/Carousel/components/RootView.tsx +79 -0
  214. package/src/Carousel/components/ScrollViewGesture.tsx +87 -0
  215. package/src/Carousel/components/index.ts +4 -0
  216. package/src/Carousel/hooks/index.ts +7 -0
  217. package/src/Carousel/hooks/useAutoplayController.ts +57 -0
  218. package/src/Carousel/hooks/useDimensionChangeReaction.ts +25 -0
  219. package/src/Carousel/hooks/useIndexController.tsx +76 -0
  220. package/src/Carousel/hooks/useItemInterpolation.ts +107 -0
  221. package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
  222. package/src/Carousel/hooks/useLoopedData.ts +26 -0
  223. package/src/Carousel/hooks/usePagingAnimation.ts +195 -0
  224. package/src/Carousel/index.ts +4 -2
  225. package/src/Carousel/types.ts +97 -0
  226. package/src/ViewPager/ChildrenMemoizedPage.tsx +97 -23
  227. package/src/ViewPager/PageStateContext.ts +15 -0
  228. package/src/ViewPager/ViewPagerNative.tsx +101 -39
  229. package/src/ViewPager/ViewPagerProps.ts +33 -19
  230. package/src/ViewPager/ViewPagerWeb.tsx +38 -29
  231. package/src/ViewPager/index.native.ts +1 -0
  232. package/src/ViewPager/index.ts +2 -1
  233. package/src/ViewPager/utils.tsx +4 -56
  234. package/src/ViewabilityTrackerView/Viewability.ts +3 -0
  235. package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
  236. package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
  237. package/src/ViewabilityTrackerView/index.ts +2 -0
  238. package/src/ViewabilityTrackerView/measureViewability.ts +56 -0
  239. package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
  240. package/src/hooks/index.ts +2 -0
  241. package/src/hooks/useDeferredExecutor.ts +46 -0
  242. package/src/hooks/useIsMounted.ts +19 -0
  243. package/src/index.ts +3 -0
  244. package/build/commonjs/Carousel/CarouselNative.js +0 -72
  245. package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
  246. package/build/commonjs/Carousel/CarouselWeb.js +0 -237
  247. package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
  248. package/build/commonjs/Carousel/index.native.js.map +0 -1
  249. package/build/commonjs/Carousel/utils.js +0 -19
  250. package/build/commonjs/Carousel/utils.js.map +0 -1
  251. package/build/module/Carousel/CarouselNative.js +0 -54
  252. package/build/module/Carousel/CarouselNative.js.map +0 -1
  253. package/build/module/Carousel/CarouselWeb.js +0 -215
  254. package/build/module/Carousel/CarouselWeb.js.map +0 -1
  255. package/build/module/Carousel/index.native.js +0 -2
  256. package/build/module/Carousel/index.native.js.map +0 -1
  257. package/build/module/Carousel/utils.js +0 -7
  258. package/build/module/Carousel/utils.js.map +0 -1
  259. package/build/typescript/Carousel/CarouselNative.d.ts +0 -2
  260. package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
  261. package/build/typescript/Carousel/index.native.d.ts +0 -1
  262. package/build/typescript/Carousel/utils.d.ts +0 -6
  263. package/src/Carousel/CarouselNative.tsx +0 -67
  264. package/src/Carousel/CarouselWeb.tsx +0 -222
  265. package/src/Carousel/index.native.ts +0 -1
  266. package/src/Carousel/utils.ts +0 -11
@@ -0,0 +1,22 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import type { OverridableComponentProps } from '@fountain-ui/core';
3
+ import type Viewability from './Viewability';
4
+ export default interface ViewabilityTrackerViewProps extends OverridableComponentProps<ViewProps, {
5
+ /**
6
+ * @default true
7
+ */
8
+ enabled?: boolean;
9
+ /**
10
+ * @default 1000
11
+ */
12
+ measurementIntervalMillis?: number;
13
+ /**
14
+ *
15
+ */
16
+ onViewabilityChange?: (viewability: Viewability) => void;
17
+ /**
18
+ * @default 50
19
+ */
20
+ visiblePercentThreshold?: number;
21
+ }> {
22
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './ViewabilityTrackerView';
2
+ export type { default as ViewabilityTrackerViewProps } from './ViewabilityTrackerViewProps';
@@ -0,0 +1,11 @@
1
+ import type { View } from 'react-native';
2
+ export interface ViewabilityDetail {
3
+ visiblePercent: number;
4
+ }
5
+ export interface MeasureViewabilityParameters {
6
+ view: View;
7
+ windowWidth: number;
8
+ windowHeight: number;
9
+ onViewabilityDetailMeasured: (detail: ViewabilityDetail) => void;
10
+ }
11
+ export default function measureViewability({ view, windowWidth, windowHeight, onViewabilityDetailMeasured, }: MeasureViewabilityParameters): void;
@@ -0,0 +1,11 @@
1
+ import type { RefObject } from 'react';
2
+ import type { View } from 'react-native';
3
+ import type Viewability from './Viewability';
4
+ export interface ViewabilityTrackerConfig {
5
+ enabled: boolean;
6
+ measurementIntervalMillis: number;
7
+ onViewabilityChange?: (viewability: Viewability) => void;
8
+ viewRef: RefObject<View>;
9
+ visiblePercentThreshold: number;
10
+ }
11
+ export default function useViewabilityTracker(config: ViewabilityTrackerConfig): void;
@@ -1,2 +1,4 @@
1
+ export { default as useDeferredExecutor } from './useDeferredExecutor';
2
+ export { default as useIsMounted } from './useIsMounted';
1
3
  export { default as useUnstableCollapsibleAppBar } from './useUnstableCollapsibleAppBar';
2
4
  export { default as useUnstableToggleDisplayStyle } from './useUnstableToggleDisplayStyle';
@@ -0,0 +1,11 @@
1
+ export interface Runnable {
2
+ (): void;
3
+ }
4
+ export interface DeferredExecute {
5
+ (runnable: Runnable, delay?: number): void;
6
+ }
7
+ export interface DeferredExecutor {
8
+ cancel: () => void;
9
+ execute: DeferredExecute;
10
+ }
11
+ export default function useDeferredExecutor(): DeferredExecutor;
@@ -0,0 +1,4 @@
1
+ export interface UseIsMounted {
2
+ (): boolean;
3
+ }
4
+ export default function useIsMounted(): UseIsMounted;
@@ -12,4 +12,6 @@ export { default as ComicViewer } from './ComicViewer';
12
12
  export * from './ComicViewer';
13
13
  export { default as StatusBarProvider, useStatusBarContext } from './StatusBarProvider';
14
14
  export * from './StatusBarProvider';
15
+ export { default as ViewabilityTrackerView } from './ViewabilityTrackerView';
16
+ export * from './ViewabilityTrackerView';
15
17
  export * from './hooks';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fountain-ui/lab",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.13",
4
4
  "private": false,
5
5
  "author": "Fountain-UI Team",
6
6
  "description": "Incubator for Fountain-UI React components.",
@@ -29,9 +29,7 @@
29
29
  "react-dom": "^16.8.0 || ^17.0.0",
30
30
  "react-native": "^0.63.0",
31
31
  "react-native-gesture-handler": "^2.0.0",
32
- "react-native-pager-view": "^4.0.0",
33
- "react-native-snap-carousel": "^3.9.0",
34
- "react-slick": "^0.25.0"
32
+ "react-native-pager-view": "^4.0.0"
35
33
  },
36
34
  "peerDependenciesMeta": {
37
35
  "@gorhom/bottom-sheet": {
@@ -40,28 +38,15 @@
40
38
  "react-dom": {
41
39
  "optional": true
42
40
  },
43
- "react-native": {
44
- "optional": true
45
- },
46
- "react-slick": {
47
- "optional": true
48
- },
49
41
  "react-native-pager-view": {
50
42
  "optional": true
51
- },
52
- "react-native-snap-carousel": {
53
- "optional": true
54
43
  }
55
44
  },
56
45
  "devDependencies": {
57
46
  "@gorhom/bottom-sheet": "4.1.3",
58
- "@types/react-native-snap-carousel": "^3.8.4",
59
- "@types/react-slick": "^0.23.5",
60
47
  "date-fns": "^2.23.0",
61
48
  "react-native-pager-view": "^4.2.4",
62
- "react-native-safe-area-context": "^3.3.2",
63
- "react-native-snap-carousel": "^3.9.1",
64
- "react-slick": "^0.28.1"
49
+ "react-native-safe-area-context": "^3.3.2"
65
50
  },
66
51
  "react-native-builder-bob": {
67
52
  "source": "./src",
@@ -85,5 +70,5 @@
85
70
  "publishConfig": {
86
71
  "access": "public"
87
72
  },
88
- "gitHead": "0ac49f4ca5f910fc8b5edad2593300d796b2d914"
73
+ "gitHead": "4f247070bf942db98feafb9573e8c1dc3fc1d758"
89
74
  }
@@ -0,0 +1,152 @@
1
+ import React, { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import ViewabilityTrackerView from '../ViewabilityTrackerView';
4
+ import type CarouselProps from './CarouselProps';
5
+ import type { CarouselInstance } from './types';
6
+ import {
7
+ useAutoplayController,
8
+ useDimensionChangeReaction,
9
+ useIndexController,
10
+ useItemVisibilityStore,
11
+ useLoopedData,
12
+ usePagingAnimation,
13
+ } from './hooks';
14
+ import { createDefaultItemStyle, createDefaultScrollAnimation } from './animation';
15
+ import { InternalContext, RootView, ScrollViewGesture } from './components';
16
+
17
+ const Carousel = forwardRef<CarouselInstance, CarouselProps>(function Carousel(props, ref) {
18
+ const {
19
+ autoplay = false,
20
+ autoplayInterval = 3000,
21
+ createItemStyle = createDefaultItemStyle,
22
+ createScrollAnimation = createDefaultScrollAnimation,
23
+ data: originalData,
24
+ disableSmartAutoplay = false,
25
+ initialIndex = 0,
26
+ itemHeight,
27
+ itemWidth,
28
+ loop = false,
29
+ onIndexChange,
30
+ renderItem,
31
+ scrollEnabled = true,
32
+ style,
33
+ windowSize = 5,
34
+ } = props;
35
+
36
+ const data = useLoopedData(originalData, loop);
37
+
38
+ const initialTx = itemWidth * initialIndex;
39
+ const controlledTx = useRef(new Animated.Value(initialTx)).current;
40
+ const offsetTx = useRef(new Animated.Value(0)).current;
41
+
42
+ const {
43
+ currentIndex,
44
+ getCurrentIndex,
45
+ lastIndex,
46
+ monitorElement,
47
+ } = useIndexController({
48
+ controlledTx,
49
+ initialIndex,
50
+ itemWidth,
51
+ numberOfOriginalData: originalData.length,
52
+ onIndexChange,
53
+ });
54
+
55
+ const itemVisibilityStore = useItemVisibilityStore({
56
+ currentIndex,
57
+ numberOfData: data.length,
58
+ windowSize,
59
+ });
60
+
61
+ const {
62
+ finalizeAnimation,
63
+ globalInterpolation,
64
+ startPagingAnimation,
65
+ } = usePagingAnimation({
66
+ controlledTx,
67
+ createScrollAnimation,
68
+ getCurrentIndex,
69
+ itemWidth,
70
+ lastIndex,
71
+ loop,
72
+ numberOfData: data.length,
73
+ offsetTx,
74
+ });
75
+
76
+ const autoplayController = useAutoplayController({
77
+ enabled: autoplay,
78
+ intervalMillis: autoplayInterval,
79
+ startPagingAnimation,
80
+ });
81
+
82
+ useDimensionChangeReaction({
83
+ controlledTx,
84
+ currentIndex,
85
+ itemWidth,
86
+ });
87
+
88
+ useImperativeHandle(
89
+ ref,
90
+ () => ({
91
+ getCurrentIndex,
92
+ next: () => startPagingAnimation('directional', { direction: 'next' }),
93
+ prev: () => startPagingAnimation('directional', { direction: 'prev' }),
94
+ scrollTo: (option) => startPagingAnimation('index', option),
95
+ }),
96
+ [startPagingAnimation, getCurrentIndex],
97
+ );
98
+
99
+ const contextValue = useMemo(() => ({
100
+ createItemStyle,
101
+ data,
102
+ globalInterpolation,
103
+ itemHeight,
104
+ itemWidth,
105
+ itemVisibilityStore,
106
+ loop,
107
+ }), [
108
+ createItemStyle,
109
+ data,
110
+ globalInterpolation,
111
+ itemHeight,
112
+ itemWidth,
113
+ itemVisibilityStore,
114
+ loop,
115
+ ]);
116
+
117
+ return (
118
+ <InternalContext.Provider value={contextValue}>
119
+ {monitorElement}
120
+
121
+ <ViewabilityTrackerView
122
+ enabled={autoplay && !disableSmartAutoplay}
123
+ measurementIntervalMillis={Math.max(3000, autoplayInterval)}
124
+ onViewabilityChange={({ visible }) => {
125
+ if (visible) {
126
+ autoplayController.resume();
127
+ } else {
128
+ autoplayController.pause();
129
+ }
130
+ }}
131
+ >
132
+ <ScrollViewGesture
133
+ autoplayController={autoplayController}
134
+ finalizeAnimation={finalizeAnimation}
135
+ offsetTx={offsetTx}
136
+ scrollEnabled={scrollEnabled}
137
+ startPagingAnimation={startPagingAnimation}
138
+ >
139
+ <RootView
140
+ data={data}
141
+ itemHeight={itemHeight}
142
+ originalData={originalData}
143
+ renderItem={renderItem}
144
+ style={style}
145
+ />
146
+ </ScrollViewGesture>
147
+ </ViewabilityTrackerView>
148
+ </InternalContext.Provider>
149
+ );
150
+ });
151
+
152
+ export default memo(Carousel);
@@ -1,8 +1,10 @@
1
- import React, { RefObject } from 'react';
2
- import type { ListRenderItemInfo } from 'react-native';
1
+ import type { RefObject } from 'react';
3
2
  import type { ComponentProps } from '@fountain-ui/core';
3
+ import type { CarouselInstance, CreateItemStyle, CreateScrollAnimation, ItemHeight, RenderItem } from './types';
4
4
 
5
5
  export default interface CarouselProps<ItemT = any> extends ComponentProps<{
6
+ ref?: RefObject<CarouselInstance>;
7
+
6
8
  /**
7
9
  * If `true`, enable autoplay.
8
10
  * @default false
@@ -16,92 +18,72 @@ export default interface CarouselProps<ItemT = any> extends ComponentProps<{
16
18
  autoplayInterval?: number;
17
19
 
18
20
  /**
19
- * Padding for center slide. If specified, `slidesToScroll` and `slidesToShow` set to 1.
21
+ * The item style creator function.
22
+ * @default createDefaultItemStyle
20
23
  */
21
- centerSlidePadding?: number;
24
+ createItemStyle?: CreateItemStyle;
22
25
 
23
26
  /**
24
- * Delay in ms until navigating to the next item.
27
+ * The scroll animation creator function.
28
+ * @default createDefaultScrollAnimation
29
+ */
30
+ createScrollAnimation?: CreateScrollAnimation;
31
+
32
+ /**
33
+ * Data for render items.
25
34
  */
26
35
  data: ReadonlyArray<ItemT>;
27
36
 
28
37
  /**
29
- * Value of the opacity effect applied to inactive slides.
30
- * @default 0.7
38
+ * If `true`, carousel will detect its own viewability and control autoplay automatically.
39
+ * @default false
31
40
  */
32
- inactiveSlideOpacity?: number;
41
+ disableSmartAutoplay?: boolean;
33
42
 
34
43
  /**
35
- * Value of the 'scale' transform applied to inactive slides.
36
- * @default 0.9
44
+ * Index of initial item that should be selected.
45
+ * @default 0
37
46
  */
38
- inactiveSlideScale?: number;
47
+ initialIndex?: number;
39
48
 
40
49
  /**
41
- * Web only. Value of the 'scale' transform applied to a active slide.
42
- * @default 0.990
50
+ * The item height.
51
+ * For a performance reason, always consider to provide a number value.
43
52
  */
44
- activeSlideScale?: number;
53
+ itemHeight: ItemHeight;
45
54
 
46
55
  /**
47
- * A number representing the index of the active slide.
56
+ * The item width.
48
57
  */
49
- index: number;
58
+ itemWidth: number;
50
59
 
51
60
  /**
52
61
  * Enable infinite loop mode.
53
62
  * @default false
54
63
  */
55
- infinite?: boolean;
64
+ loop?: boolean;
56
65
 
57
66
  /**
58
67
  * Callback fired when an index is changed.
59
68
  */
60
- onChange?: (newIndex: number) => void;
69
+ onIndexChange?: (newIndex: number) => void;
61
70
 
62
71
  /**
63
72
  * Takes an item from data and renders it into the list.
64
73
  */
65
- renderItem: (info: Omit<ListRenderItemInfo<ItemT>, 'separators'>) => React.ReactElement | null;
66
-
67
- /**
68
- * Web only. Number of slides to scroll at once.
69
- * @default 1
70
- */
71
- slidesToScroll?: number;
72
-
73
- /**
74
- * Web only. Number of slides to display.
75
- * @default 1
76
- */
77
- slidesToShow?: number;
74
+ renderItem: RenderItem<ItemT>;
78
75
 
79
76
  /**
80
- * Web only. Enable items to display at the center.
77
+ * Whether to enable scroll gesture.
81
78
  * @default true
82
79
  */
83
- centerMode?: boolean;
84
-
85
- /**
86
- * Web only. Enable arrows to display.
87
- * @default true
88
- */
89
- arrows?: boolean;
90
-
91
- /**
92
- * Web only. Style of arrows
93
- * @default true
94
- */
95
- arrowsStyle?: object;
96
-
97
- /**
98
- * Web only. Style of track
99
- * @default object
100
- */
101
- trackStyle?: object;
80
+ scrollEnabled?: boolean;
102
81
 
103
82
  /**
104
- * Only web. Refer slick object
83
+ * The maximum number of items that can respond to pan gesture events.
84
+ * Due to the nature of the `active` item, it accepts only odd number. (e.g. 1, 3, 5...)
85
+ * 0 means all items will respond to pan gesture events.
86
+ * @default 5
105
87
  */
106
- ref?: RefObject<any>;
88
+ windowSize?: number;
107
89
  }> {}
@@ -0,0 +1 @@
1
+ export const itemInterpolationInputRange = [-1, 0, 1];
@@ -0,0 +1,3 @@
1
+ import normalItemStyleFactory from './normalItemStyleFactory';
2
+
3
+ export default normalItemStyleFactory();
@@ -0,0 +1,13 @@
1
+ import { Animated, Easing } from 'react-native';
2
+
3
+ export default function createDefaultScrollAnimation(
4
+ animatedValue: Animated.Value,
5
+ toValue: number,
6
+ ): Animated.CompositeAnimation {
7
+ return Animated.timing(animatedValue, {
8
+ toValue: toValue,
9
+ duration: 350,
10
+ easing: Easing.bezier(0.25, 1, 0.5, 1),
11
+ useNativeDriver: true,
12
+ });
13
+ };
@@ -0,0 +1,4 @@
1
+ export { default as createDefaultItemStyle } from './createDefaultItemStyle';
2
+ export { default as createDefaultScrollAnimation } from './createDefaultScrollAnimation';
3
+ export { default as normalItemStyleFactory } from './normalItemStyleFactory';
4
+ export { default as parallaxItemStyleFactory } from './parallaxItemStyleFactory';
@@ -0,0 +1,19 @@
1
+ import type { CreateItemStyle } from '../types';
2
+ import { itemInterpolationInputRange } from './animationUtils';
3
+
4
+ export default function normalItemStyleFactory() {
5
+ const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {
6
+ const translate = itemInterpolation.interpolate({
7
+ inputRange: itemInterpolationInputRange,
8
+ outputRange: [
9
+ -itemWidth,
10
+ 0,
11
+ itemWidth,
12
+ ],
13
+ });
14
+
15
+ return { transform: [{ translateX: translate }] };
16
+ };
17
+
18
+ return createItemStyle;
19
+ };
@@ -0,0 +1,79 @@
1
+ import type { CreateItemStyle } from '../types';
2
+ import { itemInterpolationInputRange } from './animationUtils';
3
+
4
+ export interface ParallaxAnimationConfig {
5
+ activeItemScale?: number;
6
+ activeItemOpacity?: number;
7
+ adjacentItemScale?: number;
8
+ adjacentItemOpacity?: number;
9
+ scrollingOffset?: number;
10
+ }
11
+
12
+ const defaultParallaxAnimationConfig: Required<Readonly<ParallaxAnimationConfig>> = {
13
+ activeItemScale: 0.9,
14
+ activeItemOpacity: 1,
15
+ adjacentItemScale: Math.pow(0.9, 2),
16
+ adjacentItemOpacity: 0.5,
17
+ scrollingOffset: 50,
18
+ };
19
+
20
+ export default function parallaxItemStyleFactory(config: ParallaxAnimationConfig = defaultParallaxAnimationConfig) {
21
+ const {
22
+ activeItemOpacity,
23
+ activeItemScale,
24
+ adjacentItemOpacity,
25
+ adjacentItemScale,
26
+ scrollingOffset,
27
+ }: Required<ParallaxAnimationConfig> = {
28
+ ...config,
29
+ ...defaultParallaxAnimationConfig,
30
+ };
31
+
32
+ const createItemStyle: CreateItemStyle = (itemInterpolation, itemWidth) => {
33
+ const translate = itemInterpolation.interpolate({
34
+ inputRange: itemInterpolationInputRange,
35
+ outputRange: [
36
+ -itemWidth + scrollingOffset,
37
+ 0,
38
+ itemWidth - scrollingOffset,
39
+ ],
40
+ });
41
+
42
+ const zIndex = itemInterpolation.interpolate({
43
+ inputRange: itemInterpolationInputRange,
44
+ outputRange: [0, itemWidth, 0],
45
+ extrapolate: 'clamp',
46
+ });
47
+
48
+ const scale = itemInterpolation.interpolate({
49
+ inputRange: itemInterpolationInputRange,
50
+ outputRange: [
51
+ adjacentItemScale,
52
+ activeItemScale,
53
+ adjacentItemScale,
54
+ ],
55
+ extrapolate: 'clamp',
56
+ });
57
+
58
+ const opacity = itemInterpolation.interpolate({
59
+ inputRange: itemInterpolationInputRange,
60
+ outputRange: [
61
+ adjacentItemOpacity,
62
+ activeItemOpacity,
63
+ adjacentItemOpacity,
64
+ ],
65
+ extrapolate: 'clamp',
66
+ });
67
+
68
+ return {
69
+ transform: [
70
+ { translateX: translate },
71
+ { scale },
72
+ ],
73
+ zIndex,
74
+ opacity,
75
+ };
76
+ };
77
+
78
+ return createItemStyle;
79
+ };
@@ -0,0 +1,33 @@
1
+ import { createContext } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import type { CreateItemStyle, ItemHeight, ItemVisibilityStore } from '../types';
4
+
5
+ export interface InternalContextValue<ItemT> {
6
+ createItemStyle: CreateItemStyle;
7
+ data: ReadonlyArray<ItemT>;
8
+ globalInterpolation: Animated.AnimatedInterpolation;
9
+ itemHeight: ItemHeight;
10
+ itemWidth: number;
11
+ itemVisibilityStore: ItemVisibilityStore;
12
+ loop: boolean;
13
+ }
14
+
15
+ const mockItemVisibilityStore: ItemVisibilityStore = {
16
+ dispatch: () => void 0,
17
+ subscribe: () => () => void 0,
18
+ removeAllListeners: () => void 0,
19
+ };
20
+
21
+ const initialValue: Readonly<InternalContextValue<any>> = {
22
+ createItemStyle: () => ({}),
23
+ data: [],
24
+ globalInterpolation: Animated.add(new Animated.Value(0), 0),
25
+ itemHeight: 0,
26
+ itemWidth: 0,
27
+ itemVisibilityStore: mockItemVisibilityStore,
28
+ loop: false,
29
+ };
30
+
31
+ const InternalContext = createContext<InternalContextValue<any>>(initialValue);
32
+
33
+ export default InternalContext;
@@ -0,0 +1,66 @@
1
+ import type { ReactElement } from 'react';
2
+ import React, { useContext, useEffect, useMemo, useState } from 'react';
3
+ import type { ViewProps } from 'react-native';
4
+ import { Animated } from 'react-native';
5
+ import { StyleSheet } from '@fountain-ui/core';
6
+ import { useItemInterpolation } from '../hooks';
7
+ import InternalContext from './InternalContext';
8
+
9
+ export interface ItemViewProps {
10
+ children: (interpolation: Animated.AnimatedInterpolation) => ReactElement | null;
11
+ index: number;
12
+ onLayout?: ViewProps['onLayout'];
13
+ }
14
+
15
+ export default function ItemView(props: ItemViewProps) {
16
+ const {
17
+ children,
18
+ index,
19
+ onLayout,
20
+ } = props;
21
+
22
+ const {
23
+ createItemStyle,
24
+ itemHeight,
25
+ itemWidth,
26
+ itemVisibilityStore,
27
+ } = useContext(InternalContext);
28
+
29
+ const [visible, setVisible] = useState(false);
30
+
31
+ const interpolation = useItemInterpolation(index);
32
+
33
+ const itemStyle = useMemo(
34
+ () => createItemStyle(interpolation, itemWidth),
35
+ [createItemStyle, interpolation],
36
+ );
37
+
38
+ useEffect(() => {
39
+ return itemVisibilityStore.subscribe(ranges => {
40
+ const nextVisible = ranges.some(([from, to]) => index >= from && index <= to);
41
+ setVisible(nextVisible);
42
+ });
43
+ }, [itemVisibilityStore]);
44
+
45
+ return (
46
+ <Animated.View
47
+ children={visible ? children(interpolation) : null}
48
+ onLayout={onLayout}
49
+ style={[
50
+ {
51
+ width: itemWidth,
52
+ height: itemHeight !== 'auto' ? itemHeight : undefined,
53
+ },
54
+ styles.absolute,
55
+ // @ts-ignore
56
+ itemStyle,
57
+ ]}
58
+ />
59
+ );
60
+ };
61
+
62
+ const styles = StyleSheet.create({
63
+ absolute: {
64
+ position: 'absolute',
65
+ },
66
+ });