@fountain-ui/lab 2.0.0-beta.1 → 2.0.0-beta.12

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 (381) 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 +1 -1
  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/Carousel.js +137 -0
  15. package/build/commonjs/Carousel/Carousel.js.map +1 -0
  16. package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
  17. package/build/commonjs/Carousel/animation/animationUtils.js +9 -0
  18. package/build/commonjs/Carousel/animation/animationUtils.js.map +1 -0
  19. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js +15 -0
  20. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  21. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +20 -0
  22. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  23. package/build/commonjs/Carousel/animation/index.js +40 -0
  24. package/build/commonjs/Carousel/animation/index.js.map +1 -0
  25. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js +27 -0
  26. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  27. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +65 -0
  28. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  29. package/build/commonjs/Carousel/components/InternalContext.js +29 -0
  30. package/build/commonjs/Carousel/components/InternalContext.js.map +1 -0
  31. package/build/commonjs/Carousel/components/ItemView.js +64 -0
  32. package/build/commonjs/Carousel/components/ItemView.js.map +1 -0
  33. package/build/commonjs/Carousel/components/RootView.js +68 -0
  34. package/build/commonjs/Carousel/components/RootView.js.map +1 -0
  35. package/build/commonjs/Carousel/components/ScrollViewGesture.js +76 -0
  36. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -0
  37. package/build/commonjs/Carousel/components/index.js +40 -0
  38. package/build/commonjs/Carousel/components/index.js.map +1 -0
  39. package/build/commonjs/Carousel/hooks/index.js +64 -0
  40. package/build/commonjs/Carousel/hooks/index.js.map +1 -0
  41. package/build/commonjs/Carousel/hooks/useAutoplayController.js +55 -0
  42. package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -0
  43. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js +23 -0
  44. package/build/commonjs/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
  45. package/build/commonjs/Carousel/hooks/useIndexController.js +70 -0
  46. package/build/commonjs/Carousel/hooks/useIndexController.js.map +1 -0
  47. package/build/commonjs/Carousel/hooks/useItemInterpolation.js +63 -0
  48. package/build/commonjs/Carousel/hooks/useItemInterpolation.js.map +1 -0
  49. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js +95 -0
  50. package/build/commonjs/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  51. package/build/commonjs/Carousel/hooks/useLoopedData.js +33 -0
  52. package/build/commonjs/Carousel/hooks/useLoopedData.js.map +1 -0
  53. package/build/commonjs/Carousel/hooks/usePagingAnimation.js +124 -0
  54. package/build/commonjs/Carousel/hooks/usePagingAnimation.js.map +1 -0
  55. package/build/commonjs/Carousel/index.js +16 -2
  56. package/build/commonjs/Carousel/index.js.map +1 -1
  57. package/build/commonjs/Carousel/types.js +7 -0
  58. package/build/commonjs/Carousel/types.js.map +1 -0
  59. package/build/commonjs/ComicViewer/ComicViewer.js +16 -11
  60. package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -1
  61. package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +1 -1
  62. package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -1
  63. package/build/commonjs/ComicViewer/ViewerItem.js +4 -3
  64. package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -1
  65. package/build/commonjs/ComicViewer/index.js.map +1 -1
  66. package/build/commonjs/DateTimePicker/DateTimePicker.js +2 -2
  67. package/build/commonjs/DateTimePicker/DateTimePicker.js.map +1 -1
  68. package/build/commonjs/DateTimePicker/DateTimePickerProps.js.map +1 -1
  69. package/build/commonjs/DateTimePicker/DateTimePickerProvider.js.map +1 -1
  70. package/build/commonjs/DateTimePicker/YearPicker.js +21 -17
  71. package/build/commonjs/DateTimePicker/YearPicker.js.map +1 -1
  72. package/build/commonjs/DateTimePicker/index.js +4 -4
  73. package/build/commonjs/DateTimePicker/index.js.map +1 -1
  74. package/build/commonjs/DateTimePicker/utils.js +2 -1
  75. package/build/commonjs/DateTimePicker/utils.js.map +1 -1
  76. package/build/commonjs/FlipCard/FlipCard.js +7 -13
  77. package/build/commonjs/FlipCard/FlipCard.js.map +1 -1
  78. package/build/commonjs/FlipCard/FlipCardProps.js.map +1 -1
  79. package/build/commonjs/FlipCard/index.js.map +1 -1
  80. package/build/commonjs/StatusBarProvider/Provider.js +1 -1
  81. package/build/commonjs/StatusBarProvider/Provider.js.map +1 -1
  82. package/build/commonjs/StatusBarProvider/StatusBarProvider.js.map +1 -1
  83. package/build/commonjs/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
  84. package/build/commonjs/StatusBarProvider/index.js.map +1 -1
  85. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +86 -21
  86. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  87. package/build/commonjs/ViewPager/PageStateContext.js +22 -0
  88. package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
  89. package/build/commonjs/ViewPager/ViewPagerNative.js +61 -38
  90. package/build/commonjs/ViewPager/ViewPagerNative.js.map +1 -1
  91. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  92. package/build/commonjs/ViewPager/ViewPagerWeb.js +35 -26
  93. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +1 -1
  94. package/build/commonjs/ViewPager/index.js +8 -0
  95. package/build/commonjs/ViewPager/index.js.map +1 -1
  96. package/build/commonjs/ViewPager/index.native.js +8 -0
  97. package/build/commonjs/ViewPager/index.native.js.map +1 -1
  98. package/build/commonjs/ViewPager/utils.js +5 -39
  99. package/build/commonjs/ViewPager/utils.js.map +1 -1
  100. package/build/commonjs/ViewabilityTrackerView/Viewability.js +2 -0
  101. package/build/commonjs/ViewabilityTrackerView/Viewability.js.map +1 -0
  102. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js +45 -0
  103. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  104. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  105. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  106. package/build/commonjs/{Carousel/index.native.js → ViewabilityTrackerView/index.js} +3 -3
  107. package/build/commonjs/ViewabilityTrackerView/index.js.map +1 -0
  108. package/build/commonjs/ViewabilityTrackerView/measureViewability.js +42 -0
  109. package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -0
  110. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js +88 -0
  111. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  112. package/build/commonjs/hooks/index.js +16 -0
  113. package/build/commonjs/hooks/index.js.map +1 -1
  114. package/build/commonjs/hooks/useAppbarStyles.js.map +1 -1
  115. package/build/commonjs/hooks/useDeferredExecutor.js +45 -0
  116. package/build/commonjs/hooks/useDeferredExecutor.js.map +1 -0
  117. package/build/commonjs/hooks/useElevationStyle.js.map +1 -1
  118. package/build/commonjs/hooks/useHeight.js +5 -4
  119. package/build/commonjs/hooks/useHeight.js.map +1 -1
  120. package/build/commonjs/hooks/useIsMounted.js +22 -0
  121. package/build/commonjs/hooks/useIsMounted.js.map +1 -0
  122. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +56 -57
  123. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  124. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js +9 -11
  125. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  126. package/build/commonjs/index.js +28 -7
  127. package/build/commonjs/index.js.map +1 -1
  128. package/build/module/AnimatedY/AnimatedY.js +11 -10
  129. package/build/module/AnimatedY/AnimatedY.js.map +1 -1
  130. package/build/module/AnimatedY/AnimatedYProps.js.map +1 -1
  131. package/build/module/AnimatedY/index.js.map +1 -1
  132. package/build/module/BottomSheet/BottomSheetNative.js +1 -1
  133. package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
  134. package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
  135. package/build/module/BottomSheet/BottomSheetWeb.js +2 -6
  136. package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
  137. package/build/module/BottomSheet/TransparentBackdrop.js +1 -1
  138. package/build/module/BottomSheet/TransparentBackdrop.js.map +1 -1
  139. package/build/module/BottomSheet/index.js.map +1 -1
  140. package/build/module/BottomSheet/index.native.js.map +1 -1
  141. package/build/module/Carousel/Carousel.js +115 -0
  142. package/build/module/Carousel/Carousel.js.map +1 -0
  143. package/build/module/Carousel/CarouselProps.js.map +1 -1
  144. package/build/module/Carousel/animation/animationUtils.js +2 -0
  145. package/build/module/Carousel/animation/animationUtils.js.map +1 -0
  146. package/build/module/Carousel/animation/createDefaultItemStyle.js +3 -0
  147. package/build/module/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  148. package/build/module/Carousel/animation/createDefaultScrollAnimation.js +11 -0
  149. package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  150. package/build/module/Carousel/animation/index.js +5 -0
  151. package/build/module/Carousel/animation/index.js.map +1 -0
  152. package/build/module/Carousel/animation/normalItemStyleFactory.js +18 -0
  153. package/build/module/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  154. package/build/module/Carousel/animation/parallaxItemStyleFactory.js +55 -0
  155. package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  156. package/build/module/Carousel/components/InternalContext.js +19 -0
  157. package/build/module/Carousel/components/InternalContext.js.map +1 -0
  158. package/build/module/Carousel/components/ItemView.js +44 -0
  159. package/build/module/Carousel/components/ItemView.js.map +1 -0
  160. package/build/module/Carousel/components/RootView.js +47 -0
  161. package/build/module/Carousel/components/RootView.js.map +1 -0
  162. package/build/module/Carousel/components/ScrollViewGesture.js +62 -0
  163. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -0
  164. package/build/module/Carousel/components/index.js +5 -0
  165. package/build/module/Carousel/components/index.js.map +1 -0
  166. package/build/module/Carousel/hooks/index.js +8 -0
  167. package/build/module/Carousel/hooks/index.js.map +1 -0
  168. package/build/module/Carousel/hooks/useAutoplayController.js +45 -0
  169. package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -0
  170. package/build/module/Carousel/hooks/useDimensionChangeReaction.js +14 -0
  171. package/build/module/Carousel/hooks/useDimensionChangeReaction.js.map +1 -0
  172. package/build/module/Carousel/hooks/useIndexController.js +54 -0
  173. package/build/module/Carousel/hooks/useIndexController.js.map +1 -0
  174. package/build/module/Carousel/hooks/useItemInterpolation.js +51 -0
  175. package/build/module/Carousel/hooks/useItemInterpolation.js.map +1 -0
  176. package/build/module/Carousel/hooks/useItemVisibilityStore.js +87 -0
  177. package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  178. package/build/module/Carousel/hooks/useLoopedData.js +24 -0
  179. package/build/module/Carousel/hooks/useLoopedData.js.map +1 -0
  180. package/build/module/Carousel/hooks/usePagingAnimation.js +115 -0
  181. package/build/module/Carousel/hooks/usePagingAnimation.js.map +1 -0
  182. package/build/module/Carousel/index.js +2 -1
  183. package/build/module/Carousel/index.js.map +1 -1
  184. package/build/module/Carousel/types.js +3 -0
  185. package/build/module/Carousel/types.js.map +1 -0
  186. package/build/module/ComicViewer/ComicViewer.js +16 -11
  187. package/build/module/ComicViewer/ComicViewer.js.map +1 -1
  188. package/build/module/ComicViewer/ComicViewerItemProps.js.map +1 -1
  189. package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
  190. package/build/module/ComicViewer/ViewerItem.js +4 -3
  191. package/build/module/ComicViewer/ViewerItem.js.map +1 -1
  192. package/build/module/ComicViewer/index.js.map +1 -1
  193. package/build/module/DateTimePicker/DateTimePicker.js +2 -2
  194. package/build/module/DateTimePicker/DateTimePicker.js.map +1 -1
  195. package/build/module/DateTimePicker/DateTimePickerProps.js.map +1 -1
  196. package/build/module/DateTimePicker/DateTimePickerProvider.js.map +1 -1
  197. package/build/module/DateTimePicker/YearPicker.js +21 -17
  198. package/build/module/DateTimePicker/YearPicker.js.map +1 -1
  199. package/build/module/DateTimePicker/index.js.map +1 -1
  200. package/build/module/DateTimePicker/utils.js +2 -1
  201. package/build/module/DateTimePicker/utils.js.map +1 -1
  202. package/build/module/FlipCard/FlipCard.js +7 -7
  203. package/build/module/FlipCard/FlipCard.js.map +1 -1
  204. package/build/module/FlipCard/FlipCardProps.js.map +1 -1
  205. package/build/module/FlipCard/index.js.map +1 -1
  206. package/build/module/StatusBarProvider/Provider.js.map +1 -1
  207. package/build/module/StatusBarProvider/StatusBarProvider.js.map +1 -1
  208. package/build/module/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
  209. package/build/module/StatusBarProvider/index.js.map +1 -1
  210. package/build/module/ViewPager/ChildrenMemoizedPage.js +80 -23
  211. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +1 -1
  212. package/build/module/ViewPager/PageStateContext.js +10 -0
  213. package/build/module/ViewPager/PageStateContext.js.map +1 -0
  214. package/build/module/ViewPager/ViewPagerNative.js +57 -33
  215. package/build/module/ViewPager/ViewPagerNative.js.map +1 -1
  216. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  217. package/build/module/ViewPager/ViewPagerWeb.js +29 -24
  218. package/build/module/ViewPager/ViewPagerWeb.js.map +1 -1
  219. package/build/module/ViewPager/index.js +1 -0
  220. package/build/module/ViewPager/index.js.map +1 -1
  221. package/build/module/ViewPager/index.native.js +1 -0
  222. package/build/module/ViewPager/index.native.js.map +1 -1
  223. package/build/module/ViewPager/utils.js +2 -31
  224. package/build/module/ViewPager/utils.js.map +1 -1
  225. package/build/module/ViewabilityTrackerView/Viewability.js +2 -0
  226. package/build/module/ViewabilityTrackerView/Viewability.js.map +1 -0
  227. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js +28 -0
  228. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  229. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  230. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  231. package/build/module/ViewabilityTrackerView/index.js +2 -0
  232. package/build/module/ViewabilityTrackerView/index.js.map +1 -0
  233. package/build/module/ViewabilityTrackerView/measureViewability.js +34 -0
  234. package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -0
  235. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js +73 -0
  236. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  237. package/build/module/hooks/index.js +2 -0
  238. package/build/module/hooks/index.js.map +1 -1
  239. package/build/module/hooks/useAppbarStyles.js.map +1 -1
  240. package/build/module/hooks/useDeferredExecutor.js +33 -0
  241. package/build/module/hooks/useDeferredExecutor.js.map +1 -0
  242. package/build/module/hooks/useElevationStyle.js.map +1 -1
  243. package/build/module/hooks/useHeight.js +4 -3
  244. package/build/module/hooks/useHeight.js.map +1 -1
  245. package/build/module/hooks/useIsMounted.js +13 -0
  246. package/build/module/hooks/useIsMounted.js.map +1 -0
  247. package/build/module/hooks/useUnstableCollapsibleAppBar.js +58 -43
  248. package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  249. package/build/module/hooks/useUnstableToggleDisplayStyle.js +9 -7
  250. package/build/module/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  251. package/build/module/index.js +2 -0
  252. package/build/module/index.js.map +1 -1
  253. package/build/typescript/AnimatedY/AnimatedY.d.ts +0 -1
  254. package/build/typescript/BottomSheet/BottomSheetNative.d.ts +0 -1
  255. package/build/typescript/BottomSheet/BottomSheetWeb.d.ts +0 -1
  256. package/build/typescript/BottomSheet/TransparentBackdrop.d.ts +0 -1
  257. package/build/typescript/Carousel/Carousel.d.ts +5 -0
  258. package/build/typescript/Carousel/CarouselProps.d.ts +32 -48
  259. package/build/typescript/Carousel/animation/animationUtils.d.ts +1 -0
  260. package/build/typescript/Carousel/animation/createDefaultItemStyle.d.ts +2 -0
  261. package/build/typescript/Carousel/animation/createDefaultScrollAnimation.d.ts +2 -0
  262. package/build/typescript/Carousel/animation/index.d.ts +4 -0
  263. package/build/typescript/Carousel/animation/normalItemStyleFactory.d.ts +2 -0
  264. package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +9 -0
  265. package/build/typescript/Carousel/components/InternalContext.d.ts +14 -0
  266. package/build/typescript/Carousel/components/ItemView.d.ts +7 -0
  267. package/build/typescript/Carousel/components/RootView.d.ts +16 -0
  268. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +12 -0
  269. package/build/typescript/Carousel/components/index.d.ts +4 -0
  270. package/build/typescript/Carousel/hooks/index.d.ts +7 -0
  271. package/build/typescript/Carousel/hooks/useAutoplayController.d.ts +7 -0
  272. package/build/typescript/Carousel/hooks/useDimensionChangeReaction.d.ts +7 -0
  273. package/build/typescript/Carousel/hooks/useIndexController.d.ts +10 -0
  274. package/build/typescript/Carousel/hooks/useItemInterpolation.d.ts +2 -0
  275. package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +7 -0
  276. package/build/typescript/Carousel/hooks/useLoopedData.d.ts +1 -0
  277. package/build/typescript/Carousel/hooks/usePagingAnimation.d.ts +18 -0
  278. package/build/typescript/Carousel/index.d.ts +3 -1
  279. package/build/typescript/Carousel/types.d.ts +57 -0
  280. package/build/typescript/ComicViewer/ComicViewer.d.ts +0 -1
  281. package/build/typescript/DateTimePicker/DateTimePicker.d.ts +0 -1
  282. package/build/typescript/DateTimePicker/YearPicker.d.ts +0 -1
  283. package/build/typescript/FlipCard/FlipCard.d.ts +0 -1
  284. package/build/typescript/StatusBarProvider/StatusBarProvider.d.ts +0 -1
  285. package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +2 -1
  286. package/build/typescript/ViewPager/PageStateContext.d.ts +7 -0
  287. package/build/typescript/ViewPager/ViewPagerNative.d.ts +4 -2
  288. package/build/typescript/ViewPager/ViewPagerProps.d.ts +31 -19
  289. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +4 -2
  290. package/build/typescript/ViewPager/index.d.ts +2 -1
  291. package/build/typescript/ViewPager/index.native.d.ts +1 -0
  292. package/build/typescript/ViewPager/utils.d.ts +3 -19
  293. package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
  294. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +2 -0
  295. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
  296. package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
  297. package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
  298. package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
  299. package/build/typescript/hooks/index.d.ts +2 -0
  300. package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
  301. package/build/typescript/hooks/useIsMounted.d.ts +4 -0
  302. package/build/typescript/hooks/useUnstableCollapsibleAppBar.d.ts +2 -3
  303. package/build/typescript/hooks/useUnstableToggleDisplayStyle.d.ts +2 -2
  304. package/build/typescript/index.d.ts +2 -0
  305. package/package.json +12 -27
  306. package/src/AnimatedY/AnimatedY.tsx +13 -10
  307. package/src/Carousel/Carousel.tsx +151 -0
  308. package/src/Carousel/CarouselProps.ts +34 -53
  309. package/src/Carousel/animation/animationUtils.ts +1 -0
  310. package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
  311. package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
  312. package/src/Carousel/animation/index.ts +4 -0
  313. package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
  314. package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
  315. package/src/Carousel/components/InternalContext.ts +33 -0
  316. package/src/Carousel/components/ItemView.tsx +56 -0
  317. package/src/Carousel/components/RootView.tsx +66 -0
  318. package/src/Carousel/components/ScrollViewGesture.tsx +80 -0
  319. package/src/Carousel/components/index.ts +4 -0
  320. package/src/Carousel/hooks/index.ts +7 -0
  321. package/src/Carousel/hooks/useAutoplayController.ts +54 -0
  322. package/src/Carousel/hooks/useDimensionChangeReaction.ts +25 -0
  323. package/src/Carousel/hooks/useIndexController.tsx +76 -0
  324. package/src/Carousel/hooks/useItemInterpolation.ts +107 -0
  325. package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
  326. package/src/Carousel/hooks/useLoopedData.ts +26 -0
  327. package/src/Carousel/hooks/usePagingAnimation.ts +148 -0
  328. package/src/Carousel/index.ts +4 -2
  329. package/src/Carousel/types.ts +67 -0
  330. package/src/DateTimePicker/DateTimePicker.tsx +2 -2
  331. package/src/FlipCard/FlipCard.tsx +8 -8
  332. package/src/ViewPager/ChildrenMemoizedPage.tsx +97 -23
  333. package/src/ViewPager/PageStateContext.ts +15 -0
  334. package/src/ViewPager/ViewPagerNative.tsx +72 -36
  335. package/src/ViewPager/ViewPagerProps.ts +33 -19
  336. package/src/ViewPager/ViewPagerWeb.tsx +38 -29
  337. package/src/ViewPager/index.native.ts +1 -0
  338. package/src/ViewPager/index.ts +2 -1
  339. package/src/ViewPager/utils.tsx +4 -56
  340. package/src/ViewabilityTrackerView/Viewability.ts +3 -0
  341. package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
  342. package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
  343. package/src/ViewabilityTrackerView/index.ts +2 -0
  344. package/src/ViewabilityTrackerView/measureViewability.ts +56 -0
  345. package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
  346. package/src/hooks/index.ts +2 -0
  347. package/src/hooks/useDeferredExecutor.ts +46 -0
  348. package/src/hooks/useHeight.ts +2 -2
  349. package/src/hooks/useIsMounted.ts +19 -0
  350. package/src/hooks/useUnstableCollapsibleAppBar.ts +59 -42
  351. package/src/hooks/useUnstableToggleDisplayStyle.ts +8 -6
  352. package/src/index.ts +3 -0
  353. package/build/commonjs/Carousel/CarouselNative.js +0 -72
  354. package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
  355. package/build/commonjs/Carousel/CarouselWeb.js +0 -237
  356. package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
  357. package/build/commonjs/Carousel/index.native.js.map +0 -1
  358. package/build/commonjs/Carousel/utils.js +0 -19
  359. package/build/commonjs/Carousel/utils.js.map +0 -1
  360. package/build/commonjs/hooks/useWidth.js +0 -29
  361. package/build/commonjs/hooks/useWidth.js.map +0 -1
  362. package/build/module/Carousel/CarouselNative.js +0 -54
  363. package/build/module/Carousel/CarouselNative.js.map +0 -1
  364. package/build/module/Carousel/CarouselWeb.js +0 -215
  365. package/build/module/Carousel/CarouselWeb.js.map +0 -1
  366. package/build/module/Carousel/index.native.js +0 -2
  367. package/build/module/Carousel/index.native.js.map +0 -1
  368. package/build/module/Carousel/utils.js +0 -7
  369. package/build/module/Carousel/utils.js.map +0 -1
  370. package/build/module/hooks/useWidth.js +0 -15
  371. package/build/module/hooks/useWidth.js.map +0 -1
  372. package/build/typescript/Carousel/CarouselNative.d.ts +0 -3
  373. package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
  374. package/build/typescript/Carousel/index.native.d.ts +0 -1
  375. package/build/typescript/Carousel/utils.d.ts +0 -6
  376. package/build/typescript/hooks/useWidth.d.ts +0 -2
  377. package/src/Carousel/CarouselNative.tsx +0 -67
  378. package/src/Carousel/CarouselWeb.tsx +0 -222
  379. package/src/Carousel/index.native.ts +0 -1
  380. package/src/Carousel/utils.ts +0 -11
  381. package/src/hooks/useWidth.ts +0 -17
