@mpxjs/webpack-plugin 2.10.17 → 2.10.18

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 (238) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/file-loader.js +4 -1
  3. package/lib/global.d.ts +231 -0
  4. package/lib/index.js +58 -73
  5. package/lib/init.js +3 -0
  6. package/lib/json-compiler/index.js +13 -4
  7. package/lib/loader.js +4 -0
  8. package/lib/platform/json/wx/index.js +6 -0
  9. package/lib/platform/style/wx/index.js +102 -72
  10. package/lib/platform/template/wx/component-config/ad.js +5 -0
  11. package/lib/platform/template/wx/component-config/button.js +10 -3
  12. package/lib/platform/template/wx/component-config/camera.js +13 -3
  13. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  14. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  15. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  16. package/lib/platform/template/wx/component-config/form.js +27 -2
  17. package/lib/platform/template/wx/component-config/image.js +5 -0
  18. package/lib/platform/template/wx/component-config/input.js +10 -0
  19. package/lib/platform/template/wx/component-config/label.js +10 -2
  20. package/lib/platform/template/wx/component-config/map.js +11 -0
  21. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  22. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  23. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  24. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  25. package/lib/platform/template/wx/component-config/picker.js +3 -1
  26. package/lib/platform/template/wx/component-config/progress.js +11 -1
  27. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  28. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  29. package/lib/platform/template/wx/component-config/slider.js +8 -0
  30. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  31. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  32. package/lib/platform/template/wx/component-config/text.js +5 -0
  33. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  34. package/lib/platform/template/wx/component-config/unsupported.js +9 -0
  35. package/lib/platform/template/wx/component-config/video.js +10 -0
  36. package/lib/platform/template/wx/index.js +21 -1
  37. package/lib/react/LoadAsyncChunkModule.js +1 -1
  38. package/lib/react/processStyles.js +21 -9
  39. package/lib/react/script-helper.js +2 -2
  40. package/lib/react/style-helper.js +76 -13
  41. package/lib/resolver/AddModePlugin.js +17 -7
  42. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  43. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
  44. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  45. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  46. package/lib/runtime/components/react/context.ts +12 -3
  47. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  48. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  49. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  50. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
  51. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  52. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  53. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  54. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  55. package/lib/runtime/components/react/dist/context.d.ts +10 -3
  56. package/lib/runtime/components/react/dist/context.js +1 -2
  57. package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
  58. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
  59. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
  60. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
  61. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  62. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
  63. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
  64. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
  65. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
  67. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
  68. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  73. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  75. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  76. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  77. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
  79. package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
  80. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
  81. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
  82. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  83. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  84. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  85. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
  86. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
  87. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
  88. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
  89. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
  90. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
  91. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
  92. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
  93. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
  94. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
  95. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
  96. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
  97. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
  98. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  99. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
  100. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
  101. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
  102. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
  103. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
  104. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
  105. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
  106. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
  107. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
  108. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
  109. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  110. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  111. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  112. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  113. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
  114. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  115. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
  116. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  117. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
  118. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
  119. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  120. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  121. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  122. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
  123. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  124. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  125. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +10 -1
  126. package/lib/runtime/components/react/dist/mpx-swiper.jsx +95 -61
  127. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  128. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  129. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
  130. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
  131. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  132. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
  133. package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
  134. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
  135. package/lib/runtime/components/react/dist/parser.d.ts +0 -1
  136. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
  137. package/lib/runtime/components/react/dist/utils.d.ts +10 -9
  138. package/lib/runtime/components/react/dist/utils.jsx +47 -24
  139. package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
  140. package/lib/runtime/components/react/mpx-image.tsx +2 -2
  141. package/lib/runtime/components/react/mpx-input.tsx +77 -54
  142. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
  143. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  144. package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
  145. package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
  146. package/lib/runtime/components/react/mpx-swiper.tsx +115 -60
  147. package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
  148. package/lib/runtime/components/react/mpx-view.tsx +27 -12
  149. package/lib/runtime/components/react/tsconfig.json +26 -0
  150. package/lib/runtime/components/react/types/global.d.ts +1 -0
  151. package/lib/runtime/components/react/utils.tsx +51 -27
  152. package/lib/runtime/optionProcessor.js +5 -0
  153. package/lib/runtime/optionProcessorReact.js +7 -0
  154. package/lib/runtime/stringify.wxs +2 -2
  155. package/lib/script-setup-compiler/index.js +1 -2
  156. package/lib/style-compiler/strip-conditional.js +243 -0
  157. package/lib/template-compiler/compiler.js +2 -5
  158. package/lib/utils/string.js +25 -1
  159. package/lib/wxss/loader.js +4 -1
  160. package/lib/wxss/utils.js +7 -2
  161. package/package.json +7 -14
  162. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  163. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  164. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  165. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  166. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  167. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  168. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  169. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  170. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  171. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  172. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  173. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  174. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  175. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  176. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  177. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  178. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  179. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  180. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  181. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  182. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  183. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  184. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  185. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  186. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  187. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  189. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  190. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  192. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  194. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  196. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  198. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  200. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  202. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  204. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  206. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  208. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  210. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  212. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  214. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  216. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  218. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  220. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  222. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  224. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  226. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  228. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  229. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  230. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  231. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  232. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  233. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  234. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  235. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  236. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  237. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  238. package/lib/style-compiler/strip-conditional-loader.js +0 -289
