@fountain-ui/lab 2.0.0-beta.5 → 2.0.0-beta.50

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 (517) 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 +28 -5
  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 +26 -15
  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/BottomSheet/useDynamicSnapPoints.js +65 -0
  15. package/build/commonjs/BottomSheet/useDynamicSnapPoints.js.map +1 -0
  16. package/build/commonjs/Carousel/Carousel.js +130 -0
  17. package/build/commonjs/Carousel/Carousel.js.map +1 -0
  18. package/build/commonjs/Carousel/CarouselProps.js.map +1 -1
  19. package/build/commonjs/Carousel/animation/animationUtils.js +9 -0
  20. package/build/commonjs/Carousel/animation/animationUtils.js.map +1 -0
  21. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js +15 -0
  22. package/build/commonjs/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  23. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js +20 -0
  24. package/build/commonjs/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  25. package/build/commonjs/Carousel/animation/index.js +40 -0
  26. package/build/commonjs/Carousel/animation/index.js.map +1 -0
  27. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js +27 -0
  28. package/build/commonjs/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  29. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js +65 -0
  30. package/build/commonjs/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  31. package/build/commonjs/Carousel/components/InternalContext.js +29 -0
  32. package/build/commonjs/Carousel/components/InternalContext.js.map +1 -0
  33. package/build/commonjs/Carousel/components/ItemView.js +66 -0
  34. package/build/commonjs/Carousel/components/ItemView.js.map +1 -0
  35. package/build/commonjs/Carousel/components/RootView.js +86 -0
  36. package/build/commonjs/Carousel/components/RootView.js.map +1 -0
  37. package/build/commonjs/Carousel/components/ScrollViewGesture.js +82 -0
  38. package/build/commonjs/Carousel/components/ScrollViewGesture.js.map +1 -0
  39. package/build/commonjs/Carousel/components/index.js +40 -0
  40. package/build/commonjs/Carousel/components/index.js.map +1 -0
  41. package/build/commonjs/Carousel/components/useItemInterpolation.js +65 -0
  42. package/build/commonjs/Carousel/components/useItemInterpolation.js.map +1 -0
  43. package/build/commonjs/Carousel/hooks/index.js +48 -0
  44. package/build/commonjs/Carousel/hooks/index.js.map +1 -0
  45. package/build/commonjs/Carousel/hooks/useAutoplayController.js +58 -0
  46. package/build/commonjs/Carousel/hooks/useAutoplayController.js.map +1 -0
  47. package/build/commonjs/Carousel/hooks/useIndexController.js +55 -0
  48. package/build/commonjs/Carousel/hooks/useIndexController.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/usePagingAnimator.js +202 -0
  54. package/build/commonjs/Carousel/hooks/usePagingAnimator.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/tick.js +16 -0
  58. package/build/commonjs/Carousel/tick.js.map +1 -0
  59. package/build/commonjs/Carousel/types.js +8 -0
  60. package/build/commonjs/Carousel/types.js.map +1 -0
  61. package/build/commonjs/ComicViewer/ComicViewer.js +248 -88
  62. package/build/commonjs/ComicViewer/ComicViewer.js.map +1 -1
  63. package/build/commonjs/ComicViewer/ComicViewerProps.js.map +1 -1
  64. package/build/commonjs/ComicViewer/EncodedTile.js +10 -0
  65. package/build/commonjs/ComicViewer/EncodedTile.js.map +1 -0
  66. package/build/commonjs/ComicViewer/FastScroll.js +162 -0
  67. package/build/commonjs/ComicViewer/FastScroll.js.map +1 -0
  68. package/build/commonjs/ComicViewer/{ComicViewerItemProps.js → FastScrollProps.js} +1 -1
  69. package/build/commonjs/ComicViewer/FastScrollProps.js.map +1 -0
  70. package/build/commonjs/ComicViewer/ReloadButton.js +48 -0
  71. package/build/commonjs/ComicViewer/ReloadButton.js.map +1 -0
  72. package/build/commonjs/ComicViewer/ViewerItem.js +51 -58
  73. package/build/commonjs/ComicViewer/ViewerItem.js.map +1 -1
  74. package/build/commonjs/ComicViewer/index.js.map +1 -1
  75. package/build/commonjs/ComicViewer/util.js +27 -0
  76. package/build/commonjs/ComicViewer/util.js.map +1 -0
  77. package/build/commonjs/DateTimePicker/DateTimePicker.js.map +1 -1
  78. package/build/commonjs/DateTimePicker/DateTimePickerProps.js.map +1 -1
  79. package/build/commonjs/DateTimePicker/DateTimePickerProvider.js.map +1 -1
  80. package/build/commonjs/DateTimePicker/YearPicker.js +21 -17
  81. package/build/commonjs/DateTimePicker/YearPicker.js.map +1 -1
  82. package/build/commonjs/DateTimePicker/index.js +4 -4
  83. package/build/commonjs/DateTimePicker/index.js.map +1 -1
  84. package/build/commonjs/DateTimePicker/utils.js +2 -1
  85. package/build/commonjs/DateTimePicker/utils.js.map +1 -1
  86. package/build/commonjs/FlipCard/FlipCard.js +7 -13
  87. package/build/commonjs/FlipCard/FlipCard.js.map +1 -1
  88. package/build/commonjs/FlipCard/FlipCardProps.js.map +1 -1
  89. package/build/commonjs/FlipCard/index.js.map +1 -1
  90. package/build/commonjs/StatusBarProvider/Provider.js +1 -1
  91. package/build/commonjs/StatusBarProvider/Provider.js.map +1 -1
  92. package/build/commonjs/StatusBarProvider/StatusBarProvider.js.map +1 -1
  93. package/build/commonjs/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
  94. package/build/commonjs/StatusBarProvider/index.js.map +1 -1
  95. package/build/commonjs/ViewPager/FluxContext.js +13 -0
  96. package/build/commonjs/ViewPager/FluxContext.js.map +1 -0
  97. package/build/commonjs/ViewPager/InternalContext.js +17 -0
  98. package/build/commonjs/ViewPager/InternalContext.js.map +1 -0
  99. package/build/commonjs/ViewPager/PageStateContext.js +16 -0
  100. package/build/commonjs/ViewPager/PageStateContext.js.map +1 -0
  101. package/build/commonjs/ViewPager/ViewPager.js +81 -0
  102. package/build/commonjs/ViewPager/ViewPager.js.map +1 -0
  103. package/build/commonjs/ViewPager/ViewPager.native.js +150 -0
  104. package/build/commonjs/ViewPager/ViewPager.native.js.map +1 -0
  105. package/build/commonjs/ViewPager/ViewPagerProps.js.map +1 -1
  106. package/build/commonjs/ViewPager/components/ChildrenMemoizedPage.js +122 -0
  107. package/build/commonjs/ViewPager/components/ChildrenMemoizedPage.js.map +1 -0
  108. package/build/commonjs/ViewPager/components/FluxStoreProvider.js +37 -0
  109. package/build/commonjs/ViewPager/components/FluxStoreProvider.js.map +1 -0
  110. package/build/commonjs/ViewPager/components/index.js +24 -0
  111. package/build/commonjs/ViewPager/components/index.js.map +1 -0
  112. package/build/commonjs/ViewPager/hooks/index.js +64 -0
  113. package/build/commonjs/ViewPager/hooks/index.js.map +1 -0
  114. package/build/commonjs/ViewPager/hooks/useDispatch.js +22 -0
  115. package/build/commonjs/ViewPager/hooks/useDispatch.js.map +1 -0
  116. package/build/commonjs/ViewPager/hooks/useEagerState.js +24 -0
  117. package/build/commonjs/ViewPager/hooks/useEagerState.js.map +1 -0
  118. package/build/commonjs/ViewPager/hooks/useForceRender.js +16 -0
  119. package/build/commonjs/ViewPager/hooks/useForceRender.js.map +1 -0
  120. package/build/commonjs/ViewPager/hooks/useLazyState.js +45 -0
  121. package/build/commonjs/ViewPager/hooks/useLazyState.js.map +1 -0
  122. package/build/commonjs/ViewPager/hooks/usePageStore.js +35 -0
  123. package/build/commonjs/ViewPager/hooks/usePageStore.js.map +1 -0
  124. package/build/commonjs/ViewPager/hooks/useStore.js +26 -0
  125. package/build/commonjs/ViewPager/hooks/useStore.js.map +1 -0
  126. package/build/commonjs/ViewPager/hooks/useViewPagerPageState.js +19 -0
  127. package/build/commonjs/ViewPager/hooks/useViewPagerPageState.js.map +1 -0
  128. package/build/commonjs/ViewPager/index.js +42 -2
  129. package/build/commonjs/ViewPager/index.js.map +1 -1
  130. package/build/commonjs/ViewPager/types.js +2 -0
  131. package/build/commonjs/ViewPager/types.js.map +1 -0
  132. package/build/commonjs/ViewPager/utils.js +12 -43
  133. package/build/commonjs/ViewPager/utils.js.map +1 -1
  134. package/build/commonjs/ViewabilityTrackerView/Viewability.js +2 -0
  135. package/build/commonjs/ViewabilityTrackerView/Viewability.js.map +1 -0
  136. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js +45 -0
  137. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  138. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  139. package/build/commonjs/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  140. package/build/commonjs/{Carousel/index.native.js → ViewabilityTrackerView/index.js} +3 -3
  141. package/build/commonjs/ViewabilityTrackerView/index.js.map +1 -0
  142. package/build/commonjs/ViewabilityTrackerView/measureViewability.js +42 -0
  143. package/build/commonjs/ViewabilityTrackerView/measureViewability.js.map +1 -0
  144. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js +88 -0
  145. package/build/commonjs/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  146. package/build/commonjs/hooks/index.js +16 -0
  147. package/build/commonjs/hooks/index.js.map +1 -1
  148. package/build/commonjs/hooks/useAppbarStyles.js.map +1 -1
  149. package/build/commonjs/hooks/useDeferredExecutor.js +45 -0
  150. package/build/commonjs/hooks/useDeferredExecutor.js.map +1 -0
  151. package/build/commonjs/hooks/useElevationStyle.js.map +1 -1
  152. package/build/commonjs/hooks/useHeight.js +7 -6
  153. package/build/commonjs/hooks/useHeight.js.map +1 -1
  154. package/build/commonjs/hooks/useIsMounted.js +22 -0
  155. package/build/commonjs/hooks/useIsMounted.js.map +1 -0
  156. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js +58 -61
  157. package/build/commonjs/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  158. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js +9 -11
  159. package/build/commonjs/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  160. package/build/commonjs/index.js +28 -7
  161. package/build/commonjs/index.js.map +1 -1
  162. package/build/module/AnimatedY/AnimatedY.js +11 -10
  163. package/build/module/AnimatedY/AnimatedY.js.map +1 -1
  164. package/build/module/AnimatedY/AnimatedYProps.js.map +1 -1
  165. package/build/module/AnimatedY/index.js.map +1 -1
  166. package/build/module/BottomSheet/BottomSheetNative.js +29 -7
  167. package/build/module/BottomSheet/BottomSheetNative.js.map +1 -1
  168. package/build/module/BottomSheet/BottomSheetProps.js.map +1 -1
  169. package/build/module/BottomSheet/BottomSheetWeb.js +24 -15
  170. package/build/module/BottomSheet/BottomSheetWeb.js.map +1 -1
  171. package/build/module/BottomSheet/TransparentBackdrop.js +1 -1
  172. package/build/module/BottomSheet/TransparentBackdrop.js.map +1 -1
  173. package/build/module/BottomSheet/index.js.map +1 -1
  174. package/build/module/BottomSheet/index.native.js.map +1 -1
  175. package/build/module/BottomSheet/useDynamicSnapPoints.js +52 -0
  176. package/build/module/BottomSheet/useDynamicSnapPoints.js.map +1 -0
  177. package/build/module/Carousel/Carousel.js +109 -0
  178. package/build/module/Carousel/Carousel.js.map +1 -0
  179. package/build/module/Carousel/CarouselProps.js.map +1 -1
  180. package/build/module/Carousel/animation/animationUtils.js +2 -0
  181. package/build/module/Carousel/animation/animationUtils.js.map +1 -0
  182. package/build/module/Carousel/animation/createDefaultItemStyle.js +3 -0
  183. package/build/module/Carousel/animation/createDefaultItemStyle.js.map +1 -0
  184. package/build/module/Carousel/animation/createDefaultScrollAnimation.js +11 -0
  185. package/build/module/Carousel/animation/createDefaultScrollAnimation.js.map +1 -0
  186. package/build/module/Carousel/animation/index.js +5 -0
  187. package/build/module/Carousel/animation/index.js.map +1 -0
  188. package/build/module/Carousel/animation/normalItemStyleFactory.js +18 -0
  189. package/build/module/Carousel/animation/normalItemStyleFactory.js.map +1 -0
  190. package/build/module/Carousel/animation/parallaxItemStyleFactory.js +55 -0
  191. package/build/module/Carousel/animation/parallaxItemStyleFactory.js.map +1 -0
  192. package/build/module/Carousel/components/InternalContext.js +19 -0
  193. package/build/module/Carousel/components/InternalContext.js.map +1 -0
  194. package/build/module/Carousel/components/ItemView.js +46 -0
  195. package/build/module/Carousel/components/ItemView.js.map +1 -0
  196. package/build/module/Carousel/components/RootView.js +65 -0
  197. package/build/module/Carousel/components/RootView.js.map +1 -0
  198. package/build/module/Carousel/components/ScrollViewGesture.js +68 -0
  199. package/build/module/Carousel/components/ScrollViewGesture.js.map +1 -0
  200. package/build/module/Carousel/components/index.js +5 -0
  201. package/build/module/Carousel/components/index.js.map +1 -0
  202. package/build/module/Carousel/components/useItemInterpolation.js +51 -0
  203. package/build/module/Carousel/components/useItemInterpolation.js.map +1 -0
  204. package/build/module/Carousel/hooks/index.js +6 -0
  205. package/build/module/Carousel/hooks/index.js.map +1 -0
  206. package/build/module/Carousel/hooks/useAutoplayController.js +48 -0
  207. package/build/module/Carousel/hooks/useAutoplayController.js.map +1 -0
  208. package/build/module/Carousel/hooks/useIndexController.js +44 -0
  209. package/build/module/Carousel/hooks/useIndexController.js.map +1 -0
  210. package/build/module/Carousel/hooks/useItemVisibilityStore.js +86 -0
  211. package/build/module/Carousel/hooks/useItemVisibilityStore.js.map +1 -0
  212. package/build/module/Carousel/hooks/useLoopedData.js +24 -0
  213. package/build/module/Carousel/hooks/useLoopedData.js.map +1 -0
  214. package/build/module/Carousel/hooks/usePagingAnimator.js +192 -0
  215. package/build/module/Carousel/hooks/usePagingAnimator.js.map +1 -0
  216. package/build/module/Carousel/index.js +2 -1
  217. package/build/module/Carousel/index.js.map +1 -1
  218. package/build/module/Carousel/tick.js +6 -0
  219. package/build/module/Carousel/tick.js.map +1 -0
  220. package/build/module/Carousel/types.js +4 -0
  221. package/build/module/Carousel/types.js.map +1 -0
  222. package/build/module/ComicViewer/ComicViewer.js +245 -88
  223. package/build/module/ComicViewer/ComicViewer.js.map +1 -1
  224. package/build/module/ComicViewer/ComicViewerProps.js.map +1 -1
  225. package/build/module/ComicViewer/EncodedTile.js +3 -0
  226. package/build/module/ComicViewer/EncodedTile.js.map +1 -0
  227. package/build/module/ComicViewer/FastScroll.js +141 -0
  228. package/build/module/ComicViewer/FastScroll.js.map +1 -0
  229. package/build/module/ComicViewer/FastScrollProps.js +2 -0
  230. package/build/module/ComicViewer/FastScrollProps.js.map +1 -0
  231. package/build/module/ComicViewer/ReloadButton.js +33 -0
  232. package/build/module/ComicViewer/ReloadButton.js.map +1 -0
  233. package/build/module/ComicViewer/ViewerItem.js +51 -59
  234. package/build/module/ComicViewer/ViewerItem.js.map +1 -1
  235. package/build/module/ComicViewer/index.js.map +1 -1
  236. package/build/module/ComicViewer/util.js +15 -0
  237. package/build/module/ComicViewer/util.js.map +1 -0
  238. package/build/module/DateTimePicker/DateTimePicker.js.map +1 -1
  239. package/build/module/DateTimePicker/DateTimePickerProps.js.map +1 -1
  240. package/build/module/DateTimePicker/DateTimePickerProvider.js.map +1 -1
  241. package/build/module/DateTimePicker/YearPicker.js +21 -17
  242. package/build/module/DateTimePicker/YearPicker.js.map +1 -1
  243. package/build/module/DateTimePicker/index.js.map +1 -1
  244. package/build/module/DateTimePicker/utils.js +2 -1
  245. package/build/module/DateTimePicker/utils.js.map +1 -1
  246. package/build/module/FlipCard/FlipCard.js +7 -7
  247. package/build/module/FlipCard/FlipCard.js.map +1 -1
  248. package/build/module/FlipCard/FlipCardProps.js.map +1 -1
  249. package/build/module/FlipCard/index.js.map +1 -1
  250. package/build/module/StatusBarProvider/Provider.js.map +1 -1
  251. package/build/module/StatusBarProvider/StatusBarProvider.js.map +1 -1
  252. package/build/module/StatusBarProvider/StatusBarProviderProps.js.map +1 -1
  253. package/build/module/StatusBarProvider/index.js.map +1 -1
  254. package/build/module/ViewPager/FluxContext.js +4 -0
  255. package/build/module/ViewPager/FluxContext.js.map +1 -0
  256. package/build/module/ViewPager/InternalContext.js +7 -0
  257. package/build/module/ViewPager/InternalContext.js.map +1 -0
  258. package/build/module/ViewPager/PageStateContext.js +7 -0
  259. package/build/module/ViewPager/PageStateContext.js.map +1 -0
  260. package/build/module/ViewPager/ViewPager.js +57 -0
  261. package/build/module/ViewPager/ViewPager.js.map +1 -0
  262. package/build/module/ViewPager/ViewPager.native.js +127 -0
  263. package/build/module/ViewPager/ViewPager.native.js.map +1 -0
  264. package/build/module/ViewPager/ViewPagerProps.js.map +1 -1
  265. package/build/module/ViewPager/components/ChildrenMemoizedPage.js +101 -0
  266. package/build/module/ViewPager/components/ChildrenMemoizedPage.js.map +1 -0
  267. package/build/module/ViewPager/components/FluxStoreProvider.js +20 -0
  268. package/build/module/ViewPager/components/FluxStoreProvider.js.map +1 -0
  269. package/build/module/ViewPager/components/index.js +3 -0
  270. package/build/module/ViewPager/components/index.js.map +1 -0
  271. package/build/module/ViewPager/hooks/index.js +8 -0
  272. package/build/module/ViewPager/hooks/index.js.map +1 -0
  273. package/build/module/ViewPager/hooks/useDispatch.js +10 -0
  274. package/build/module/ViewPager/hooks/useDispatch.js.map +1 -0
  275. package/build/module/ViewPager/hooks/useEagerState.js +12 -0
  276. package/build/module/ViewPager/hooks/useEagerState.js.map +1 -0
  277. package/build/module/ViewPager/hooks/useForceRender.js +7 -0
  278. package/build/module/ViewPager/hooks/useForceRender.js.map +1 -0
  279. package/build/module/ViewPager/hooks/useLazyState.js +30 -0
  280. package/build/module/ViewPager/hooks/useLazyState.js.map +1 -0
  281. package/build/module/ViewPager/hooks/usePageStore.js +25 -0
  282. package/build/module/ViewPager/hooks/usePageStore.js.map +1 -0
  283. package/build/module/ViewPager/hooks/useStore.js +14 -0
  284. package/build/module/ViewPager/hooks/useStore.js.map +1 -0
  285. package/build/module/ViewPager/hooks/useViewPagerPageState.js +7 -0
  286. package/build/module/ViewPager/hooks/useViewPagerPageState.js.map +1 -0
  287. package/build/module/ViewPager/index.js +3 -1
  288. package/build/module/ViewPager/index.js.map +1 -1
  289. package/build/module/ViewPager/types.js +2 -0
  290. package/build/module/ViewPager/types.js.map +1 -0
  291. package/build/module/ViewPager/utils.js +6 -33
  292. package/build/module/ViewPager/utils.js.map +1 -1
  293. package/build/module/ViewabilityTrackerView/Viewability.js +2 -0
  294. package/build/module/ViewabilityTrackerView/Viewability.js.map +1 -0
  295. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js +28 -0
  296. package/build/module/ViewabilityTrackerView/ViewabilityTrackerView.js.map +1 -0
  297. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js +2 -0
  298. package/build/module/ViewabilityTrackerView/ViewabilityTrackerViewProps.js.map +1 -0
  299. package/build/module/ViewabilityTrackerView/index.js +2 -0
  300. package/build/module/ViewabilityTrackerView/index.js.map +1 -0
  301. package/build/module/ViewabilityTrackerView/measureViewability.js +34 -0
  302. package/build/module/ViewabilityTrackerView/measureViewability.js.map +1 -0
  303. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js +73 -0
  304. package/build/module/ViewabilityTrackerView/useViewabilityTracker.js.map +1 -0
  305. package/build/module/hooks/index.js +2 -0
  306. package/build/module/hooks/index.js.map +1 -1
  307. package/build/module/hooks/useAppbarStyles.js.map +1 -1
  308. package/build/module/hooks/useDeferredExecutor.js +33 -0
  309. package/build/module/hooks/useDeferredExecutor.js.map +1 -0
  310. package/build/module/hooks/useElevationStyle.js.map +1 -1
  311. package/build/module/hooks/useHeight.js +4 -4
  312. package/build/module/hooks/useHeight.js.map +1 -1
  313. package/build/module/hooks/useIsMounted.js +13 -0
  314. package/build/module/hooks/useIsMounted.js.map +1 -0
  315. package/build/module/hooks/useUnstableCollapsibleAppBar.js +58 -45
  316. package/build/module/hooks/useUnstableCollapsibleAppBar.js.map +1 -1
  317. package/build/module/hooks/useUnstableToggleDisplayStyle.js +9 -7
  318. package/build/module/hooks/useUnstableToggleDisplayStyle.js.map +1 -1
  319. package/build/module/index.js +2 -0
  320. package/build/module/index.js.map +1 -1
  321. package/build/typescript/BottomSheet/BottomSheetProps.d.ts +18 -1
  322. package/build/typescript/BottomSheet/useDynamicSnapPoints.d.ts +12 -0
  323. package/build/typescript/Carousel/Carousel.d.ts +5 -0
  324. package/build/typescript/Carousel/CarouselProps.d.ts +33 -48
  325. package/build/typescript/Carousel/animation/animationUtils.d.ts +1 -0
  326. package/build/typescript/Carousel/animation/createDefaultItemStyle.d.ts +2 -0
  327. package/build/typescript/Carousel/animation/createDefaultScrollAnimation.d.ts +2 -0
  328. package/build/typescript/Carousel/animation/index.d.ts +4 -0
  329. package/build/typescript/Carousel/animation/normalItemStyleFactory.d.ts +2 -0
  330. package/build/typescript/Carousel/animation/parallaxItemStyleFactory.d.ts +9 -0
  331. package/build/typescript/Carousel/components/InternalContext.d.ts +14 -0
  332. package/build/typescript/Carousel/components/ItemView.d.ts +9 -0
  333. package/build/typescript/Carousel/components/RootView.d.ts +16 -0
  334. package/build/typescript/Carousel/components/ScrollViewGesture.d.ts +12 -0
  335. package/build/typescript/Carousel/components/index.d.ts +4 -0
  336. package/build/typescript/Carousel/components/useItemInterpolation.d.ts +2 -0
  337. package/build/typescript/Carousel/hooks/index.d.ts +5 -0
  338. package/build/typescript/Carousel/hooks/useAutoplayController.d.ts +7 -0
  339. package/build/typescript/Carousel/hooks/useIndexController.d.ts +10 -0
  340. package/build/typescript/Carousel/hooks/useItemVisibilityStore.d.ts +7 -0
  341. package/build/typescript/Carousel/hooks/useLoopedData.d.ts +1 -0
  342. package/build/typescript/Carousel/hooks/usePagingAnimator.d.ts +17 -0
  343. package/build/typescript/Carousel/index.d.ts +3 -1
  344. package/build/typescript/Carousel/tick.d.ts +2 -0
  345. package/build/typescript/Carousel/types.d.ts +91 -0
  346. package/build/typescript/ComicViewer/ComicViewer.d.ts +1 -1
  347. package/build/typescript/ComicViewer/ComicViewerProps.d.ts +56 -43
  348. package/build/typescript/ComicViewer/EncodedTile.d.ts +2 -0
  349. package/build/typescript/ComicViewer/FastScroll.d.ts +4 -0
  350. package/build/typescript/ComicViewer/FastScrollProps.d.ts +70 -0
  351. package/build/typescript/ComicViewer/ReloadButton.d.ts +7 -0
  352. package/build/typescript/ComicViewer/ViewerItem.d.ts +42 -7
  353. package/build/typescript/ComicViewer/index.d.ts +3 -2
  354. package/build/typescript/ComicViewer/util.d.ts +2 -0
  355. package/build/typescript/ViewPager/FluxContext.d.ts +5 -0
  356. package/build/typescript/ViewPager/InternalContext.d.ts +7 -0
  357. package/build/typescript/ViewPager/PageStateContext.d.ts +6 -0
  358. package/build/typescript/ViewPager/ViewPager.d.ts +5 -0
  359. package/build/typescript/ViewPager/ViewPager.native.d.ts +5 -0
  360. package/build/typescript/ViewPager/ViewPagerProps.d.ts +18 -29
  361. package/build/typescript/ViewPager/components/ChildrenMemoizedPage.d.ts +14 -0
  362. package/build/typescript/ViewPager/components/FluxStoreProvider.d.ts +6 -0
  363. package/build/typescript/ViewPager/components/index.d.ts +2 -0
  364. package/build/typescript/ViewPager/hooks/index.d.ts +7 -0
  365. package/build/typescript/ViewPager/hooks/useDispatch.d.ts +2 -0
  366. package/build/typescript/ViewPager/hooks/useEagerState.d.ts +1 -0
  367. package/build/typescript/ViewPager/hooks/useForceRender.d.ts +2 -0
  368. package/build/typescript/ViewPager/hooks/useLazyState.d.ts +2 -0
  369. package/build/typescript/ViewPager/hooks/usePageStore.d.ts +2 -0
  370. package/build/typescript/ViewPager/hooks/useStore.d.ts +2 -0
  371. package/build/typescript/ViewPager/hooks/useViewPagerPageState.d.ts +1 -0
  372. package/build/typescript/ViewPager/index.d.ts +4 -1
  373. package/build/typescript/ViewPager/types.d.ts +12 -0
  374. package/build/typescript/ViewPager/utils.d.ts +5 -20
  375. package/build/typescript/ViewabilityTrackerView/Viewability.d.ts +3 -0
  376. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerView.d.ts +3 -0
  377. package/build/typescript/ViewabilityTrackerView/ViewabilityTrackerViewProps.d.ts +22 -0
  378. package/build/typescript/ViewabilityTrackerView/index.d.ts +2 -0
  379. package/build/typescript/ViewabilityTrackerView/measureViewability.d.ts +11 -0
  380. package/build/typescript/ViewabilityTrackerView/useViewabilityTracker.d.ts +11 -0
  381. package/build/typescript/hooks/index.d.ts +2 -0
  382. package/build/typescript/hooks/useDeferredExecutor.d.ts +11 -0
  383. package/build/typescript/hooks/useIsMounted.d.ts +4 -0
  384. package/build/typescript/hooks/useUnstableCollapsibleAppBar.d.ts +2 -3
  385. package/build/typescript/hooks/useUnstableToggleDisplayStyle.d.ts +2 -2
  386. package/build/typescript/index.d.ts +2 -0
  387. package/package.json +13 -27
  388. package/src/AnimatedY/AnimatedY.tsx +13 -10
  389. package/src/BottomSheet/BottomSheetNative.tsx +30 -3
  390. package/src/BottomSheet/BottomSheetProps.ts +21 -1
  391. package/src/BottomSheet/BottomSheetWeb.tsx +32 -13
  392. package/src/BottomSheet/useDynamicSnapPoints.ts +73 -0
  393. package/src/Carousel/Carousel.tsx +135 -0
  394. package/src/Carousel/CarouselProps.ts +42 -53
  395. package/src/Carousel/animation/animationUtils.ts +1 -0
  396. package/src/Carousel/animation/createDefaultItemStyle.ts +3 -0
  397. package/src/Carousel/animation/createDefaultScrollAnimation.ts +13 -0
  398. package/src/Carousel/animation/index.ts +4 -0
  399. package/src/Carousel/animation/normalItemStyleFactory.ts +19 -0
  400. package/src/Carousel/animation/parallaxItemStyleFactory.ts +79 -0
  401. package/src/Carousel/components/InternalContext.ts +33 -0
  402. package/src/Carousel/components/ItemView.tsx +66 -0
  403. package/src/Carousel/components/RootView.tsx +79 -0
  404. package/src/Carousel/components/ScrollViewGesture.tsx +92 -0
  405. package/src/Carousel/components/index.ts +4 -0
  406. package/src/Carousel/components/useItemInterpolation.ts +107 -0
  407. package/src/Carousel/hooks/index.ts +5 -0
  408. package/src/Carousel/hooks/useAutoplayController.ts +57 -0
  409. package/src/Carousel/hooks/useIndexController.tsx +57 -0
  410. package/src/Carousel/hooks/useItemVisibilityStore.ts +107 -0
  411. package/src/Carousel/hooks/useLoopedData.ts +26 -0
  412. package/src/Carousel/hooks/usePagingAnimator.ts +255 -0
  413. package/src/Carousel/index.ts +4 -2
  414. package/src/Carousel/tick.ts +6 -0
  415. package/src/Carousel/types.ts +114 -0
  416. package/src/ComicViewer/ComicViewer.tsx +283 -104
  417. package/src/ComicViewer/ComicViewerProps.ts +60 -44
  418. package/src/ComicViewer/EncodedTile.ts +3 -0
  419. package/src/ComicViewer/FastScroll.tsx +158 -0
  420. package/src/ComicViewer/FastScrollProps.ts +83 -0
  421. package/src/ComicViewer/ReloadButton.tsx +36 -0
  422. package/src/ComicViewer/ViewerItem.tsx +97 -62
  423. package/src/ComicViewer/index.ts +8 -2
  424. package/src/ComicViewer/util.ts +15 -0
  425. package/src/FlipCard/FlipCard.tsx +8 -8
  426. package/src/ViewPager/FluxContext.ts +8 -0
  427. package/src/ViewPager/InternalContext.ts +13 -0
  428. package/src/ViewPager/PageStateContext.ts +11 -0
  429. package/src/ViewPager/ViewPager.native.tsx +150 -0
  430. package/src/ViewPager/ViewPager.tsx +69 -0
  431. package/src/ViewPager/ViewPagerProps.ts +20 -35
  432. package/src/ViewPager/components/ChildrenMemoizedPage.tsx +124 -0
  433. package/src/ViewPager/components/FluxStoreProvider.tsx +27 -0
  434. package/src/ViewPager/components/index.ts +2 -0
  435. package/src/ViewPager/hooks/index.ts +7 -0
  436. package/src/ViewPager/hooks/useDispatch.ts +11 -0
  437. package/src/ViewPager/hooks/useEagerState.ts +14 -0
  438. package/src/ViewPager/hooks/useForceRender.ts +7 -0
  439. package/src/ViewPager/hooks/useLazyState.ts +32 -0
  440. package/src/ViewPager/hooks/usePageStore.ts +30 -0
  441. package/src/ViewPager/hooks/useStore.ts +15 -0
  442. package/src/ViewPager/hooks/useViewPagerPageState.ts +6 -0
  443. package/src/ViewPager/index.ts +11 -2
  444. package/src/ViewPager/types.ts +15 -0
  445. package/src/ViewPager/utils.tsx +9 -56
  446. package/src/ViewabilityTrackerView/Viewability.ts +3 -0
  447. package/src/ViewabilityTrackerView/ViewabilityTrackerView.tsx +33 -0
  448. package/src/ViewabilityTrackerView/ViewabilityTrackerViewProps.ts +25 -0
  449. package/src/ViewabilityTrackerView/index.ts +2 -0
  450. package/src/ViewabilityTrackerView/measureViewability.ts +54 -0
  451. package/src/ViewabilityTrackerView/useViewabilityTracker.ts +85 -0
  452. package/src/hooks/index.ts +2 -0
  453. package/src/hooks/useDeferredExecutor.ts +46 -0
  454. package/src/hooks/useHeight.ts +3 -4
  455. package/src/hooks/useIsMounted.ts +19 -0
  456. package/src/hooks/useUnstableCollapsibleAppBar.ts +62 -45
  457. package/src/hooks/useUnstableToggleDisplayStyle.ts +8 -6
  458. package/src/index.ts +3 -0
  459. package/yarn-error.log +103 -0
  460. package/build/commonjs/Carousel/CarouselNative.js +0 -72
  461. package/build/commonjs/Carousel/CarouselNative.js.map +0 -1
  462. package/build/commonjs/Carousel/CarouselWeb.js +0 -237
  463. package/build/commonjs/Carousel/CarouselWeb.js.map +0 -1
  464. package/build/commonjs/Carousel/index.native.js.map +0 -1
  465. package/build/commonjs/Carousel/utils.js +0 -19
  466. package/build/commonjs/Carousel/utils.js.map +0 -1
  467. package/build/commonjs/ComicViewer/ComicViewerItemProps.js.map +0 -1
  468. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js +0 -49
  469. package/build/commonjs/ViewPager/ChildrenMemoizedPage.js.map +0 -1
  470. package/build/commonjs/ViewPager/ViewPagerNative.js +0 -72
  471. package/build/commonjs/ViewPager/ViewPagerNative.js.map +0 -1
  472. package/build/commonjs/ViewPager/ViewPagerWeb.js +0 -55
  473. package/build/commonjs/ViewPager/ViewPagerWeb.js.map +0 -1
  474. package/build/commonjs/ViewPager/index.native.js +0 -16
  475. package/build/commonjs/ViewPager/index.native.js.map +0 -1
  476. package/build/commonjs/hooks/useWidth.js +0 -29
  477. package/build/commonjs/hooks/useWidth.js.map +0 -1
  478. package/build/module/Carousel/CarouselNative.js +0 -54
  479. package/build/module/Carousel/CarouselNative.js.map +0 -1
  480. package/build/module/Carousel/CarouselWeb.js +0 -215
  481. package/build/module/Carousel/CarouselWeb.js.map +0 -1
  482. package/build/module/Carousel/index.native.js +0 -2
  483. package/build/module/Carousel/index.native.js.map +0 -1
  484. package/build/module/Carousel/utils.js +0 -7
  485. package/build/module/Carousel/utils.js.map +0 -1
  486. package/build/module/ComicViewer/ComicViewerItemProps.js +0 -2
  487. package/build/module/ComicViewer/ComicViewerItemProps.js.map +0 -1
  488. package/build/module/ViewPager/ChildrenMemoizedPage.js +0 -37
  489. package/build/module/ViewPager/ChildrenMemoizedPage.js.map +0 -1
  490. package/build/module/ViewPager/ViewPagerNative.js +0 -53
  491. package/build/module/ViewPager/ViewPagerNative.js.map +0 -1
  492. package/build/module/ViewPager/ViewPagerWeb.js +0 -41
  493. package/build/module/ViewPager/ViewPagerWeb.js.map +0 -1
  494. package/build/module/ViewPager/index.native.js +0 -2
  495. package/build/module/ViewPager/index.native.js.map +0 -1
  496. package/build/module/hooks/useWidth.js +0 -15
  497. package/build/module/hooks/useWidth.js.map +0 -1
  498. package/build/typescript/Carousel/CarouselNative.d.ts +0 -3
  499. package/build/typescript/Carousel/CarouselWeb.d.ts +0 -4
  500. package/build/typescript/Carousel/index.native.d.ts +0 -1
  501. package/build/typescript/Carousel/utils.d.ts +0 -6
  502. package/build/typescript/ComicViewer/ComicViewerItemProps.d.ts +0 -12
  503. package/build/typescript/ViewPager/ChildrenMemoizedPage.d.ts +0 -4
  504. package/build/typescript/ViewPager/ViewPagerNative.d.ts +0 -3
  505. package/build/typescript/ViewPager/ViewPagerWeb.d.ts +0 -3
  506. package/build/typescript/ViewPager/index.native.d.ts +0 -1
  507. package/build/typescript/hooks/useWidth.d.ts +0 -2
  508. package/src/Carousel/CarouselNative.tsx +0 -67
  509. package/src/Carousel/CarouselWeb.tsx +0 -222
  510. package/src/Carousel/index.native.ts +0 -1
  511. package/src/Carousel/utils.ts +0 -11
  512. package/src/ComicViewer/ComicViewerItemProps.ts +0 -15
  513. package/src/ViewPager/ChildrenMemoizedPage.tsx +0 -36
  514. package/src/ViewPager/ViewPagerNative.tsx +0 -66
  515. package/src/ViewPager/ViewPagerWeb.tsx +0 -52
  516. package/src/ViewPager/index.native.ts +0 -1
  517. package/src/hooks/useWidth.ts +0 -17