@@ -0,0 +1,107 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import { InternalContext } from '../components';
4
+
5
+ const OVERSCROLL_FRICTION_FACTOR = 4;
6
+
7
+ export default function useItemInterpolation(index: number): Animated.AnimatedInterpolation {
8
+ const {
9
+ itemWidth,
10
+ data,
11
+ globalInterpolation,
12
+ loop,
13
+ } = useContext(InternalContext);
14
+
15
+ const numberOfData = data.length;
16
+
17
+ const interpolationConfigOnLoop = useMemo<Animated.InterpolationConfigType>(() => {
18
+ const lastIndex = numberOfData - 1;
19
+ const maxWidth = Math.abs(itemWidth * numberOfData);
20
+ const halfOfItemWidth = 0.5 * itemWidth;
21
+
22
+ const positiveCount = Math.round(lastIndex / 2);
23
+ const startPosition = index > positiveCount
24
+ ? (index - numberOfData) * itemWidth
25
+ : itemWidth * index;
26
+
27
+ const max = positiveCount * itemWidth;
28
+ const min = -((lastIndex - positiveCount) * itemWidth);
29
+
30
+ const inputRange = [
31
+ -maxWidth,
32
+ min - halfOfItemWidth - startPosition - Number.MIN_VALUE,
33
+ min - halfOfItemWidth - startPosition,
34
+ 0,
35
+ max + halfOfItemWidth - startPosition,
36
+ max + halfOfItemWidth - startPosition + Number.MIN_VALUE,
37
+ maxWidth,
38
+ ];
39
+
40
+ const outputRange = [
41
+ startPosition,
42
+ max + halfOfItemWidth - Number.MIN_VALUE,
43
+ min - halfOfItemWidth,
44
+ startPosition,
45
+ max + halfOfItemWidth,
46
+ min - halfOfItemWidth + Number.MIN_VALUE,
47
+ startPosition,
48
+ ];
49
+
50
+ return {
51
+ inputRange,
52
+ outputRange,
53
+ extrapolate: 'clamp',
54
+ };
55
+ }, [
56
+ index,
57
+ itemWidth,
58
+ numberOfData,
59
+ ]);
60
+
61
+ const interpolationConfigOnNoLoop = useMemo<Animated.InterpolationConfigType>(() => {
62
+ const lastIndex = numberOfData - 1;
63
+ const maxWidth = itemWidth * lastIndex;
64
+ const startPosition = itemWidth * index;
65
+ const friction = itemWidth / OVERSCROLL_FRICTION_FACTOR;
66
+
67
+ const inputRange = [
68
+ -(maxWidth + itemWidth), // overscroll
69
+ -maxWidth,
70
+ 0,
71
+ itemWidth, // overscroll
72
+ ];
73
+
74
+ const outputRange = [
75
+ -maxWidth + startPosition - friction,
76
+ -maxWidth + startPosition,
77
+ startPosition,
78
+ startPosition + friction,
79
+ ];
80
+
81
+ return {
82
+ inputRange,
83
+ outputRange,
84
+ extrapolate: 'clamp',
85
+ };
86
+ }, [
87
+ index,
88
+ itemWidth,
89
+ numberOfData,
90
+ ]);
91
+
92
+ return useMemo(() => {
93
+ const interpolationConfig = loop
94
+ ? interpolationConfigOnLoop
95
+ : interpolationConfigOnNoLoop;
96
+
97
+ const offsetX = globalInterpolation.interpolate(interpolationConfig);
98
+
99
+ return Animated.divide(offsetX, itemWidth);
100
+ }, [
101
+ globalInterpolation,
102
+ interpolationConfigOnLoop,
103
+ interpolationConfigOnNoLoop,
104
+ itemWidth,
105
+ loop,
106
+ ]);
107
+ };
@@ -0,0 +1,107 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import type { ItemVisibilityStore, VisibleIndexRanges } from '../types';
3
+
4
+ export interface Parameters {
5
+ currentIndex: number;
6
+ numberOfData: number;
7
+ windowSize: number;
8
+ }
9
+
10
+ class SimpleItemVisibilityStore implements ItemVisibilityStore {
11
+
12
+ private store: VisibleIndexRanges;
13
+
14
+ constructor(initialValue: VisibleIndexRanges) {
15
+ this.store = initialValue;
16
+ }
17
+
18
+ private listeners: Array<(ranges: VisibleIndexRanges) => void> = [];
19
+
20
+ subscribe(listener: (ranges: VisibleIndexRanges) => void) {
21
+ this.listeners.push(listener);
22
+
23
+ listener(this.store);
24
+
25
+ return () => {
26
+ const index = this.listeners.indexOf(listener);
27
+ this.listeners.splice(index, 1);
28
+ };
29
+ }
30
+
31
+ dispatch(ranges: VisibleIndexRanges): void {
32
+ this.store = ranges;
33
+ for (const id in this.listeners) {
34
+ const listener = this.listeners[id];
35
+ listener?.(ranges);
36
+ }
37
+ }
38
+
39
+ removeAllListeners(): void {
40
+ this.listeners.splice(0, this.listeners.length);
41
+ }
42
+
43
+ }
44
+
45
+ function normalize(windowSize: number, numberOfData: number): number {
46
+ if (windowSize <= 0) {
47
+ return numberOfData;
48
+ }
49
+ if (windowSize > 0 && windowSize % 2 === 0) {
50
+ return windowSize + 1;
51
+ }
52
+ return windowSize;
53
+ }
54
+
55
+ function mod(value: number, modulo: number): number {
56
+ return ((value % modulo) + modulo) % modulo;
57
+ }
58
+
59
+ function makeVisibleIndexRanges(numberOfData: number, windowSize: number, index: number): VisibleIndexRanges {
60
+ const ws = normalize(windowSize, numberOfData);
61
+
62
+ const firstIndex = 0;
63
+ const lastIndex = numberOfData - 1;
64
+ const halfNumberOfAdjacent = Math.floor(ws / 2);
65
+
66
+ const leftSide = index - halfNumberOfAdjacent;
67
+ const rightSide = index + halfNumberOfAdjacent;
68
+
69
+ const leftRanges = leftSide >= 0
70
+ ? [[leftSide, index]]
71
+ : [[firstIndex, index], [mod(leftSide, numberOfData), lastIndex]];
72
+
73
+ const rightRanges = rightSide < numberOfData
74
+ ? [[index, rightSide]]
75
+ : [[index, lastIndex], [firstIndex, mod(rightSide, numberOfData)]];
76
+
77
+ // @ts-ignore
78
+ return [
79
+ ...leftRanges,
80
+ ...rightRanges,
81
+ ];
82
+ }
83
+
84
+ export default function useItemVisibilityStore(params: Parameters): ItemVisibilityStore {
85
+ const {
86
+ currentIndex,
87
+ numberOfData,
88
+ windowSize,
89
+ } = params;
90
+
91
+ const [initialRange] = useState(() => makeVisibleIndexRanges(numberOfData, windowSize, currentIndex));
92
+ const store = useRef(new SimpleItemVisibilityStore(initialRange)).current;
93
+
94
+ useEffect(() => {
95
+ const newRanges = makeVisibleIndexRanges(numberOfData, windowSize, currentIndex);
96
+
97
+ store.dispatch(newRanges);
98
+ }, [currentIndex, numberOfData, windowSize]);
99
+
100
+ useEffect(() => {
101
+ return () => {
102
+ store.removeAllListeners();
103
+ };
104
+ }, []);
105
+
106
+ return store;
107
+ };
@@ -0,0 +1,26 @@
1
+ import { useMemo } from 'react';
2
+
3
+ export default function useLoopedData<ItemT>(
4
+ originalData: ReadonlyArray<ItemT>,
5
+ loop: boolean,
6
+ ): ReadonlyArray<ItemT> {
7
+ return useMemo(() => {
8
+ if (!loop) {
9
+ return originalData;
10
+ }
11
+
12
+ const numberOfData = originalData.length;
13
+
14
+ if (numberOfData === 1) {
15
+ const [first] = originalData;
16
+ return [first, first, first];
17
+ }
18
+
19
+ if (numberOfData === 2) {
20
+ const [first, second] = originalData;
21
+ return [first, second, first, second];
22
+ }
23
+
24
+ return originalData;
25
+ }, [originalData, loop]);
26
+ };
@@ -0,0 +1,148 @@
1
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
2
+ import { Animated, Platform } from 'react-native';
3
+ import type { CreateScrollAnimation, GetCurrentIndex, PagingDirection, StartPagingAnimation } from '../types';
4
+
5
+ export interface PagingAnimationConfig {
6
+ controlledTx: Animated.Value;
7
+ createScrollAnimation: CreateScrollAnimation;
8
+ getCurrentIndex: GetCurrentIndex;
9
+ itemWidth: number;
10
+ lastIndex: number;
11
+ loop: boolean;
12
+ numberOfData: number;
13
+ offsetTx: Animated.Value;
14
+ }
15
+
16
+ export interface UsePagingAnimation {
17
+ finalizeAnimation: () => void;
18
+ globalInterpolation: Animated.AnimatedInterpolation;
19
+ startAnimation: StartPagingAnimation;
20
+ }
21
+
22
+ function directionToValue(itemWidth: number) {
23
+ return function (direction: PagingDirection): number {
24
+ switch (direction) {
25
+ case 'next':
26
+ return -itemWidth;
27
+ case 'prev':
28
+ return itemWidth;
29
+ case 'stay':
30
+ return 0;
31
+ }
32
+ };
33
+ }
34
+
35
+ export default function usePagingAnimation(config: PagingAnimationConfig): UsePagingAnimation {
36
+ const {
37
+ controlledTx,
38
+ createScrollAnimation,
39
+ getCurrentIndex,
40
+ itemWidth,
41
+ lastIndex,
42
+ loop,
43
+ numberOfData,
44
+ offsetTx,
45
+ } = config;
46
+
47
+ const animationRef = useRef<Animated.CompositeAnimation | null>(null);
48
+ const toValueRef = useRef<number>(0);
49
+
50
+ const globalInterpolation = useMemo(
51
+ () => Animated.add(controlledTx, offsetTx),
52
+ [controlledTx, offsetTx],
53
+ );
54
+
55
+ useEffect(() => {
56
+ const subscriptionId = controlledTx.addListener((value) => {
57
+ const currentTx = value.value;
58
+
59
+ // Prevent infinite loop
60
+ if (currentTx !== 0) {
61
+ const maxWidth = numberOfData * itemWidth;
62
+
63
+ if (Math.abs(Math.round(currentTx)) === Math.round(maxWidth)) {
64
+ // reset position
65
+ controlledTx.setValue(0);
66
+ }
67
+ }
68
+ });
69
+
70
+ return () => {
71
+ controlledTx.removeListener(subscriptionId);
72
+ };
73
+ }, [numberOfData, itemWidth]);
74
+
75
+ const finalizeAnimation = useCallback(() => {
76
+ const stopUnfinishedSnapAnimation = () => {
77
+ if (animationRef.current) {
78
+ animationRef.current?.stop();
79
+ animationRef.current = null;
80
+ }
81
+ };
82
+
83
+ const resetBoundary = () => {
84
+ controlledTx.setOffset(toValueRef.current);
85
+ controlledTx.flattenOffset();
86
+
87
+ // FIXME: react-native-web bug maybe?
88
+ // `AnimatedValue.flattenOffset()` does not trigger any event listener.
89
+ // Accessing value directly via `_value` is dangerous but working on web (`useNativeDriver` always false).
90
+ // So setting same value with `value.setValue(value._value)` will trigger event listener.
91
+ if (Platform.OS === 'web') {
92
+ // @ts-ignore
93
+ controlledTx.setValue(controlledTx._value);
94
+ }
95
+
96
+ offsetTx.setValue(0);
97
+ toValueRef.current = 0;
98
+ };
99
+
100
+ stopUnfinishedSnapAnimation();
101
+
102
+ resetBoundary();
103
+ }, [controlledTx]);
104
+
105
+ const startAnimation = useCallback((direction: PagingDirection, isGesture: boolean = false) => {
106
+ const getToValueByDirection = directionToValue(itemWidth);
107
+
108
+ const currentIndex = getCurrentIndex();
109
+
110
+ const computeToValueOnNoLoop = (): number => {
111
+ if (currentIndex === 0 && direction === 'prev') {
112
+ return isGesture
113
+ ? getToValueByDirection('stay')
114
+ : -lastIndex * itemWidth; // last position
115
+ } else if (currentIndex === lastIndex && direction === 'next') {
116
+ return isGesture
117
+ ? getToValueByDirection('stay')
118
+ : lastIndex * itemWidth; // first position
119
+ }
120
+ return getToValueByDirection(direction);
121
+ };
122
+
123
+ const toValue = loop ? getToValueByDirection(direction) : computeToValueOnNoLoop();
124
+ const animation = createScrollAnimation(offsetTx, toValue);
125
+
126
+ animationRef.current = animation;
127
+ toValueRef.current = toValue;
128
+
129
+ animation.start(({ finished }) => {
130
+ if (finished) {
131
+ finalizeAnimation();
132
+ }
133
+ });
134
+ }, [
135
+ createScrollAnimation,
136
+ getCurrentIndex,
137
+ finalizeAnimation,
138
+ itemWidth,
139
+ lastIndex,
140
+ loop,
141
+ ]);
142
+
143
+ return {
144
+ globalInterpolation,
145
+ finalizeAnimation,
146
+ startAnimation,
147
+ };
148
+ };
@@ -1,2 +1,4 @@
1
- export { default } from './CarouselWeb';
2
- export type { default as CarouselProps } from './CarouselProps';
1
+ export { default } from './Carousel';
2
+ export type { default as CarouselProps } from './CarouselProps';
3
+ export type { CarouselInstance } from './types';
4
+ export { normalItemStyleFactory, parallaxItemStyleFactory } from './animation';
@@ -0,0 +1,67 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { Animated, ViewProps } from 'react-native';
3
+
4
+ const directions = ['next', 'prev', 'stay'] as const;
5
+
6
+ export type PagingDirection = (typeof directions)[number];
7
+
8
+ export interface RenderItem<T> {
9
+ (info: { item: T, index: number, interpolation: Animated.AnimatedInterpolation }): ReactElement | null;
10
+ }
11
+
12
+ export interface CreateScrollAnimation {
13
+ (aValue: Animated.AnimatedValue, toValue: number): Animated.CompositeAnimation;
14
+ }
15
+
16
+ export interface CreateItemStyle {
17
+ (itemInterpolation: Animated.AnimatedInterpolation, itemWidth: number): Animated.AnimatedProps<ViewProps['style']>;
18
+ }
19
+
20
+ export interface GetCurrentIndex {
21
+ (): number;
22
+ }
23
+
24
+ export interface IndexController {
25
+ currentIndex: number;
26
+ getCurrentIndex: GetCurrentIndex;
27
+ lastIndex: number;
28
+ monitorElement: ReactElement;
29
+ }
30
+
31
+ export interface StartPagingAnimation {
32
+ (direction: PagingDirection, isGesture?: boolean): void;
33
+ }
34
+
35
+ export type VisibleIndexRanges = Array<[number, number]>;
36
+
37
+ export interface StoreSubscription {
38
+ (): void;
39
+ }
40
+
41
+ export interface ItemVisibilityStore {
42
+ dispatch: (ranges: VisibleIndexRanges) => void;
43
+ subscribe: (listener: (ranges: VisibleIndexRanges) => void) => StoreSubscription;
44
+ removeAllListeners: () => void;
45
+ }
46
+
47
+ export interface AutoplayController {
48
+ pause: () => void;
49
+ resume: () => void;
50
+ }
51
+
52
+ export interface CarouselInstance {
53
+ /**
54
+ * Scroll to next visible item.
55
+ */
56
+ next: () => void;
57
+
58
+ /**
59
+ * Scroll to previous visible item.
60
+ */
61
+ prev: () => void;
62
+
63
+ /**
64
+ * Get current visible item index.
65
+ */
66
+ getCurrentIndex: GetCurrentIndex;
67
+ }
@@ -82,8 +82,8 @@ export default function DateTimePicker(props: DateTimePickerProps) {
82
82
  />
83
83
  )}