@@ -0,0 +1,301 @@
1
+ import { hasOwn, dash2hump, error, warn } from '@mpxjs/utils'
2
+ import { useMemo, useRef, useEffect } from 'react'
3
+ import {
4
+ Easing,
5
+ makeMutable,
6
+ runOnJS,
7
+ useSharedValue,
8
+ useAnimatedStyle,
9
+ cancelAnimation
10
+ } from 'react-native-reanimated'
11
+ import {
12
+ easingKey,
13
+ transitionSupportedProperty,
14
+ transformInitial,
15
+ cubicBezierExp,
16
+ secondRegExp,
17
+ percentExp,
18
+ getTransformObj,
19
+ getUnit,
20
+ getInitialVal,
21
+ getAnimation,
22
+ isTransform
23
+ } from './utils'
24
+ import { parseValues, useRunOnJSCallback } from '../utils'
25
+ import type { SharedValue, AnimatableValue, EasingFunction } from 'react-native-reanimated'
26
+ import type { TransformsStyle } from 'react-native'
27
+ import type { ExtendedViewStyle } from '../types/common'
28
+ import type { AnimationHooksPropsType, TransitionMap, TimingFunction } from './utils'
29
+
30
+ type AnimationDataType = {
31
+ property?: string
32
+ duration?: number
33
+ delay?: number
34
+ easing: EasingFunction
35
+ }
36
+ const propName = {
37
+ transition: '',
38
+ transitionDuration: 'duration',
39
+ transitionProperty: 'property',
40
+ transitionTimingFunction: 'easing',
41
+ transitionDelay: 'delay'
42
+ }
43
+ const behaviorExp = /^(allow-discrete|normal)$/
44
+ const defaultValueExp = /^(inherit|initial|revert|revert-layer|unset)$/
45
+ const timingFunctionExp = /^(step-start|step-end|steps)/
46
+ // cubic-bezier 参数解析
47
+ function getBezierParams (str: string) {
48
+ // ease 0.25, 0.1, 0.25, 1.0
49
+ return str.match(cubicBezierExp)?.[1]?.split(',').map(item => +item)
50
+ }
51
+ // 解析 transition-prop
52
+ function parseTransitionSingleProp (vals: string[], property: string) {
53
+ let setDuration = false
54
+ property = propName[property as keyof typeof propName]
55
+ return vals.map(val => {
56
+ // transition-property all
57
+ if (val === 'all') {
58
+ error('[Mpx runtime error]: the value of transition-property is not supported \'all\'')
59
+ return undefined
60
+ }
61
+ // behavior
62
+ if (behaviorExp.test(val)) {
63
+ error('[Mpx runtime error]: transition-behavior is not supported')
64
+ return undefined
65
+ }
66
+ // global values
67
+ if (defaultValueExp.test(val)) {
68
+ error('[Mpx runtime error]: global values is not supported')
69
+ return undefined
70
+ }
71
+ if (timingFunctionExp.test(val)) {
72
+ error('[Mpx runtime error]: the timingFunction in step-start,step-end,steps() is not supported')
73
+ return undefined
74
+ }
75
+ // timingFunction
76
+ if (Object.keys(easingKey).includes(val) || cubicBezierExp.test(val)) {
77
+ const bezierParams = getBezierParams(val)
78
+ return {
79
+ easing: bezierParams?.length ? Easing.bezier(bezierParams[0], bezierParams[1], bezierParams[2], bezierParams[3]) : easingKey[val as TimingFunction] || Easing.inOut(Easing.ease)
80
+ }
81
+ }
82
+ // duration & delay
83
+ if (secondRegExp.test(val)) {
84
+ const newProperty = property || (!setDuration ? 'duration' : 'delay')
85
+ setDuration = true
86
+ // console.log('parseTransitionSingleProp val=', val, property, setDuration)
87
+ return {
88
+ [newProperty]: getUnit(val)
89
+ }
90
+ }
91
+ // property
92
+ return {
93
+ property: dash2hump(val)
94
+ }
95
+ }).filter(item => item !== undefined)
96
+ }
97
+ // transition 解析
98
+ function parseTransitionStyle (originalStyle: ExtendedViewStyle) {
99
+ let transitionData: AnimationDataType[] = []
100
+ Object.entries(originalStyle).filter(arr => arr[0].includes('transition')).forEach(([prop, value]) => {
101
+ if (prop === 'transition') {
102
+ const vals = parseValues(value, ',').map(item => {
103
+ return parseTransitionSingleProp(parseValues(item), prop).reduce((map, subItem) => {
104
+ return Object.assign(map, subItem)
105
+ }, {} as AnimationDataType)
106
+ })
107
+ // console.log(`parseTransitionStyle ${prop}=${value} formatVal=`, vals)
108
+ if (transitionData.length) {
109
+ transitionData = (vals.length > transitionData.length ? vals : transitionData).map((transitionItem, i) => {
110
+ const valItem = vals[i] || {}
111
+ const current = transitionData[i] || {}
112
+ // console.log('parseTransitionStyle current=', current)
113
+ // console.log('parseTransitionStyle valItem=', valItem)
114
+ // console.log('parseTransitionStyle mergeObj=', Object.assign({}, current, valItem))
115
+ return Object.assign({}, current, valItem)
116
+ })
117
+ // console.log(`parseTransitionStyle ${prop}=${value}, transitionData=`, transitionData)
118
+ } else {
119
+ transitionData = vals
120
+ }
121
+ } else {
122
+ const vals = parseTransitionSingleProp(parseValues(value, ','), prop)
123
+ // console.log(`parseTransitionStyle ${prop}=${value} formatVal=`, vals)
124
+ // formatVal [{"property": "transform"}, {"property": "marginLeft"}]
125
+ if (transitionData.length) {
126
+ transitionData = (vals.length > transitionData.length ? vals : transitionData).map((transitionItem, i) => {
127
+ const valItem = vals[i] || vals[vals.length - 1]
128
+ const current = transitionData[i] || transitionData[transitionData.length - 1]
129
+ // console.log('parseTransitionStyle current=', current)
130
+ // console.log('parseTransitionStyle valItem=', valItem)
131
+ // console.log('parseTransitionStyle mergeObj=', Object.assign({}, current, valItem))
132
+ return Object.assign({}, current, valItem)
133
+ })
134
+ // console.log(`parseTransitionStyle ${prop}=${value}, transitionData=`, transitionData)
135
+ } else {
136
+ transitionData = vals as AnimationDataType[]
137
+ }
138
+ // transitionData.push(...vals)
139
+ }
140
+ })
141
+ // console.log(`parseTransitionStyle transitionData=`, transitionData)
142
+ // 从style 中解析的动画数据,结构如下:
143
+ // transitionMap= {"marginLeft": {"delay": 0, "duration": 3000, "easing": []}, "transform": {"delay": 0, "duration": 3000, "easing": []}}
144
+ const transitionMap = transitionData.reduce((acc, cur) => {
145
+ // hasOwn(transitionSupportedProperty, dash2hump(val)) || val === Transform
146
+ const { property = '', duration = 0, delay = 0, easing = Easing.inOut(Easing.ease) } = cur
147
+ if ((hasOwn(transitionSupportedProperty, dash2hump(property)) || property === 'transform') && duration > 0) {
148
+ acc[property] = {
149
+ duration,
150
+ delay,
151
+ easing
152
+ }
153
+ }
154
+ return acc
155
+ }, {} as TransitionMap)
156
+ // console.log(`parseTransitionStyle transitionMap=`, transitionMap)
157
+ return transitionMap
158
+ }
159
+
160
+ export default function useTransitionHooks<T, P> (props: AnimationHooksPropsType) {
161
+ // console.log(`useTransitionHooks, props=`, props)
162
+ const { style: originalStyle = {}, transitionend } = props
163
+ // style变更标识(首次render不执行),初始值为0,首次渲染后为1
164
+ const animationDeps = useRef(0)
165
+ // 记录上次style map
166
+ // const lastStyleRef = useRef({} as {[propName: keyof ExtendedViewStyle]: number|string})
167
+ // ** 从 style 中获取动画数据
168
+ const transitionMap = useMemo(() => {
169
+ return parseTransitionStyle(originalStyle)
170
+ }, [])
171
+ // ** style prop sharedValue interpolateOutput: SharedValue<InterpolateOutput>
172
+ const { shareValMap, animatedKeys, animatedStyleKeys } = useMemo(() => {
173
+ // 记录需要执行动画的 propName
174
+ const animatedKeys = [] as string[]
175
+ // 有动画样式的 style key(useAnimatedStyle使用)
176
+ const animatedStyleKeys = [] as (string|string[])[]
177
+ const transforms = [] as string[]
178
+ const shareValMap = Object.keys(transitionMap).reduce((valMap, property) => {
179
+ // const { property } = transition || {}
180
+ if (property === 'transform') {
181
+ Object.keys(originalStyle.transform ? getTransformObj(originalStyle.transform!) : transformInitial).forEach((key) => {
182
+ const defaultVal = getInitialVal(originalStyle, key)
183
+ // console.log(`shareValMap property=${key} defaultVal=${defaultVal}`)
184
+ valMap[key] = makeMutable(defaultVal)
185
+ animatedKeys.push(key)
186
+ transforms.push(key)
187
+ })
188
+ } else if (hasOwn(transitionSupportedProperty, property)) {
189
+ const defaultVal = getInitialVal(originalStyle, property)
190
+ // console.log(`shareValMap property=${property} defaultVal=${defaultVal}`)
191
+ valMap[property] = makeMutable(defaultVal)
192
+ animatedKeys.push(property)
193
+ animatedStyleKeys.push(property)
194
+ }
195
+ // console.log('shareValMap = ', valMap)
196
+ return valMap
197
+ }, {} as { [propName: keyof ExtendedViewStyle]: SharedValue<string|number> })
198
+ if (transforms.length) animatedStyleKeys.push(transforms)
199
+ return {
200
+ shareValMap,
201
+ animatedKeys,
202
+ animatedStyleKeys
203
+ }
204
+ }, [])
205
+ const runOnJSCallbackRef = useRef({})
206
+ const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
207
+ // 根据 animation action 创建&驱动动画
208
+ function createAnimation () {
209
+ let transformTransitionendDone = false
210
+ animatedKeys.forEach(key => {
211
+ // console.log(`createAnimation key=${key} originalStyle=`, originalStyle)
212
+ const isTransformKey = isTransform(key)
213
+ let ruleV = originalStyle[key]
214
+ if (isTransformKey) {
215
+ const transform = getTransformObj(originalStyle.transform!)
216
+ ruleV = transform[key]
217
+ }
218
+ let toVal = ruleV !== undefined
219
+ ? ruleV
220
+ : transitionSupportedProperty[key]
221
+ const shareVal = shareValMap[key].value
222
+ if (percentExp.test(`${toVal}`) && !percentExp.test(shareVal as string) && !isNaN(+shareVal)) {
223
+ // 获取到的toVal为百分比格式化shareValMap为百分比
224
+ shareValMap[key].value = `${shareVal as number * 100}%`
225
+ } else if (percentExp.test(shareVal as string) && !percentExp.test(toVal as string) && !isNaN(+toVal)) {
226
+ // 初始值为百分比则格式化toVal为百分比
227
+ toVal = `${toVal * 100}%`
228
+ } else if (typeof toVal !== typeof shareVal) {
229
+ // 动画起始值和终态值类型不一致报错提示一下
230
+ warn(`[Mpx runtime error]: Value types of property ${key} must be consistent during the animation`)
231
+ }
232
+ if ((toVal === 'auto' && !isNaN(+shareVal)) || (shareVal === 'auto' && !isNaN(+toVal))) {
233
+ // 有 auto 直接赋值不做动画
234
+ shareValMap[key].value = toVal
235
+ } else {
236
+ // console.log(`key=${key} oldVal=${shareValMap[key].value} newVal=${toVal}`)
237
+ const { delay = 0, duration, easing } = transitionMap[isTransformKey ? 'transform' : key]
238
+ // console.log('animationOptions=', { delay, duration, easing })
239
+ let callback
240
+ if (transitionend && (!isTransformKey || !transformTransitionendDone)) {
241
+ runOnJSCallbackRef.current = {
242
+ animationCallback: (duration: number, finished: boolean, current?: AnimatableValue) => {
243
+ transitionend(finished, current, duration)
244
+ }
245
+ }
246
+ callback = (finished?: boolean, current?: AnimatableValue) => {
247
+ 'worklet'
248
+ // 动画结束后设置下一次transformOrigin
249
+ if (finished) {
250
+ runOnJS(runOnJSCallback)('animationCallback', duration, finished, current)
251
+ }
252
+ }
253
+ }
254
+ const animation = getAnimation({ key, value: toVal! }, { delay, duration, easing }, callback)
255
+ // Todo transform 有多个属性时也仅执行一次 transitionend(对齐wx)
256
+ if (isTransformKey) {
257
+ transformTransitionendDone = true
258
+ }
259
+ shareValMap[key].value = animation
260
+ }
261
+ // console.log(`useTransitionHooks, ${key}=`, animation)
262
+ })
263
+ }
264
+ // ** style 更新
265
+ useEffect(() => {
266
+ // console.log('useEffect originalStyle animationDeps=', animationDeps.current, originalStyle)
267
+ // 首次不执行
268
+ if (!animationDeps.current) {
269
+ animationDeps.current = 1
270
+ return
271
+ }
272
+ createAnimation()
273
+ }, [originalStyle])
274
+ // ** 清空动画
275
+ useEffect(() => {
276
+ return () => {
277
+ Object.values(shareValMap).forEach((value) => {
278
+ cancelAnimation(value)
279
+ })
280
+ }
281
+ }, [])
282
+ // ** 生成动画样式
283
+ return useAnimatedStyle(() => {
284
+ // console.info(`useAnimatedStyle styles=`, originalStyle)
285
+ return animatedStyleKeys.reduce((styles, key) => {
286
+ if (Array.isArray(key)) {
287
+ const transformStyle = getTransformObj(originalStyle.transform || [])
288
+ key.forEach((transformKey) => {
289
+ transformStyle[transformKey] = shareValMap[transformKey].value
290
+ })
291
+ styles.transform = Object.entries(transformStyle).map(([key, value]) => {
292
+ return { [key]: value }
293
+ }) as Extract<'transform', TransformsStyle>
294
+ } else {
295
+ styles[key] = shareValMap[key].value
296
+ }
297
+ // console.log('animationStyle', styles)
298
+ return styles
299
+ }, {} as ExtendedViewStyle)
300
+ })
301
+ }
@@ -0,0 +1,197 @@
1
+ import {
2
+ Easing,
3
+ withTiming,
4
+ withDelay
5
+ } from 'react-native-reanimated'
6
+ import type { AnimatableValue, WithTimingConfig, AnimationCallback, EasingFunction } from 'react-native-reanimated'
7
+ import { hasOwn } from '@mpxjs/utils'
8
+ import type { ExtendedViewStyle } from '../types/common'
9
+ import type { _ViewProps } from '../mpx-view'
10
+
11
+ export type TimingFunction = 'linear' | 'ease' | 'ease-in' | 'ease-in-out'| 'ease-out'
12
+
13
+ export type AnimatedOption = {
14
+ duration: number
15
+ delay?: number
16
+ useNativeDriver?: boolean
17
+ timingFunction?: TimingFunction
18
+ transformOrigin?: string
19
+ }
20
+ export type ExtendWithTimingConfig = WithTimingConfig & {
21
+ delay?: number
22
+ }
23
+ export type AnimationStepItem = {
24
+ animatedOption: AnimatedOption
25
+ rules: Map<string, number | string>
26
+ transform: Map<string, number>
27
+ }
28
+ export type AnimationProp = {
29
+ id: number,
30
+ actions: AnimationStepItem[]
31
+ }
32
+
33
+ export type CustomAnimationCallback = (finished?: boolean, current?: AnimatableValue, duration?: number) => void
34
+
35
+ export type TransitionMap = {
36
+ [propName: string]: {
37
+ duration: number
38
+ delay?: number
39
+ easing: EasingFunction
40
+ }
41
+ }
42
+
43
+ export type InterpolateOutput = {
44
+ [propName: string]: string[]
45
+ }
46
+
47
+ export type AnimationHooksPropsType = _ViewProps & { transitionend?: CustomAnimationCallback }
48
+
49
+ // ms s 单位匹配
50
+ export const secondRegExp = /^\s*(\d*(?:\.\d+)?)(s|ms)?\s*$/
51
+ export const cubicBezierExp = /cubic-bezier\(["']?(.*?)["']?\)/
52
+ export const percentExp = /^((-?(\d+(\.\d+)?|\.\d+))%)$/
53
+ // export const PropNameColorExp = /^c|Color$/
54
+ // export const NumberExp = /^((opacity|flex-grow|flex-shrink|gap|left|right|top|bottom)|(.+-(width|height|left|right|top|bottom|radius|spacing|size|gap|index|offset|opacity)))$/
55
+ // export const ColorExp = /^(color|(.+Color))$/
56
+ // transform
57
+ // export const transform = 'transform'
58
+ // export const transformOrigin = 'transformOrigin'
59
+ // export const transition = 'transition'
60
+
61
+ // 微信 timingFunction 和 RN Easing 对应关系
62
+ export const easingKey = {
63
+ linear: Easing.linear,
64
+ ease: Easing.inOut(Easing.ease),
65
+ 'ease-in': Easing.in(Easing.poly(3)),
66
+ 'ease-in-out': Easing.inOut(Easing.poly(3)),
67
+ 'ease-out': Easing.out(Easing.poly(3))
68
+ // 'step-start': '',
69
+ // 'step-end': ''
70
+ }
71
+ export const transformInitial: ExtendedViewStyle = {
72
+ // matrix: 0,
73
+ // matrix3d: 0,
74
+ // rotate: '0deg',
75
+ rotateX: '0deg',
76
+ rotateY: '0deg',
77
+ rotateZ: '0deg',
78
+ // rotate3d:[0,0,0]
79
+ // scale: 1,
80
+ // scale3d: [1, 1, 1],
81
+ scaleX: 1,
82
+ scaleY: 1,
83
+ // scaleZ: 1,
84
+ // skew: 0,
85
+ skewX: '0deg',
86
+ skewY: '0deg',
87
+ // translate: 0,
88
+ // translate3d: 0,
89
+ translateX: 0,
90
+ translateY: 0
91
+ // translateZ: 0,
92
+ }
93
+ // animation api 动画默认初始值
94
+ export const animationAPIInitialValue: ExtendedViewStyle = Object.assign({
95
+ opacity: 1,
96
+ backgroundColor: 'transparent',
97
+ // fixme 未设置 height 初始值定义了 transition-property height 时把动画高度值把原由子元素撑开的高度给覆盖的问题
98
+ width: 'auto',
99
+ height: 'auto',
100
+ top: 0,
101
+ right: 0,
102
+ bottom: 0,
103
+ left: 0,
104
+ transformOrigin: ['50%', '50%', 0]
105
+ }, transformInitial)
106
+ // transition property
107
+ export const transitionSupportedProperty = Object.assign({
108
+ color: 'transparent',
109
+ borderColor: 'transparent',
110
+ borderBottomColor: 'transparent',
111
+ borderLeftColor: 'transparent',
112
+ borderRightColor: 'transparent',
113
+ borderTopColor: 'transparent',
114
+ borderTopLeftRadius: 0,
115
+ borderTopRightRadius: 0,
116
+ borderBottomLeftRadius: 0,
117
+ borderBottomRightRadius: 0,
118
+ borderRadius: 0,
119
+ borderBottomWidth: 0,
120
+ borderLeftWidth: 0,
121
+ borderRightWidth: 0,
122
+ borderTopWidth: 0,
123
+ borderWidth: 0,
124
+ margin: 0,
125
+ marginBottom: 0,
126
+ marginLeft: 0,
127
+ marginRight: 0,
128
+ marginTop: 0,
129
+ marginHorizontal: 0,
130
+ marginVertical: 0,
131
+ maxHeight: 0,
132
+ maxWidth: 0,
133
+ minHeight: 0,
134
+ minWidth: 0,
135
+ padding: 0,
136
+ paddingBottom: 0,
137
+ paddingLeft: 0,
138
+ paddingRight: 0,
139
+ paddingTop: 0,
140
+ paddingHorizontal: 0,
141
+ paddingVertical: 0,
142
+ fontSize: 0, // Todo
143
+ letterSpacing: 0 // Todo
144
+ }, animationAPIInitialValue)
145
+
146
+ // export type PropertyType = keyof transitionSupportedProperty
147
+ // transform
148
+ export const isTransform = (key: string) => hasOwn(transformInitial, key)
149
+ // transform 数组转对象
150
+ export function getTransformObj (transforms: { [propName: string]: string | number }[]) {
151
+ 'worklet'
152
+ return (transforms || []).reduce((transformObj, item) => {
153
+ return Object.assign(transformObj, item)
154
+ }, {} as { [propName: string]: string | number })
155
+ }
156
+ // 获取样式初始值(prop style or 默认值)
157
+ export function getInitialVal (style: ExtendedViewStyle, key: string) {
158
+ if (isTransform(key) && Array.isArray(style.transform)) {
159
+ let initialVal = transitionSupportedProperty[key]
160
+ // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
161
+ style.transform.forEach(item => {
162
+ if (item[key] !== undefined) initialVal = item[key]
163
+ })
164
+ return initialVal
165
+ }
166
+ return style[key] === undefined ? transitionSupportedProperty[key] : style[key]
167
+ }
168
+ // animated key transform 格式化
169
+ export function formatAnimatedKeys (keys: string[]) {
170
+ // console.log('formatAnimatedKeys keys=', keys)
171
+ const animatedKeys = [] as (string|string[])[]
172
+ const transforms = [] as string[]
173
+ keys.forEach(key => {
174
+ if (isTransform(key)) {
175
+ transforms.push(key)
176
+ } else {
177
+ animatedKeys.push(key)
178
+ }
179
+ })
180
+ if (transforms.length) animatedKeys.push(transforms)
181
+ // console.log('formatAnimatedKeys animatedKeys=', animatedKeys)
182
+ return animatedKeys
183
+ }
184
+ // 解析动画时长
185
+ export function getUnit (duration: string) {
186
+ const match = secondRegExp.exec(duration)
187
+ return match ? match[2] === 's' ? +match[1] * 1000 : +match[1] : 0
188
+ }
189
+
190
+ // 根据动画数据创建单个animation
191
+ export function getAnimation ({ key, value }: { key: string, value: string|number }, { delay = 0, duration, easing }: ExtendWithTimingConfig, callback?: AnimationCallback) {
192
+ // console.log('getAnimation', key, value, delay, duration, easing)
193
+ const animation = typeof callback === 'function'
194
+ ? withTiming(value, { duration, easing }, callback)
195
+ : withTiming(value, { duration, easing })
196
+ return delay ? withDelay(delay, animation) : animation
197
+ }
@@ -1,5 +1,5 @@
1
1
  import { createContext, Dispatch, MutableRefObject, SetStateAction } from 'react'
2
- import { NativeSyntheticEvent, Animated } from 'react-native'
2
+ import type { NativeSyntheticEvent, Animated, ScaledSize } from 'react-native'
3
3
  import { noop } from '@mpxjs/utils'
4
4
 
5
5
  export type LabelContextValue = MutableRefObject<{
@@ -10,8 +10,12 @@ export type KeyboardAvoidContextValue = MutableRefObject<{
10
10
  cursorSpacing: number
11
11
  ref: MutableRefObject<any>
12
12
  adjustPosition: boolean
13
+ holdKeyboard?: boolean
13
14
  keyboardHeight?: number
15
+ /** @internal bindfocus 异步延迟上报方法 */
14
16
  onKeyboardShow?: () => void
17
+ /** @internal 多个 Input 切换聚焦场景标记位 */
18
+ readyToShow?: boolean
15
19
  } | null>
16
20
 
17
21
  export interface GroupValue {
@@ -48,7 +52,7 @@ export interface PortalContextValue {
48
52
 
49
53
  export interface ScrollViewContextValue {
50
54
  gestureRef: React.RefObject<any> | null
51
- scrollOffset: Animated.Value
55
+ scrollOffset: Animated.Value | null
52
56
  }
53
57
 
54
58
  export interface RouteContextValue {
@@ -56,6 +60,11 @@ export interface RouteContextValue {
56
60
  navigation: Record<string, any>
57
61
  }
58
62
 
63
+ export interface DimensionsValue {
64
+ window: ScaledSize;
65
+ screen: ScaledSize;
66
+ }
67
+
59
68
  export interface StickyContextValue {
60
69
  registerStickyHeader: Function
61
70
  unregisterStickyHeader: Function
@@ -83,7 +92,7 @@ export const SwiperContext = createContext({})
83
92
 
84
93
  export const KeyboardAvoidContext = createContext<KeyboardAvoidContextValue | null>(null)
85
94
 
86
- export const ScrollViewContext = createContext<ScrollViewContextValue>({ gestureRef: null, scrollOffset: new Animated.Value(0) })
95
+ export const ScrollViewContext = createContext<ScrollViewContextValue>({ gestureRef: null, scrollOffset: null })
87
96
 
88
97
  export const PortalContext = createContext<PortalContextValue>(null as any)
89
98
 
@@ -0,0 +1,15 @@
1
+ import type { MutableRefObject } from 'react';
2
+ import type { NativeSyntheticEvent } from 'react-native';
3
+ import type { _ViewProps } from '../mpx-view';
4
+ export type AnimationType = 'api' | 'animation' | 'transition' | 'none';
5
+ export default function useAnimationHooks<T, P>(props: _ViewProps & {
6
+ enableAnimation?: boolean | AnimationType;
7
+ layoutRef: MutableRefObject<any>;
8
+ transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
9
+ }): {
10
+ enableStyleAnimation: boolean;
11
+ animationStyle?: undefined;
12
+ } | {
13
+ enableStyleAnimation: boolean;
14
+ animationStyle: import("../types/common").ExtendedViewStyle;
15
+ };
@@ -0,0 +1,67 @@
1
+ import { error, collectDataset, hasOwn } from '@mpxjs/utils';
2
+ import { useRef } from 'react';
3
+ import useAnimationAPIHooks from './useAnimationAPIHooks';
4
+ import useTransitionHooks from './useTransitionHooks';
5
+ export default function useAnimationHooks(props) {
6
+ const { style: originalStyle = {}, enableAnimation, animation, transitionend, layoutRef } = props;
7
+ // 记录动画类型
8
+ let animationType = '';
9
+ if (hasOwn(originalStyle, 'animation') || (hasOwn(originalStyle, 'animationName') && hasOwn(originalStyle, 'animationDuration'))) {
10
+ // css animation 只做检测提示
11
+ animationType = 'animation';
12
+ }
13
+ if (!!animation || enableAnimation === true) {
14
+ animationType = 'api';
15
+ }
16
+ // 优先级 css transition > API
17
+ if (hasOwn(originalStyle, 'transition') || (hasOwn(originalStyle, 'transitionProperty') && hasOwn(originalStyle, 'transitionDuration'))) {
18
+ animationType = 'transition';
19
+ }
20
+ // 优先以 enableAnimation 定义类型为准
21
+ if (enableAnimation === 'api' || enableAnimation === 'transition' || enableAnimation === 'animation') {
22
+ animationType = enableAnimation;
23
+ }
24
+ const animationTypeRef = useRef(animationType);
25
+ if (animationType && animationTypeRef.current !== animationType) {
26
+ // 允许 API、CssTransition 到 none,不允许 API、CssTransition 互切,不允许 none 到 API、CssTransition
27
+ error('[Mpx runtime error]: The animation type should be stable in the component lifecycle, or you can set animation type with [enable-animation].');
28
+ }
29
+ if (animationType === 'animation') {
30
+ // 暂不支持 CssAnimation 提示
31
+ error('[Mpx runtime error]: CSS animation is not supported yet');
32
+ return { enableStyleAnimation: false };
33
+ }
34
+ if (!animationTypeRef.current)
35
+ return { enableStyleAnimation: false };
36
+ const hooksProps = { style: originalStyle };
37
+ if (transitionend && typeof transitionend === 'function') {
38
+ function withTimingCallback(finished, current, duration) {
39
+ const target = {
40
+ id: animation?.id || -1,
41
+ dataset: collectDataset(props),
42
+ offsetLeft: layoutRef?.current?.offsetLeft || 0,
43
+ offsetTop: layoutRef?.current?.offsetTop || 0
44
+ };
45
+ transitionend({
46
+ type: 'transitionend',
47
+ // elapsedTime 对齐wx 单位s
48
+ detail: { elapsedTime: duration ? duration / 1000 : 0, finished, current },
49
+ target,
50
+ currentTarget: target,
51
+ timeStamp: Date.now()
52
+ });
53
+ }
54
+ Object.assign(hooksProps, { transitionend: withTimingCallback });
55
+ }
56
+ if (animationTypeRef.current === 'api') {
57
+ Object.assign(hooksProps, { animation });
58
+ }
59
+ return {
60
+ enableStyleAnimation: !!animationTypeRef.current,
61
+ animationStyle: animationTypeRef.current === 'api'
62
+ // eslint-disable-next-line react-hooks/rules-of-hooks
63
+ ? useAnimationAPIHooks(hooksProps)
64
+ // eslint-disable-next-line react-hooks/rules-of-hooks
65
+ : useTransitionHooks(hooksProps)
66
+ };
67
+ }
@@ -0,0 +1,3 @@
1
+ import type { ExtendedViewStyle } from '../types/common';
2
+ import type { AnimationHooksPropsType } from './utils';
3
+ export default function useAnimationAPIHooks<T, P>(props: AnimationHooksPropsType): ExtendedViewStyle;