@@ -0,0 +1,192 @@
1
+ import { useCallback, useMemo, useRef } from 'react';
2
+ import { Animated } from 'react-native';
3
+ import { useAnimatedValue } from '@fountain-ui/core';
4
+
5
+ function directionToValue(itemWidth) {
6
+ return function (direction) {
7
+ switch (direction) {
8
+ case 'next':
9
+ return -itemWidth;
10
+
11
+ case 'prev':
12
+ return itemWidth;
13
+
14
+ case 'stay':
15
+ return 0;
16
+ }
17
+ };
18
+ }
19
+
20
+ function toValueCompensator(itemWidth) {
21
+ return function (toValue, currentOffset) {
22
+ const remainder = Math.abs(currentOffset % itemWidth);
23
+ const halfOfItemWidth = Math.abs(itemWidth / 2);
24
+ const compensateVector = remainder > halfOfItemWidth ? remainder - itemWidth : remainder;
25
+ const direction = currentOffset > 0 ? -1 : 1;
26
+ return toValue + direction * compensateVector;
27
+ };
28
+ }
29
+
30
+ export default function usePagingAnimator(config) {
31
+ const {
32
+ createScrollAnimation,
33
+ itemWidth,
34
+ indexController,
35
+ initialIndex,
36
+ loop,
37
+ numberOfData
38
+ } = config;
39
+ const {
40
+ getCurrentIndex,
41
+ lastIndex,
42
+ notifyScrollStateHasChanged
43
+ } = indexController;
44
+ const initialOffsetX = itemWidth * initialIndex;
45
+ const accumulativeOffsetX = useAnimatedValue(initialOffsetX);
46
+ const animationOffsetX = useAnimatedValue(0);
47
+ const gestureTranslationX = useAnimatedValue(0);
48
+ const globalInterpolation = useMemo(() => {
49
+ return Animated.add(Animated.add(accumulativeOffsetX, animationOffsetX), gestureTranslationX);
50
+ }, []);
51
+ const toValueRef = useRef(0);
52
+ const currentOffsetRef = useRef(0);
53
+ const isAnimatingRef = useRef(false);
54
+ const maxWidth = Math.abs(numberOfData * itemWidth);
55
+ const ensureOffsetBoundary = useCallback(offset => {
56
+ if (loop) {
57
+ const isCloseToEnd = Math.abs(offset) >= maxWidth - itemWidth;
58
+
59
+ if (isCloseToEnd) {
60
+ const signOfOffset = offset > 0 ? 1 : -1;
61
+ return offset + -signOfOffset * maxWidth;
62
+ }
63
+ }
64
+
65
+ return offset % maxWidth;
66
+ }, [itemWidth, loop, maxWidth]);
67
+ const requireNewOffset = useCallback(newOffset => {
68
+ const nextOffset = ensureOffsetBoundary(newOffset);
69
+ currentOffsetRef.current = nextOffset;
70
+ accumulativeOffsetX.setValue(nextOffset);
71
+ toValueRef.current = 0;
72
+ animationOffsetX.setValue(0);
73
+ }, [ensureOffsetBoundary]);
74
+ const interruptAnimation = useCallback(() => {
75
+ if (!isAnimatingRef.current) {
76
+ return;
77
+ }
78
+
79
+ animationOffsetX.stopAnimation(lastValue => {
80
+ isAnimatingRef.current = false;
81
+ const prevOffset = currentOffsetRef.current;
82
+ const totalOffset = prevOffset + lastValue;
83
+ requireNewOffset(totalOffset);
84
+ notifyScrollStateHasChanged({
85
+ offset: totalOffset,
86
+ state: 'interrupted'
87
+ });
88
+ });
89
+ }, [notifyScrollStateHasChanged, requireNewOffset]);
90
+ const finalizeAnimation = useCallback(() => {
91
+ isAnimatingRef.current = false;
92
+ const prevOffset = currentOffsetRef.current;
93
+ const toValue = toValueRef.current;
94
+ const totalOffset = prevOffset + toValue;
95
+ requireNewOffset(totalOffset);
96
+ notifyScrollStateHasChanged({
97
+ offset: totalOffset,
98
+ state: 'idle'
99
+ });
100
+ }, [notifyScrollStateHasChanged, requireNewOffset]);
101
+ const startPagingAnimation = useCallback((type, config) => {
102
+ if (isAnimatingRef.current) {
103
+ return;
104
+ }
105
+
106
+ const configWithDefaults = {
107
+ animated: true,
108
+ ...config
109
+ };
110
+ const currentIndex = getCurrentIndex();
111
+ const getValueByDirectionOnAllAdjacentItemsVisible = directionToValue(itemWidth);
112
+ const compensateToValue = toValueCompensator(itemWidth);
113
+
114
+ const getValueByDirectionalPagingOnLoopDisabled = _config => {
115
+ const {
116
+ direction,
117
+ isOriginatedFromGesture
118
+ } = _config;
119
+
120
+ if (currentIndex === 0 && direction === 'prev') {
121
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : -lastIndex * itemWidth; // last position
122
+ } else if (currentIndex === lastIndex && direction === 'next') {
123
+ return isOriginatedFromGesture ? getValueByDirectionOnAllAdjacentItemsVisible('stay') : lastIndex * itemWidth; // first position
124
+ }
125
+
126
+ return getValueByDirectionOnAllAdjacentItemsVisible(direction);
127
+ };
128
+
129
+ const getValueByDirectionalPaging = _config => {
130
+ const _configWithDefaults = {
131
+ isOriginatedFromGesture: false,
132
+ ..._config
133
+ };
134
+ return loop ? getValueByDirectionOnAllAdjacentItemsVisible(_configWithDefaults.direction) : getValueByDirectionalPagingOnLoopDisabled(_configWithDefaults);
135
+ };
136
+
137
+ const getValueByIndexPaging = _ref => {
138
+ let {
139
+ index
140
+ } = _ref;
141
+
142
+ if (index < 0 || index > lastIndex || index === currentIndex) {
143
+ // no animation if index is invalid or equals to current index
144
+ return 0;
145
+ }
146
+
147
+ const distance = Math.abs(currentIndex - index) * itemWidth;
148
+ const direction = index > currentIndex ? -1 : 1;
149
+ return distance * direction;
150
+ };
151
+
152
+ const wantedToValue = type === 'directional' // @ts-ignore
153
+ ? getValueByDirectionalPaging(configWithDefaults) // @ts-ignore
154
+ : getValueByIndexPaging(configWithDefaults);
155
+ const toValue = compensateToValue(wantedToValue, currentOffsetRef.current);
156
+ toValueRef.current = toValue;
157
+ isAnimatingRef.current = true;
158
+ notifyScrollStateHasChanged({
159
+ offset: currentOffsetRef.current + toValue,
160
+ state: 'dragging'
161
+ });
162
+ const lastGestureTranslationX = configWithDefaults.lastGestureTranslationX ?? 0;
163
+
164
+ if (Number.isFinite(lastGestureTranslationX)) {
165
+ animationOffsetX.setValue(lastGestureTranslationX);
166
+ gestureTranslationX.setValue(0);
167
+ }
168
+
169
+ if (configWithDefaults.animated) {
170
+ const animation = createScrollAnimation(animationOffsetX, toValue);
171
+ animation.start(_ref2 => {
172
+ let {
173
+ finished
174
+ } = _ref2;
175
+
176
+ if (finished) {
177
+ finalizeAnimation();
178
+ }
179
+ });
180
+ } else {
181
+ finalizeAnimation();
182
+ }
183
+ }, [createScrollAnimation, getCurrentIndex, finalizeAnimation, itemWidth, lastIndex, loop, notifyScrollStateHasChanged]);
184
+ return {
185
+ gestureTranslationX,
186
+ globalInterpolation,
187
+ interruptAnimation,
188
+ startPagingAnimation
189
+ };
190
+ }
191
+ ;
192
+ //# sourceMappingURL=usePagingAnimator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useMemo","useRef","Animated","useAnimatedValue","directionToValue","itemWidth","direction","toValueCompensator","toValue","currentOffset","remainder","Math","abs","halfOfItemWidth","compensateVector","usePagingAnimator","config","createScrollAnimation","indexController","initialIndex","loop","numberOfData","getCurrentIndex","lastIndex","notifyScrollStateHasChanged","initialOffsetX","accumulativeOffsetX","animationOffsetX","gestureTranslationX","globalInterpolation","add","toValueRef","currentOffsetRef","isAnimatingRef","maxWidth","ensureOffsetBoundary","offset","isCloseToEnd","signOfOffset","requireNewOffset","newOffset","nextOffset","current","setValue","interruptAnimation","stopAnimation","lastValue","prevOffset","totalOffset","state","finalizeAnimation","startPagingAnimation","type","configWithDefaults","animated","currentIndex","getValueByDirectionOnAllAdjacentItemsVisible","compensateToValue","getValueByDirectionalPagingOnLoopDisabled","_config","isOriginatedFromGesture","getValueByDirectionalPaging","_configWithDefaults","getValueByIndexPaging","index","distance","wantedToValue","lastGestureTranslationX","Number","isFinite","animation","start","finished"],"sources":["usePagingAnimator.ts"],"sourcesContent":["import { useCallback, useMemo, useRef } from 'react';\nimport { Animated } from 'react-native';\nimport { useAnimatedValue } from '@fountain-ui/core';\nimport type {\n CreateScrollAnimation,\n DirectionalPagingAnimationConfig,\n IndexController,\n IndexPagingAnimationConfig,\n PagingAnimationConfig,\n PagingAnimationType,\n PagingDirection,\n StartPagingAnimation,\n} from '../types';\n\nexport interface PagingAnimatorConfig {\n createScrollAnimation: CreateScrollAnimation;\n itemWidth: number;\n indexController: IndexController;\n initialIndex: number;\n loop: boolean;\n numberOfData: number;\n}\n\nexport interface PagingAnimator {\n gestureTranslationX: Animated.Value;\n globalInterpolation: Animated.AnimatedInterpolation;\n interruptAnimation: () => void;\n startPagingAnimation: StartPagingAnimation;\n}\n\nfunction directionToValue(itemWidth: number) {\n return function (direction: PagingDirection): number {\n switch (direction) {\n case 'next':\n return -itemWidth;\n case 'prev':\n return itemWidth;\n case 'stay':\n return 0;\n }\n };\n}\n\nfunction toValueCompensator(itemWidth: number) {\n return function (toValue: number, currentOffset: number): number {\n const remainder = Math.abs(currentOffset % itemWidth);\n\n const halfOfItemWidth = Math.abs(itemWidth / 2);\n const compensateVector = remainder > halfOfItemWidth\n ? remainder - itemWidth\n : remainder;\n\n const direction = currentOffset > 0 ? -1 : 1;\n\n return toValue + (direction * compensateVector);\n };\n}\n\nexport default function usePagingAnimator(config: PagingAnimatorConfig): PagingAnimator {\n const {\n createScrollAnimation,\n itemWidth,\n indexController,\n initialIndex,\n loop,\n numberOfData,\n } = config;\n\n const {\n getCurrentIndex,\n lastIndex,\n notifyScrollStateHasChanged,\n } = indexController;\n\n const initialOffsetX = itemWidth * initialIndex;\n const accumulativeOffsetX = useAnimatedValue(initialOffsetX);\n const animationOffsetX = useAnimatedValue(0);\n const gestureTranslationX = useAnimatedValue(0);\n\n const globalInterpolation = useMemo(() => {\n return Animated.add(\n Animated.add(accumulativeOffsetX, animationOffsetX),\n gestureTranslationX,\n );\n }, []);\n\n const toValueRef = useRef<number>(0);\n const currentOffsetRef = useRef<number>(0);\n\n const isAnimatingRef = useRef<boolean>(false);\n\n const maxWidth = Math.abs(numberOfData * itemWidth);\n\n const ensureOffsetBoundary: (offset: number) => number = useCallback((offset: number) => {\n if (loop) {\n const isCloseToEnd = Math.abs(offset) >= (maxWidth - itemWidth);\n if (isCloseToEnd) {\n const signOfOffset = offset > 0 ? 1 : -1;\n return offset + (-signOfOffset * maxWidth);\n }\n }\n\n return offset % maxWidth;\n }, [itemWidth, loop, maxWidth]);\n\n const requireNewOffset = useCallback((newOffset: number) => {\n const nextOffset = ensureOffsetBoundary(newOffset);\n\n currentOffsetRef.current = nextOffset;\n accumulativeOffsetX.setValue(nextOffset);\n\n toValueRef.current = 0;\n animationOffsetX.setValue(0);\n }, [\n ensureOffsetBoundary,\n ]);\n\n const interruptAnimation = useCallback(() => {\n if (!isAnimatingRef.current) {\n return;\n }\n\n animationOffsetX.stopAnimation(lastValue => {\n isAnimatingRef.current = false;\n\n const prevOffset = currentOffsetRef.current;\n const totalOffset = prevOffset + lastValue;\n\n requireNewOffset(totalOffset);\n\n notifyScrollStateHasChanged({ offset: totalOffset, state: 'interrupted' });\n });\n }, [\n notifyScrollStateHasChanged,\n requireNewOffset,\n ]);\n\n const finalizeAnimation = useCallback(() => {\n isAnimatingRef.current = false;\n\n const prevOffset = currentOffsetRef.current;\n const toValue = toValueRef.current;\n const totalOffset = prevOffset + toValue;\n\n requireNewOffset(totalOffset);\n\n notifyScrollStateHasChanged({ offset: totalOffset, state: 'idle' });\n }, [\n notifyScrollStateHasChanged,\n requireNewOffset,\n ]);\n\n const startPagingAnimation = useCallback((type: PagingAnimationType, config: PagingAnimationConfig) => {\n if (isAnimatingRef.current) {\n return;\n }\n\n const configWithDefaults: PagingAnimationConfig = {\n animated: true,\n ...config,\n };\n\n const currentIndex = getCurrentIndex();\n\n const getValueByDirectionOnAllAdjacentItemsVisible = directionToValue(itemWidth);\n const compensateToValue = toValueCompensator(itemWidth);\n\n const getValueByDirectionalPagingOnLoopDisabled = (_config: DirectionalPagingAnimationConfig): number => {\n const { direction, isOriginatedFromGesture } = _config;\n\n if (currentIndex === 0 && direction === 'prev') {\n return isOriginatedFromGesture\n ? getValueByDirectionOnAllAdjacentItemsVisible('stay')\n : -lastIndex * itemWidth; // last position\n } else if (currentIndex === lastIndex && direction === 'next') {\n return isOriginatedFromGesture\n ? getValueByDirectionOnAllAdjacentItemsVisible('stay')\n : lastIndex * itemWidth; // first position\n }\n return getValueByDirectionOnAllAdjacentItemsVisible(direction);\n };\n\n const getValueByDirectionalPaging = (_config: DirectionalPagingAnimationConfig): number => {\n const _configWithDefaults: DirectionalPagingAnimationConfig = {\n isOriginatedFromGesture: false,\n ..._config,\n };\n\n return loop\n ? getValueByDirectionOnAllAdjacentItemsVisible(_configWithDefaults.direction)\n : getValueByDirectionalPagingOnLoopDisabled(_configWithDefaults);\n };\n\n const getValueByIndexPaging = ({ index }: IndexPagingAnimationConfig): number => {\n if (index < 0 || index > lastIndex || index === currentIndex) {\n // no animation if index is invalid or equals to current index\n return 0;\n }\n\n const distance = Math.abs(currentIndex - index) * itemWidth;\n const direction = index > currentIndex ? -1 : 1;\n\n return distance * direction;\n };\n\n const wantedToValue = type === 'directional'\n // @ts-ignore\n ? getValueByDirectionalPaging(configWithDefaults)\n // @ts-ignore\n : getValueByIndexPaging(configWithDefaults);\n\n const toValue = compensateToValue(wantedToValue, currentOffsetRef.current);\n\n toValueRef.current = toValue;\n isAnimatingRef.current = true;\n\n notifyScrollStateHasChanged({\n offset: currentOffsetRef.current + toValue,\n state: 'dragging',\n });\n\n const lastGestureTranslationX: number = configWithDefaults.lastGestureTranslationX ?? 0;\n if (Number.isFinite(lastGestureTranslationX)) {\n animationOffsetX.setValue(lastGestureTranslationX);\n gestureTranslationX.setValue(0);\n }\n\n if (configWithDefaults.animated) {\n const animation = createScrollAnimation(animationOffsetX, toValue);\n\n animation.start(({ finished }) => {\n if (finished) {\n finalizeAnimation();\n }\n });\n } else {\n finalizeAnimation();\n }\n }, [\n createScrollAnimation,\n getCurrentIndex,\n finalizeAnimation,\n itemWidth,\n lastIndex,\n loop,\n notifyScrollStateHasChanged,\n ]);\n\n return {\n gestureTranslationX,\n globalInterpolation,\n interruptAnimation,\n startPagingAnimation,\n };\n};\n"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,OAAtB,EAA+BC,MAA/B,QAA6C,OAA7C;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,gBAAT,QAAiC,mBAAjC;;AA4BA,SAASC,gBAAT,CAA0BC,SAA1B,EAA6C;EACzC,OAAO,UAAUC,SAAV,EAA8C;IACjD,QAAQA,SAAR;MACI,KAAK,MAAL;QACI,OAAO,CAACD,SAAR;;MACJ,KAAK,MAAL;QACI,OAAOA,SAAP;;MACJ,KAAK,MAAL;QACI,OAAO,CAAP;IANR;EAQH,CATD;AAUH;;AAED,SAASE,kBAAT,CAA4BF,SAA5B,EAA+C;EAC3C,OAAO,UAAUG,OAAV,EAA2BC,aAA3B,EAA0D;IAC7D,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAL,CAASH,aAAa,GAAGJ,SAAzB,CAAlB;IAEA,MAAMQ,eAAe,GAAGF,IAAI,CAACC,GAAL,CAASP,SAAS,GAAG,CAArB,CAAxB;IACA,MAAMS,gBAAgB,GAAGJ,SAAS,GAAGG,eAAZ,GACnBH,SAAS,GAAGL,SADO,GAEnBK,SAFN;IAIA,MAAMJ,SAAS,GAAGG,aAAa,GAAG,CAAhB,GAAoB,CAAC,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AAS,GAAGrD,qBAAqB,CAACU,gBAAD,EAAmBnB,OAAnB,CAAvC;MAEA8D,SAAS,CAACC,KAAV,CAAgB,SAAkB;QAAA,IAAjB;UAAEC;QAAF,CAAiB;;QAC9B,IAAIA,QAAJ,EAAc;UACVtB,iBAAiB;QACpB;MACJ,CAJD;IAKH,CARD,MAQO;MACHA,iBAAiB;IACpB;EACJ,CAtFuC,EAsFrC,CACCjC,qBADD,EAECK,eAFD,EAGC4B,iBAHD,EAIC7C,SAJD,EAKCkB,SALD,EAMCH,IAND,EAOCI,2BAPD,CAtFqC,CAAxC;EAgGA,OAAO;IACHI,mBADG;IAEHC,mBAFG;IAGHe,kBAHG;IAIHO;EAJG,CAAP;AAMH;AAAA"}
@@ -1,2 +1,3 @@
1
- export { default } from './CarouselWeb';
1
+ export { default } from './Carousel';
2
+ export { normalItemStyleFactory, parallaxItemStyleFactory } from './animation';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["default"],"mappings":"AAAA,SAASA,OAAT,QAAwB,eAAxB","sourcesContent":["export { default } from './CarouselWeb';\nexport type { default as CarouselProps } from './CarouselProps';"]}
1
+ {"version":3,"names":["default","normalItemStyleFactory","parallaxItemStyleFactory"],"sources":["index.ts"],"sourcesContent":["export { default } from './Carousel';\nexport type { default as CarouselProps } from './CarouselProps';\nexport type { CarouselInstance } from './types';\nexport { normalItemStyleFactory, parallaxItemStyleFactory } from './animation';\n"],"mappings":"AAAA,SAASA,OAAT,QAAwB,YAAxB;AAGA,SAASC,sBAAT,EAAiCC,wBAAjC,QAAiE,aAAjE"}
@@ -0,0 +1,6 @@
1
+ import { logger } from '@fountain-ui/utils';
2
+ export default logger('Carousel', {
3
+ enabled: __DEV__,
4
+ format: 'diff'
5
+ });
6
+ //# sourceMappingURL=tick.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["logger","enabled","__DEV__","format"],"sources":["tick.ts"],"sourcesContent":["import { logger } from '@fountain-ui/utils';\n\nexport default logger('Carousel', {\n enabled: __DEV__,\n format: 'diff',\n});\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,oBAAvB;AAEA,eAAeA,MAAM,CAAC,UAAD,EAAa;EAC9BC,OAAO,EAAEC,OADqB;EAE9BC,MAAM,EAAE;AAFsB,CAAb,CAArB"}
@@ -0,0 +1,4 @@
1
+ const directions = ['next', 'prev', 'stay'];
2
+ const scrollStates = ['idle', 'dragging', 'interrupted'];
3
+ export {};
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["directions","scrollStates"],"sources":["types.ts"],"sourcesContent":["import type { ReactElement } from 'react';\nimport type { Animated, ViewProps } from 'react-native';\n\nconst directions = ['next', 'prev', 'stay'] as const;\n\nexport type PagingDirection = (typeof directions)[number];\n\nconst scrollStates = ['idle', 'dragging', 'interrupted'] as const;\n\nexport type ScrollState = (typeof scrollStates)[number];\n\nexport type ItemHeight = number | 'auto';\n\nexport interface RenderItem<T> {\n (info: { item: T, index: number, interpolation: Animated.AnimatedInterpolation }): ReactElement | null;\n}\n\nexport interface CreateScrollAnimation {\n (aValue: Animated.AnimatedValue, toValue: number): Animated.CompositeAnimation;\n}\n\nexport interface CreateItemStyle {\n (itemInterpolation: Animated.AnimatedInterpolation, itemWidth: number): Animated.AnimatedProps<ViewProps['style']>;\n}\n\nexport interface GetCurrentIndex {\n (): number;\n}\n\nexport interface OnIndexChange {\n (itemIndex: number): void;\n}\n\nexport interface OnPositionChange {\n (position: number): void;\n}\n\nexport interface ScrollStateChangeEvent {\n offset: number;\n state: ScrollState;\n}\n\nexport interface IndexController {\n getCurrentIndex: GetCurrentIndex;\n lastIndex: number;\n notifyScrollStateHasChanged: (event: ScrollStateChangeEvent) => void;\n}\n\nexport type PagingAnimationType = 'directional' | 'index';\n\nexport interface BasePagingAnimationConfig {\n animated?: boolean;\n lastGestureTranslationX?: number;\n}\n\nexport interface DirectionalPagingAnimationConfig extends BasePagingAnimationConfig {\n direction: PagingDirection;\n isOriginatedFromGesture?: boolean;\n}\n\nexport interface IndexPagingAnimationConfig extends BasePagingAnimationConfig {\n index: number;\n}\n\nexport type PagingAnimationConfig = DirectionalPagingAnimationConfig | IndexPagingAnimationConfig;\n\nexport interface StartPagingAnimation {\n (type: PagingAnimationType, config: PagingAnimationConfig): void;\n}\n\nexport type VisibleIndexRanges = Array<[number, number]>;\n\nexport interface StoreSubscription {\n (): void;\n}\n\nexport interface ItemVisibilityStore {\n dispatch: (ranges: VisibleIndexRanges) => void;\n subscribe: (listener: (ranges: VisibleIndexRanges) => void) => StoreSubscription;\n removeAllListeners: () => void;\n}\n\nexport interface AutoplayController {\n pause: () => void;\n resume: () => void;\n}\n\nexport interface ScrollToOption {\n index: number;\n animated?: boolean;\n}\n\nexport interface CarouselInstance {\n /**\n * Get current visible item index.\n */\n getCurrentIndex: GetCurrentIndex;\n\n /**\n * Scroll to next visible item.\n */\n next: () => void;\n\n /**\n * Scroll to previous visible item.\n */\n prev: () => void;\n\n /**\n * Scroll to desired indexed item.\n * Invalid index is ignored.\n */\n scrollTo: (option: ScrollToOption) => void;\n}\n"],"mappings":"AAGA,MAAMA,UAAU,GAAG,CAAC,MAAD,EAAS,MAAT,EAAiB,MAAjB,CAAnB;AAIA,MAAMC,YAAY,GAAG,CAAC,MAAD,EAAS,UAAT,EAAqB,aAArB,CAArB"}
@@ -1,126 +1,279 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { FlatList } from 'react-native';
5
5
  import * as R from 'ramda';