84
84
  theme={{
85
- backgroundColor: theme.palette.background.default,
86
- calendarBackground: theme.palette.background.default,
85
+ backgroundColor: theme.palette.paper.default,
86
+ calendarBackground: theme.palette.paper.default,
87
87
  dayTextColor: theme.palette.text.primary,
88
88
  textDisabledColor: theme.palette.text.hint,
89
89
  }}
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { StyleSheet, View } from 'react-native';
3
- import Animated from 'react-native-reanimated';
3
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
4
4
  import type FlipCardProps from './FlipCardProps';
5
5
 
6
6
  const styles = StyleSheet.create({
@@ -27,9 +27,9 @@ export default function FlipCard(props: FlipCardProps) {
27
27
  style,
28
28
  } = props;
29
29
 
30
- const sharedAngle = Animated.useSharedValue(0);
30
+ const sharedAngle = useSharedValue(0);
31
31
 
32
- const animatedFrontCardStyle = Animated.useAnimatedStyle(() => {
32
+ const animatedFrontCardStyle = useAnimatedStyle(() => {
33
33
  return {
34
34
  zIndex: sharedAngle.value < Z_INDEX_CHANGE_ANGLE ? 2 : 1,
35
35
  transform: [
@@ -37,9 +37,9 @@ export default function FlipCard(props: FlipCardProps) {
37
37
  { rotateX: `${sharedAngle.value}deg` },
38
38
  ],
39
39
  };
40
- });
40
+ }, []);
41
41
 
42
- const animatedBackCardStyle = Animated.useAnimatedStyle(() => {
42
+ const animatedBackCardStyle = useAnimatedStyle(() => {
43
43
  return {
44
44
  zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,
45
45
  transform: [
@@ -47,11 +47,11 @@ export default function FlipCard(props: FlipCardProps) {
47
47
  { rotateX: `${(sharedAngle.value + 180)}deg` },
48
48
  ],
49
49
  };
50
- });
50
+ }, []);
51
51
 
52
52
  useEffect(() => {
53
53
  sharedAngle.value = 0;
54
- sharedAngle.value = Animated.withTiming(180, { duration: 500 });
54
+ sharedAngle.value = withTiming(180, { duration: 500 });
55
55
  }, [reanimationKey]);
56
56
 
57
57
  return (
@@ -65,4 +65,4 @@ export default function FlipCard(props: FlipCardProps) {
65
65
  </Animated.View>
66
66
  </View>
67
67
  );
68
- };
68
+ };
@@ -1,36 +1,110 @@
1
- import React from 'react';
2
- import { View } from 'react-native';
1
+ import React, { memo, useMemo, useState } from 'react';
2
+ import { Platform, View } from 'react-native';
3
+ import { runOnJS, useAnimatedReaction } from 'react-native-reanimated';
4
+ import { StyleSheet } from '@fountain-ui/core';
3
5
  import type { PageProps } from './ViewPagerProps';
6
+ import PageStateContext from './PageStateContext';
4
7
 
5
- const Page = function Page(props: PageProps) {
6
- const { isVisible, ...otherProps } = props;
8
+ const styles = StyleSheet.create({
9
+ fill: { width: '100%', height: '100%' },
10
+ none: { display: 'none' },
11
+ });
7
12
 
8
- return (
9
- <View
10
- collapsable={false}
11
- {...otherProps}
12
- />
13
+ interface InternalPageState {
14
+ isActive: boolean;
15
+ isLoaded: boolean;
16
+ }
17
+
18
+ function Page(props: PageProps) {
19
+ const {
20
+ index,
21
+ children,
22
+ loading,
23
+ offscreenPageRerenderLimit,
24
+ sharedIndex,
25
+ } = props;
26
+
27
+ const assumeInitialPageState = (): InternalPageState => {
28
+ const activeIndex = sharedIndex.value;
29
+
30
+ const isActive = index === activeIndex;
31
+
32
+ if (loading === 'eager') {
33
+ return { isActive, isLoaded: true };
34
+ }
35
+
36
+ const isLoaded = index >= activeIndex - offscreenPageRerenderLimit
37
+ && index <= activeIndex + offscreenPageRerenderLimit;
38
+
39
+ return { isActive, isLoaded };
40
+ };
41
+
42
+ const [pageState, setPageState] = useState<InternalPageState>(assumeInitialPageState);
43
+
44
+ const content = pageState.isLoaded ? children : null;
45
+
46
+ const onActiveStateChange = (isActive: boolean) => {
47
+ setPageState(prevState => ({
48
+ ...prevState,
49
+ isActive,
50
+ isLoaded: isActive || prevState.isLoaded,
51
+ }));
52
+ };
53
+
54
+ const onBecomeNeighbor = () => {
55
+ setPageState(prevState => ({
56
+ ...prevState,
57
+ isLoaded: true,
58
+ }));
59
+ };
60
+
61
+ useAnimatedReaction(
62
+ () => {
63
+ const activeIndex = sharedIndex.value;
64
+
65
+ const isActive = index === activeIndex;
66
+
67
+ const shouldRerender = index >= activeIndex - offscreenPageRerenderLimit
68
+ && index <= activeIndex + offscreenPageRerenderLimit;
69
+
70
+ const becomeNeighbor = shouldRerender && !isActive;
71
+
72
+ return { isActive, becomeNeighbor };
73
+ },
74
+ (nextState, prevState) => {
75
+ if (nextState.isActive !== prevState?.isActive) {
76
+ runOnJS(onActiveStateChange)(nextState.isActive);
77
+ } else if (nextState.becomeNeighbor) {
78
+ runOnJS(onBecomeNeighbor)();
79
+ }
80
+ },
81
+ [index],
13
82
  );
14
- };
15
83
 
16
- export default React.memo(Page, (prevProps, nextProps) => {
17
- if (prevProps.children === null && nextProps.children === null) {
18
- return true;
19
- }
84
+ const contextValue = useMemo(() => ({
85
+ isActive: pageState.isActive,
86
+ }), [pageState.isActive]);
20
87
 
21
- // isVisible is an important condition for determining memos on the web.
22
- // Reference ViewPagerWeb's return.
23
- if (prevProps.isVisible !== nextProps.isVisible) {
24
- return false;
25
- }
88
+ const style = Platform.OS === 'web'
89
+ ? (pageState.isActive ? StyleSheet.absoluteFill : styles.none)
90
+ : styles.fill;
26
91
 
27
- if (nextProps.isVisible || nextProps.isNeighbor) {
28
- return false;
29
- }
92
+ return (
93
+ <View
94
+ collapsable={false}
95
+ style={style}
96
+ >
97
+ <PageStateContext.Provider value={contextValue}>
98
+ {content}
99
+ </PageStateContext.Provider>
100
+ </View>
101
+ );
102
+ }
30
103
 
104
+ export default memo(Page, (prevProps, nextProps) => {
31
105
  if (prevProps.rerenderKey !== nextProps.rerenderKey) {
32
106
  return false;
33
107
  }
34
108
 
35
- return prevProps.children !== null && nextProps.children !== null;
109
+ return prevProps.index !== nextProps.index;
36
110
  });
@@ -0,0 +1,15 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ interface PageState {
4
+ isActive: boolean;
5
+ }
6
+
7
+ const initialPageState: Readonly<PageState> = { isActive: false };
8
+
9
+ const PageStateContext = createContext<PageState>(initialPageState);
10
+
11
+ export const useViewPagerPageState = () => {
12
+ return useContext(PageStateContext);
13
+ };
14
+
15
+ export default PageStateContext;