6
+ import { useDebounce } from '@fountain-ui/core';
6
7
  import ViewerItem from './ViewerItem';
7
-
8
- const getItemHeights = items => R.map(content => content.height)(items);
8
+ import FastScroll from './FastScroll';
9
9
 
10
10
  const appender = (left, right) => [left + right, left + right];
11
11
 
12
- const getHeightAccum = itemHeights => R.mapAccum(appender, 0, itemHeights);
12
+ const getHeightAccum = heights => R.mapAccum(appender, 0, heights);
13
+
14
+ const keyExtractor = item => String(item.index);
15
+
16
+ const createInitialImageState = dimension => ({
17
+ isNewUrlIncoming: false,
18
+ totalErrorCount: 0,
19
+ dimension
20
+ });
13
21
 
14
- const keyExtractor = item => item.id;
22
+ const mapImageStateToItemState = (index, imageState, autoHandleErrorCount) => {
23
+ var _imageState$urlState, _imageState$urlState2;
24
+
25
+ return {
26
+ index,
27
+ url: (_imageState$urlState = imageState.urlState) === null || _imageState$urlState === void 0 ? void 0 : _imageState$urlState.url,
28
+ reloadButtonVisible: ((_imageState$urlState2 = imageState.urlState) === null || _imageState$urlState2 === void 0 ? void 0 : _imageState$urlState2.validity) !== 'valid' && imageState.totalErrorCount >= autoHandleErrorCount,
29
+ dimension: imageState.dimension
30
+ };
31
+ };
15
32
 
33
+ const mapIndexed = R.addIndex(R.map);
34
+ const MAXIMUM_WIDTH = 720;
35
+ const NUMBER_OF_ADJACENT_ITEM = 5;
16
36
  export default function ComicViewer(props) {
17
37
  const {
18
- data,
19
- errorDebounceMillis = 500,
20
- errorRetryCount = 3,
38
+ debounceMillis = 100,
39
+ autoHandleErrorCount = 3,
40
+ fastScrollOptions,
41
+ getUrlByIndex,
21
42
  initialNumToRender = 1,
22
43
  initialScrollPercentage = 0,
23
44
  itemVisiblePercentThreshold = 0,
45
+ intrinsicDimensions,
46
+ maxContentWidth = MAXIMUM_WIDTH,
47
+ onItemPress,
48
+ onScroll,
24
49
  onError,
25
- viewerWidth,
50
+ onReloadPress,
51
+ viewportWidth,
52
+ invisiblePaddingTop = 0,
26
53
  windowSize = 3,
27
54
  ...otherProps
28
55
  } = props;
56
+ const fastScrollRef = fastScrollOptions === null || fastScrollOptions === void 0 ? void 0 : fastScrollOptions.ref;
29
57
  const flatListRef = useRef(null);
30
- const errors = useRef(new Map());
31
- const debounceTimeOut = useRef(null);
32
- const resourceString = R.toString(R.map(itemData => itemData.sourceUrl)(data));
33
- const initialItems = R.map(itemData => ({ ...itemData,
34
- isViewable: false,
35
- width: viewerWidth,
36
- height: itemData.height * viewerWidth / itemData.width
37
- }))(data);
38
- const [items, setItems] = useState(initialItems);
39
- const itemHeights = getItemHeights(items);
40
- const itemHeightAccum = getHeightAccum(itemHeights);
58
+ const maybeLoadableItemsIndexRange = useRef([-1, 0]);
59
+ const actualImageWidth = Math.min(viewportWidth, maxContentWidth);
60
+ const initialImageStates = useMemo(() => R.map(createInitialImageState, intrinsicDimensions), []);
61
+ const imageStatesRef = useRef(initialImageStates);
62
+
63
+ const mapImageStatesToItemStates = imageStates => {
64
+ return imageStates.map((image, index) => mapImageStateToItemState(index, image, autoHandleErrorCount));
65
+ };
66
+
67
+ const [itemStates, setItemStates] = useState(() => {
68
+ return mapImageStatesToItemStates(imageStatesRef.current);
69
+ });
70
+ const renderedDimensions = useMemo(() => {
71
+ return mapIndexed((intrinsicDimension, index) => {
72
+ const height = intrinsicDimension.height * actualImageWidth / intrinsicDimension.width + (index === 0 ? invisiblePaddingTop : 0);
73
+ return {
74
+ width: actualImageWidth,
75
+ height: isNaN(height) ? 0 : height
76
+ };
77
+ }, intrinsicDimensions);
78
+ }, [actualImageWidth]);
79
+ const layoutFromDimensions = useCallback(() => {
80
+ const itemHeights = R.map(dimension => dimension.height, renderedDimensions);
81
+ const [totalHeight, heightAccum] = getHeightAccum(itemHeights);
82
+ const itemOffsets = R.prepend(0, heightAccum);
83
+
84
+ const getItemLayout = (data, index) => ({
85
+ index,
86
+ length: itemHeights[index],
87
+ offset: itemOffsets[index]
88
+ });
89
+
90
+ return {
91
+ totalHeight,
92
+ getItemLayout
93
+ };
94
+ }, [renderedDimensions]);
95
+ const {
96
+ totalHeight,
97
+ getItemLayout
98
+ } = layoutFromDimensions();
41
99
  const viewabilityConfig = useMemo(() => ({
42
100
  itemVisiblePercentThreshold
43
101
  }), [itemVisiblePercentThreshold]);
44
- const getItemLayout = useCallback((data, index) => {
45
- const offsets = R.prepend(0, itemHeightAccum[1]);
46
- return {
47
- length: itemHeights[index],
48
- offset: offsets[index],
49
- index
50
- };
51
- }, [itemHeights]);
52
- const onViewableItemsChanged = useRef(({
53
- viewableItems
54
- }) => {
55
- setItems(prev => {
56
- const viewableItemIds = R.map(viewableItem => viewableItem.item.id)(viewableItems);
57
- return R.map(prevItem => ({ ...prevItem,
58
- isViewable: R.includes(prevItem.id, viewableItemIds)
59
- }))([...prev]);
102
+
103
+ const updateImageState = updateFunction => {
104
+ const prevImageStates = imageStatesRef.current;
105
+ const newImageStates = prevImageStates.map(updateFunction);
106
+ imageStatesRef.current = newImageStates;
107
+ setItemStates(prevItemStates => {
108
+ const newItemStates = mapImageStatesToItemStates(newImageStates);
109
+ return R.equals(prevItemStates, newItemStates) ? prevItemStates : newItemStates;
60
110
  });
61
- });
111
+ };
62
112
 
63
- const onErrorHandler = errors => {
64
- const isRetryLimited = R.any(error => error.count >= errorRetryCount)(errors);
113
+ const loadUrlByIndex = async indexes => {
114
+ const filteredIndexes = R.filter(index => {
115
+ var _state$urlState;
65
116
 
66
- if (isRetryLimited) {
67
- return;
117
+ const state = imageStatesRef.current[index];
118
+ return !state.isNewUrlIncoming && (R.isNil(state.urlState) || ((_state$urlState = state.urlState) === null || _state$urlState === void 0 ? void 0 : _state$urlState.validity) === 'invalid');
119
+ }, indexes);
120
+ updateImageState((imageState, i) => {
121
+ return R.includes(i, filteredIndexes) ? { ...imageState,
122
+ isNewUrlIncoming: true
123
+ } : imageState;
124
+ });
125
+
126
+ try {
127
+ const urls = await getUrlByIndex(filteredIndexes);
128
+ updateImageState((imageState, i) => {
129
+ const newUrl = urls === null || urls === void 0 ? void 0 : urls.get(i);
130
+ const urlState = imageState.urlState;
131
+
132
+ if (newUrl !== undefined && (urlState === null || urlState === void 0 ? void 0 : urlState.validity) !== 'valid') {
133
+ return { ...imageState,
134
+ urlState: {
135
+ url: newUrl,
136
+ validity: 'unknown'
137
+ }
138
+ };
139
+ }
140
+
141
+ return imageState;
142
+ });
143
+ } catch (e) {// ignore
144
+ } finally {
145
+ updateImageState((imageState, i) => {
146
+ return R.includes(i, filteredIndexes) ? { ...imageState,
147
+ isNewUrlIncoming: false
148
+ } : imageState;
149
+ });
68
150
  }
151
+ };
69
152
 
70
- onError && onError(errors);
153
+ const loadMaybeLoadableItems = () => {
154
+ const [startIndex, endIndex] = maybeLoadableItemsIndexRange.current;
155
+ const affectedIndexes = R.range(startIndex, endIndex);
156
+ loadUrlByIndex(affectedIndexes);
71
157
  };
72
158
 
73
- const itemErrorHandler = useCallback(errorInfo => {
74
- errors.current.set(errorInfo.id, errorInfo.count);
159
+ const ignoreDebounce = useRef(true);
160
+ const loadItemsDebounce = useDebounce(loadMaybeLoadableItems, debounceMillis);
161
+ const onViewableItemsChanged = useRef(_ref => {
162
+ var _R$head, _R$last;
163
+
164
+ let {
165
+ viewableItems
166
+ } = _ref;
167
+ const orderedViewableItems = R.sort((a, b) => (a.index || 0) - (b.index || 0), viewableItems);
168
+ const firstViewableIndex = (_R$head = R.head(orderedViewableItems)) === null || _R$head === void 0 ? void 0 : _R$head.index;
169
+ const lastViewableItemIndex = (_R$last = R.last(orderedViewableItems)) === null || _R$last === void 0 ? void 0 : _R$last.index;
75
170
 
76
- if (debounceTimeOut.current) {
77
- clearTimeout(debounceTimeOut.current);
171
+ if (R.isNil(firstViewableIndex) || R.isNil(lastViewableItemIndex)) {
172
+ return;
78
173
  }
79
174
 
80
- debounceTimeOut.current = setTimeout(function () {
81
- const errorsArray = Array.from(errors.current.entries());
82
- const errorsInfo = R.map(([key, value]) => ({
83
- id: key,
84
- count: value
85
- }))(errorsArray);
86
- onErrorHandler([...errorsInfo]);
87
- errors.current.clear();
88
- }, errorDebounceMillis);
89
- }, [errorDebounceMillis, errors.current]);
90
- const renderItem = useCallback(({
91
- item
92
- }) => {
93
- const props = { ...item,
94
- onError: itemErrorHandler
95
- };
96
- return /*#__PURE__*/React.createElement(ViewerItem, {
97
- props: props
175
+ const startIndex = R.max(firstViewableIndex - NUMBER_OF_ADJACENT_ITEM, 0);
176
+ const endIndex = R.min(lastViewableItemIndex + NUMBER_OF_ADJACENT_ITEM, itemStates.length - 1);
177
+ maybeLoadableItemsIndexRange.current = [startIndex, endIndex + 1];
178
+
179
+ if (ignoreDebounce.current) {
180
+ loadMaybeLoadableItems();
181
+ ignoreDebounce.current = false;
182
+ return;
183
+ }
184
+
185
+ loadItemsDebounce();
186
+ });
187
+ const handleScroll = useCallback(event => {
188
+ var _fastScrollRef$curren;
189
+
190
+ fastScrollRef === null || fastScrollRef === void 0 ? void 0 : (_fastScrollRef$curren = fastScrollRef.current) === null || _fastScrollRef$curren === void 0 ? void 0 : _fastScrollRef$curren.onContentScroll(event);
191
+ onScroll === null || onScroll === void 0 ? void 0 : onScroll(event);
192
+ }, [onScroll]);
193
+
194
+ const scrollContentToOffset = offset => {
195
+ var _flatListRef$current;
196
+
197
+ (_flatListRef$current = flatListRef.current) === null || _flatListRef$current === void 0 ? void 0 : _flatListRef$current.scrollToOffset({
198
+ offset,
199
+ animated: false
98
200
  });
99
- }, []);
100
- useEffect(() => {
101
- setItems(prev => {
102
- return R.map(prevItem => {
103
- const currentData = R.find(currentItemData => prevItem.id === currentItemData.id)(data);
201
+ };
104
202
 
105
- if (currentData && currentData.sourceUrl !== prevItem.sourceUrl) {
106
- return { ...prevItem,
107
- sourceUrl: currentData.sourceUrl
203
+ const renderItem = useCallback(_ref2 => {
204
+ var _renderedDimensions$i, _renderedDimensions$i2;
205
+
206
+ let {
207
+ item,
208
+ index
209
+ } = _ref2;
210
+
211
+ const handleError = () => {
212
+ onError && onError();
213
+ updateImageState((imageState, i) => {
214
+ const urlState = imageState.urlState;
215
+
216
+ if (i === index && urlState !== undefined) {
217
+ return { ...imageState,
218
+ totalErrorCount: imageState.totalErrorCount + 1,
219
+ urlState: { ...urlState,
220
+ validity: 'invalid'
221
+ }
108
222
  };
109
223
  }
110
224
 
111
- return prevItem;
112
- })([...prev]);
225
+ return imageState;
226
+ });
227
+
228
+ if (item.reloadButtonVisible) {
229
+ return;
230
+ }
231
+
232
+ const [startIndex, endIndex] = maybeLoadableItemsIndexRange.current;
233
+
234
+ if (index >= startIndex || index < endIndex) {
235
+ loadItemsDebounce();
236
+ }
237
+ };
238
+
239
+ const handleReloadPress = () => {
240
+ onReloadPress && onReloadPress();
241
+ const [startIndex, endIndex] = maybeLoadableItemsIndexRange.current;
242
+
243
+ if (index >= startIndex || index < endIndex) {
244
+ loadUrlByIndex([index]);
245
+ }
246
+ };
247
+
248
+ const onLoad = () => {
249
+ updateImageState((imageState, i) => {
250
+ const urlState = imageState.urlState;
251
+
252
+ if (i === index && urlState !== undefined) {
253
+ return { ...imageState,
254
+ urlState: { ...urlState,
255
+ validity: 'valid'
256
+ }
257
+ };
258
+ }
259
+
260
+ return imageState;
261
+ });
262
+ };
263
+
264
+ return /*#__PURE__*/React.createElement(ViewerItem, {
265
+ onError: handleError,
266
+ onLoad: onLoad,
267
+ onPress: onItemPress,
268
+ onReloadPress: handleReloadPress,
269
+ url: item.url,
270
+ invisiblePaddingTop: index === 0 ? invisiblePaddingTop : 0,
271
+ width: ((_renderedDimensions$i = renderedDimensions[index]) === null || _renderedDimensions$i === void 0 ? void 0 : _renderedDimensions$i.width) ?? 0,
272
+ height: ((_renderedDimensions$i2 = renderedDimensions[index]) === null || _renderedDimensions$i2 === void 0 ? void 0 : _renderedDimensions$i2.height) ?? 0,
273
+ reloadButtonVisible: item.reloadButtonVisible
113
274
  });
114
- }, [resourceString]);
275
+ }, [onItemPress, renderedDimensions]);
115
276
  useEffect(() => {
116
- const newItems = R.map(item => ({ ...item,
117
- width: viewerWidth,
118
- height: item.height * viewerWidth / item.width
119
- }))(items);
120
- setItems(newItems);
121
- }, [viewerWidth]);
122
- useEffect(() => {
123
- const totalHeight = itemHeightAccum[0];
124
277
  const offset = Math.floor(initialScrollPercentage / 100 * totalHeight);
125
278
 
126
279
  if (flatListRef.current) {
@@ -129,9 +282,9 @@ export default function ComicViewer(props) {
129
282
  animated: false
130
283
  });
131
284
  }
132
- }, [flatListRef.current]);
133
- return /*#__PURE__*/React.createElement(FlatList, _extends({
134
- data: items,
285
+ }, []);
286
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FlatList, _extends({
287
+ data: itemStates,
135
288
  getItemLayout: getItemLayout,
136
289
  initialNumToRender: initialNumToRender,
137
290
  keyExtractor: keyExtractor,
@@ -139,8 +292,12 @@ export default function ComicViewer(props) {
139
292
  ref: flatListRef,
140
293
  renderItem: renderItem,
141
294
  viewabilityConfig: viewabilityConfig,
142
- windowSize: windowSize
143
- }, otherProps));
295
+ windowSize: windowSize,
296
+ onScroll: handleScroll
297
+ }, otherProps)), /*#__PURE__*/React.createElement(FastScroll, _extends({}, fastScrollOptions, {
298
+ contentLength: totalHeight,
299
+ scrollContentToOffset: scrollContentToOffset
300
+ })));
144
301
  }
145
302
  ;
146
303
  //# sourceMappingURL=ComicViewer.js.map