@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,151 @@
1
+ import { Easing, withTiming, withDelay } from 'react-native-reanimated';
2
+ import { hasOwn } from '@mpxjs/utils';
3
+ // ms s 单位匹配
4
+ export const secondRegExp = /^\s*(\d*(?:\.\d+)?)(s|ms)?\s*$/;
5
+ export const cubicBezierExp = /cubic-bezier\(["']?(.*?)["']?\)/;
6
+ export const percentExp = /^((-?(\d+(\.\d+)?|\.\d+))%)$/;
7
+ // export const PropNameColorExp = /^c|Color$/
8
+ // 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)))$/
9
+ // export const ColorExp = /^(color|(.+Color))$/
10
+ // transform
11
+ // export const transform = 'transform'
12
+ // export const transformOrigin = 'transformOrigin'
13
+ // export const transition = 'transition'
14
+ // 微信 timingFunction 和 RN Easing 对应关系
15
+ export const easingKey = {
16
+ linear: Easing.linear,
17
+ ease: Easing.inOut(Easing.ease),
18
+ 'ease-in': Easing.in(Easing.poly(3)),
19
+ 'ease-in-out': Easing.inOut(Easing.poly(3)),
20
+ 'ease-out': Easing.out(Easing.poly(3))
21
+ // 'step-start': '',
22
+ // 'step-end': ''
23
+ };
24
+ export const transformInitial = {
25
+ // matrix: 0,
26
+ // matrix3d: 0,
27
+ // rotate: '0deg',
28
+ rotateX: '0deg',
29
+ rotateY: '0deg',
30
+ rotateZ: '0deg',
31
+ // rotate3d:[0,0,0]
32
+ // scale: 1,
33
+ // scale3d: [1, 1, 1],
34
+ scaleX: 1,
35
+ scaleY: 1,
36
+ // scaleZ: 1,
37
+ // skew: 0,
38
+ skewX: '0deg',
39
+ skewY: '0deg',
40
+ // translate: 0,
41
+ // translate3d: 0,
42
+ translateX: 0,
43
+ translateY: 0
44
+ // translateZ: 0,
45
+ };
46
+ // animation api 动画默认初始值
47
+ export const animationAPIInitialValue = Object.assign({
48
+ opacity: 1,
49
+ backgroundColor: 'transparent',
50
+ // fixme 未设置 height 初始值定义了 transition-property height 时把动画高度值把原由子元素撑开的高度给覆盖的问题
51
+ width: 'auto',
52
+ height: 'auto',
53
+ top: 0,
54
+ right: 0,
55
+ bottom: 0,
56
+ left: 0,
57
+ transformOrigin: ['50%', '50%', 0]
58
+ }, transformInitial);
59
+ // transition property
60
+ export const transitionSupportedProperty = Object.assign({
61
+ color: 'transparent',
62
+ borderColor: 'transparent',
63
+ borderBottomColor: 'transparent',
64
+ borderLeftColor: 'transparent',
65
+ borderRightColor: 'transparent',
66
+ borderTopColor: 'transparent',
67
+ borderTopLeftRadius: 0,
68
+ borderTopRightRadius: 0,
69
+ borderBottomLeftRadius: 0,
70
+ borderBottomRightRadius: 0,
71
+ borderRadius: 0,
72
+ borderBottomWidth: 0,
73
+ borderLeftWidth: 0,
74
+ borderRightWidth: 0,
75
+ borderTopWidth: 0,
76
+ borderWidth: 0,
77
+ margin: 0,
78
+ marginBottom: 0,
79
+ marginLeft: 0,
80
+ marginRight: 0,
81
+ marginTop: 0,
82
+ marginHorizontal: 0,
83
+ marginVertical: 0,
84
+ maxHeight: 0,
85
+ maxWidth: 0,
86
+ minHeight: 0,
87
+ minWidth: 0,
88
+ padding: 0,
89
+ paddingBottom: 0,
90
+ paddingLeft: 0,
91
+ paddingRight: 0,
92
+ paddingTop: 0,
93
+ paddingHorizontal: 0,
94
+ paddingVertical: 0,
95
+ fontSize: 0,
96
+ letterSpacing: 0 // Todo
97
+ }, animationAPIInitialValue);
98
+ // export type PropertyType = keyof transitionSupportedProperty
99
+ // transform
100
+ export const isTransform = (key) => hasOwn(transformInitial, key);
101
+ // transform 数组转对象
102
+ export function getTransformObj(transforms) {
103
+ 'worklet';
104
+ return (transforms || []).reduce((transformObj, item) => {
105
+ return Object.assign(transformObj, item);
106
+ }, {});
107
+ }
108
+ // 获取样式初始值(prop style or 默认值)
109
+ export function getInitialVal(style, key) {
110
+ if (isTransform(key) && Array.isArray(style.transform)) {
111
+ let initialVal = transitionSupportedProperty[key];
112
+ // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
113
+ style.transform.forEach(item => {
114
+ if (item[key] !== undefined)
115
+ initialVal = item[key];
116
+ });
117
+ return initialVal;
118
+ }
119
+ return style[key] === undefined ? transitionSupportedProperty[key] : style[key];
120
+ }
121
+ // animated key transform 格式化
122
+ export function formatAnimatedKeys(keys) {
123
+ // console.log('formatAnimatedKeys keys=', keys)
124
+ const animatedKeys = [];
125
+ const transforms = [];
126
+ keys.forEach(key => {
127
+ if (isTransform(key)) {
128
+ transforms.push(key);
129
+ }
130
+ else {
131
+ animatedKeys.push(key);
132
+ }
133
+ });
134
+ if (transforms.length)
135
+ animatedKeys.push(transforms);
136
+ // console.log('formatAnimatedKeys animatedKeys=', animatedKeys)
137
+ return animatedKeys;
138
+ }
139
+ // 解析动画时长
140
+ export function getUnit(duration) {
141
+ const match = secondRegExp.exec(duration);
142
+ return match ? match[2] === 's' ? +match[1] * 1000 : +match[1] : 0;
143
+ }
144
+ // 根据动画数据创建单个animation
145
+ export function getAnimation({ key, value }, { delay = 0, duration, easing }, callback) {
146
+ // console.log('getAnimation', key, value, delay, duration, easing)
147
+ const animation = typeof callback === 'function'
148
+ ? withTiming(value, { duration, easing }, callback)
149
+ : withTiming(value, { duration, easing });
150
+ return delay ? withDelay(delay, animation) : animation;
151
+ }
@@ -1,5 +1,5 @@
1
1
  import { Dispatch, MutableRefObject, SetStateAction } from 'react';
2
- import { NativeSyntheticEvent, Animated } from 'react-native';
2
+ import type { NativeSyntheticEvent, Animated, ScaledSize } from 'react-native';
3
3
  export type LabelContextValue = MutableRefObject<{
4
4
  triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void;
5
5
  }>;
@@ -7,8 +7,12 @@ export type KeyboardAvoidContextValue = MutableRefObject<{
7
7
  cursorSpacing: number;
8
8
  ref: MutableRefObject<any>;
9
9
  adjustPosition: boolean;
10
+ holdKeyboard?: boolean;
10
11
  keyboardHeight?: number;
12
+ /** @internal bindfocus 异步延迟上报方法 */
11
13
  onKeyboardShow?: () => void;
14
+ /** @internal 多个 Input 切换聚焦场景标记位 */
15
+ readyToShow?: boolean;
12
16
  } | null>;
13
17
  export interface GroupValue {
14
18
  [key: string]: {
@@ -44,12 +48,16 @@ export interface PortalContextValue {
44
48
  }
45
49
  export interface ScrollViewContextValue {
46
50
  gestureRef: React.RefObject<any> | null;
47
- scrollOffset: Animated.Value;
51
+ scrollOffset: Animated.Value | null;
48
52
  }
49
53
  export interface RouteContextValue {
50
54
  pageId: number;
51
55
  navigation: Record<string, any>;
52
56
  }
57
+ export interface DimensionsValue {
58
+ window: ScaledSize;
59
+ screen: ScaledSize;
60
+ }
53
61
  export interface StickyContextValue {
54
62
  registerStickyHeader: Function;
55
63
  unregisterStickyHeader: Function;
@@ -72,4 +80,3 @@ export declare const ScrollViewContext: import("react").Context<ScrollViewContex
72
80
  export declare const PortalContext: import("react").Context<PortalContextValue>;
73
81
  export declare const StickyContext: import("react").Context<StickyContextValue>;
74
82
  export declare const ProviderContext: import("react").Context<null>;
75
- //# sourceMappingURL=context.d.ts.map
@@ -1,5 +1,4 @@
1
1
  import { createContext } from 'react';
2
- import { Animated } from 'react-native';
3
2
  import { noop } from '@mpxjs/utils';
4
3
  export const MovableAreaContext = createContext({ width: 0, height: 0 });
5
4
  export const FormContext = createContext(null);
@@ -12,7 +11,7 @@ export const IntersectionObserverContext = createContext(null);
12
11
  export const RouteContext = createContext(null);
13
12
  export const SwiperContext = createContext({});
14
13
  export const KeyboardAvoidContext = createContext(null);
15
- export const ScrollViewContext = createContext({ gestureRef: null, scrollOffset: new Animated.Value(0) });
14
+ export const ScrollViewContext = createContext({ gestureRef: null, scrollOffset: null });
16
15
  export const PortalContext = createContext(null);
17
16
  export const StickyContext = createContext({ registerStickyHeader: noop, unregisterStickyHeader: noop });
18
17
  export const ProviderContext = createContext(null);
@@ -5,4 +5,3 @@ declare const eventConfigMap: {
5
5
  };
6
6
  };
7
7
  export default eventConfigMap;
8
- //# sourceMappingURL=event.config.d.ts.map
@@ -5,4 +5,3 @@ export declare const getCustomEvent: (type: string | undefined, oe: any, { detai
5
5
  }, props?: Props) => any;
6
6
  declare const useInnerProps: (props?: Props, userRemoveProps?: RemoveProps, rawConfig?: RawConfig) => Record<string, (e: ExtendedNativeTouchEvent) => void> & Omit<Props, string>;
7
7
  export default useInnerProps;
8
- //# sourceMappingURL=getInnerListeners.d.ts.map
@@ -10,4 +10,3 @@ interface AsyncSuspenseProps {
10
10
  }
11
11
  declare const AsyncSuspense: React.FC<AsyncSuspenseProps>;
12
12
  export default AsyncSuspense;
13
- //# sourceMappingURL=mpx-async-suspense.d.ts.map
@@ -1,6 +1,5 @@
1
1
  import { useState, useEffect, useCallback, useRef, createElement } from 'react';
2
2
  import { View, Image, StyleSheet, Text, TouchableOpacity } from 'react-native';
3
- import FastImage from '@d11/react-native-fast-image';
4
3
  const asyncChunkMap = new Map();
5
4
  const styles = StyleSheet.create({
6
5
  container: {
@@ -63,6 +62,9 @@ const DefaultFallback = ({ onReload }) => {
63
62
  </View>);
64
63
  };
65
64
  const DefaultLoading = () => {
65
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
66
+ const FastImageModule = require('@d11/react-native-fast-image');
67
+ const FastImage = FastImageModule.default || FastImageModule;
66
68
  return (<View style={styles.container}>
67
69
  <FastImage style={styles.loadingImage} source={{
68
70
  uri: 'https://dpubstatic.udache.com/static/dpubimg/439jiCVOtNOnEv9F2LaDs_loading.gif'
@@ -66,4 +66,3 @@ export interface ButtonProps {
66
66
  }
67
67
  declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HandlerRef<View, ButtonProps>>>;
68
68
  export default Button;
69
- //# sourceMappingURL=mpx-button.d.ts.map
@@ -21,4 +21,3 @@ export default class Bus {
21
21
  clearBatchingTimeout(): void;
22
22
  }
23
23
  export {};
24
- //# sourceMappingURL=Bus.d.ts.map
@@ -5,4 +5,3 @@ export default class CanvasGradient {
5
5
  constructor(canvas: CanvasInstance, noOnConstruction?: boolean);
6
6
  postMessage(message: WebviewMessage): Promise<any>;
7
7
  }
8
- //# sourceMappingURL=CanvasGradient.d.ts.map
@@ -4,4 +4,3 @@ export default class CanvasRenderingContext2D {
4
4
  constructor(canvas: CanvasInstance);
5
5
  postMessage(message: WebviewMessage): Promise<any>;
6
6
  }
7
- //# sourceMappingURL=CanvasRenderingContext2D.d.ts.map
@@ -18,4 +18,3 @@ export declare class Image {
18
18
  get onerror(): ((...args: any[]) => void);
19
19
  }
20
20
  export declare function createImage(canvas: CanvasInstance, width?: number, height?: number): Image;
21
- //# sourceMappingURL=Image.d.ts.map
@@ -6,4 +6,3 @@ export default class ImageData {
6
6
  postMessage: (message: WebviewMessage) => Promise<any>;
7
7
  }
8
8
  export declare function createImageData(canvas: CanvasInstance, dataArray: number[], width: number, height: number): ImageData;
9
- //# sourceMappingURL=ImageData.d.ts.map
@@ -8,4 +8,3 @@ export declare function useConstructorsRegistry(): {
8
8
  register: (registerWebviewConstructor: Function) => void;
9
9
  getConstructor: (type: ConstructorType) => WebviewConstructor | undefined;
10
10
  };
11
- //# sourceMappingURL=constructorsRegistry.d.ts.map
@@ -1,3 +1,2 @@
1
1
  declare const _default: "<html><head>\n <meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no\" name=\"viewport\">\n <style>\n html {\n -ms-content-zooming: none;\n -ms-touch-action: pan-x pan-y;\n }\n body {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n margin: 0;\n padding: 0;\n overflow: hidden;\n }\n * {\n user-select: none;\n -ms-user-select: none;\n -moz-user-select: none;\n -webkit-user-select: none;\n }\n </style>\n </head>\n <body>\n <script>\n var scale = function (ratio) {\n return function (item) {\n if (typeof item === \"number\") {\n return item * ratio;\n }\n return item;\n };\n};\nfunction autoScaleCanvas(canvas) {\n var ctx = canvas.getContext(\"2d\");\n var ratio = window.devicePixelRatio || 1;\n if (ratio !== 1) {\n canvas.width *= ratio;\n canvas.height *= ratio;\n ctx.scale(ratio, ratio);\n ctx.isPointInPath = function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n return CanvasRenderingContext2D.prototype.isPointInPath.apply(ctx, args.map(scale(ratio)));\n };\n }\n return canvas;\n}\nwindow.autoScaleCanvas = autoScaleCanvas;\n</script>\n<script>\n\nvar WEBVIEW_TARGET = '@@WEBVIEW_TARGET';\n\nvar ID = function () {\n return Math.random().toString(32).slice(2);\n};\n\nvar flattenObjectCopyValue = function (flatObj, srcObj, key) {\n var value = srcObj[key];\n if (typeof value === 'function') {\n return;\n }\n if (typeof value === 'object' && value instanceof Node) {\n return;\n }\n flatObj[key] = flattenObject(value);\n};\n\nvar flattenObject = function (object) {\n if (typeof object !== 'object' || object === null) {\n return object;\n }\n // Handle TypedArray\n if (object instanceof Uint8ClampedArray) {\n return Array.from(object);\n }\n var flatObject = {};\n for (var key in object) {\n flattenObjectCopyValue(flatObject, object, key);\n }\n for (var key in Object.getOwnPropertyNames(object)) {\n flattenObjectCopyValue(flatObject, object, key);\n }\n return flatObject;\n};\n\nvar AutoScaledCanvas = function (element) {\n this.element = element;\n};\n\nAutoScaledCanvas.prototype.toDataURL = function () {\n return this.element.toDataURL.apply(this.element, arguments);\n};\n\nAutoScaledCanvas.prototype.autoScale = function () {\n if (this.savedHeight !== undefined) {\n this.element.height = this.savedHeight;\n }\n if (this.savedWidth !== undefined) {\n this.element.width = this.savedWidth;\n }\n window.autoScaleCanvas(this.element);\n};\n\nObject.defineProperty(AutoScaledCanvas.prototype, 'width', {\n get: function () {\n return this.element.width;\n },\n set: function (value) {\n this.savedWidth = value;\n this.autoScale();\n return value;\n },\n});\n\nObject.defineProperty(AutoScaledCanvas.prototype, 'height', {\n get: function () {\n return this.element.height;\n },\n set: function (value) {\n this.savedHeight = value;\n this.autoScale();\n return value;\n },\n});\nvar toMessage = function (result) {\n if (result instanceof Blob) {\n return {\n type: 'blob',\n payload: btoa(result),\n meta: {},\n };\n }\n if (result instanceof Object) {\n if (!result[WEBVIEW_TARGET]) {\n var id = ID();\n result[WEBVIEW_TARGET] = id;\n targets[id] = result;\n }\n return {\n type: 'json',\n payload: flattenObject(result),\n args: toArgs(flattenObject(result)),\n meta: {\n target: result[WEBVIEW_TARGET],\n constructor: result.__constructorName__ || result.constructor.name,\n },\n };\n }\n return {\n type: 'json',\n payload: typeof result === 'string' ? result : JSON.stringify(result),\n meta: {},\n };\n};\nvar toArgs = function (result) {\n var args = [];\n for (var key in result) {\n if (result[key] !== undefined && key !== '@@WEBVIEW_TARGET') {\n args.push(result[key]);\n }\n }\n return args;\n};\n\nvar createObjectsFromArgs = function (args) {\n for (var index = 0; index < args.length; index += 1) {\n var currentArg = args[index];\n if (currentArg && currentArg.className !== undefined) {\n var className = currentArg.className, classArgs = currentArg.classArgs;\n // new ImageData,第一个参数需要是 Uint8ClampedArray\n var object = new (Function.prototype.bind.apply(constructors[className], [null].concat(classArgs)))();\n args[index] = object;\n }\n }\n return args;\n};\n\nvar canvas = document.createElement('canvas');\ncanvas.style.width = '100%';\ncanvas.style.height = '100%';\nvar autoScaledCanvas = new AutoScaledCanvas(canvas);\n\nvar targets = {\n canvas: autoScaledCanvas,\n context2D: canvas.getContext('2d'),\n};\n\nvar constructors = {\n CanvasGradient: CanvasGradient,\n Image: Image,\n ImageData: ImageData,\n Uint8ClampedArray: Uint8ClampedArray,\n};\n\nImage.bind =\n Image.bind ||\n function () {\n return Image;\n };\n\nImageData.bind =\n ImageData.bind ||\n function () {\n return ImageData;\n };\nUint8ClampedArray.bind =\n Uint8ClampedArray.bind ||\n function () {\n return Uint8ClampedArray;\n };\n\nvar populateRefs = function (arg) {\n if (arg && arg.__ref__) {\n return targets[arg.__ref__];\n }\n return arg;\n};\ndocument.body.appendChild(canvas);\n\nvar mergeObjects = function (target, source) {\n for (var key in source) {\n if (source.hasOwnProperty(key)) {\n target[key] = source[key];\n }\n }\n return target;\n};\n\nfunction handleMessage(message) {\n var id = message.id,\n type = message.type,\n payload = message.payload;\n\n switch (type) {\n case 'exec': {\n var target = payload.target,\n method = payload.method,\n args = payload.args;\n var result = targets[target][method].apply(targets[target], args.map(populateRefs));\n var msg = toMessage(result);\n\n if (typeof result === 'object' && !msg.meta.constructor) {\n for (var constructorName in constructors) {\n if (result instanceof constructors[constructorName]) {\n msg.meta.constructor = constructorName;\n }\n }\n }\n window.ReactNativeWebView.postMessage(JSON.stringify(mergeObjects({ id: id }, msg)));\n break;\n }\n case 'set': {\n var target = payload.target,\n key = payload.key,\n value = payload.value;\n targets[target][key] = populateRefs(value);\n break;\n }\n case 'construct': {\n var constructor = payload.constructor,\n target = payload.id,\n args = payload.args || [];\n var newArgs = createObjectsFromArgs(args);\n var object;\n try {\n object = new (Function.prototype.bind.apply(constructors[constructor], [null].concat(newArgs)))();\n }\n catch (error) {\n throw new Error('Error while constructing '.concat(constructor, ' ').concat(error.message));\n }\n object.__constructorName__ = constructor;\n var msg = toMessage({});\n targets[target] = object;\n window.ReactNativeWebView.postMessage(JSON.stringify(mergeObjects({ id: id }, msg)));\n break;\n }\n case 'listen': {\n var types = payload.types,\n target = payload.target;\n for (var i = 0; i < types.length; i++) {\n var eventType = types[i];\n targets[target].addEventListener(eventType, function (e) {\n const message = toMessage({\n type: 'event',\n payload: {\n type: e.type,\n target: mergeObjects(flattenObject(targets[target]), {\n [WEBVIEW_TARGET]: target,\n }),\n },\n });\n window.ReactNativeWebView.postMessage(\n JSON.stringify(mergeObjects({ id: id }, message))\n );\n });\n }\n break;\n}\n }\n}\nvar handleError = function (err, message) {\n window.ReactNativeWebView.postMessage(JSON.stringify({\n id: message.id,\n type: 'error',\n payload: {\n message: err.message,\n stack: err.stack,\n },\n }));\n document.removeEventListener('message', handleIncomingMessage);\n};\n\nfunction handleIncomingMessage(data) {\n if (Array.isArray(data)) {\n for (var i = 0; i < data.length; i++) {\n try {\n handleMessage(data[i]);\n } catch (err) {\n handleError(err, data[i]);\n }\n }\n } else {\n try {\n handleMessage(data);\n } catch (err) {\n handleError(err, data);\n }\n }\n}\n\nwindow.mpxWebviewMessageCallback = handleIncomingMessage\n</script>\n \n\n</body></html>";
2
2
  export default _default;
3
- //# sourceMappingURL=html.d.ts.map
@@ -30,4 +30,3 @@ interface CanvasProps {
30
30
  }
31
31
  declare const _Canvas: import("react").ForwardRefExoticComponent<CanvasProps & import("react").RefAttributes<HandlerRef<CanvasProps & View, CanvasProps>>>;
32
32
  export default _Canvas;
33
- //# sourceMappingURL=index.d.ts.map
@@ -50,4 +50,3 @@ export declare const useWebviewBinding: ({ targetName, properties, methods }: {
50
50
  properties?: Record<string, any> | undefined;
51
51
  methods?: string[] | undefined;
52
52
  }) => import("react").MutableRefObject<{}>;
53
- //# sourceMappingURL=utils.d.ts.map
@@ -18,4 +18,3 @@ export interface CheckboxGroupProps {
18
18
  }
19
19
  declare const CheckboxGroup: import("react").ForwardRefExoticComponent<CheckboxGroupProps & import("react").RefAttributes<HandlerRef<View, CheckboxGroupProps>>>;
20
20
  export default CheckboxGroup;
21
- //# sourceMappingURL=mpx-checkbox-group.d.ts.map
@@ -30,4 +30,3 @@ export interface CheckboxProps extends Selection {
30
30
  }
31
31
  declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<HandlerRef<View, CheckboxProps>>>;
32
32
  export default Checkbox;
33
- //# sourceMappingURL=mpx-checkbox.d.ts.map
@@ -25,4 +25,3 @@ interface FormProps {
25
25
  }
26
26
  declare const _Form: import("react").ForwardRefExoticComponent<FormProps & import("react").RefAttributes<HandlerRef<View, FormProps>>>;
27
27
  export default _Form;
28
- //# sourceMappingURL=mpx-form.d.ts.map
@@ -16,4 +16,3 @@ export interface IconProps {
16
16
  }
17
17
  declare const Icon: import("react").ForwardRefExoticComponent<IconProps & import("react").RefAttributes<HandlerRef<Text, IconProps>>>;
18
18
  export default Icon;
19
- //# sourceMappingURL=index.d.ts.map
@@ -19,4 +19,3 @@ export interface ImageProps {
19
19
  }
20
20
  declare const Image: import("react").ForwardRefExoticComponent<ImageProps & import("react").RefAttributes<HandlerRef<RNImage, ImageProps>>>;
21
21
  export default Image;
22
- //# sourceMappingURL=mpx-image.d.ts.map
@@ -16,7 +16,7 @@ import { noop } from '@mpxjs/utils';
16
16
  import { SvgCssUri } from 'react-native-svg/css';
17
17
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
18
18
  import useNodesRef from './useNodesRef';
19
- import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject } from './utils';
19
+ import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject, isAndroid } from './utils';
20
20
  import Portal from './mpx-portal';
21
21
  const DEFAULT_IMAGE_WIDTH = 320;
22
22
  const DEFAULT_IMAGE_HEIGHT = 240;
@@ -104,7 +104,7 @@ const Image = forwardRef((props, ref) => {
104
104
  setLoaded(true);
105
105
  }
106
106
  };
107
- const { hasPositionFixed, hasSelfPercent, normalStyle, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
107
+ const { hasPositionFixed, hasSelfPercent, normalStyle, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, transformRadiusPercent: isAndroid && !isSvg && !isLayoutMode, externalVarContext, parentFontSize, parentWidth, parentHeight });
108
108
  const { layoutRef, layoutStyle, layoutProps } = useLayout({
109
109
  props,
110
110
  hasSelfPercent,
@@ -5,4 +5,3 @@ declare const InlineText: {
5
5
  displayName: string;
6
6
  };
7
7
  export default InlineText;
8
- //# sourceMappingURL=mpx-inline-text.d.ts.map
@@ -31,7 +31,9 @@ export interface InputProps {
31
31
  'parent-font-size'?: number;
32
32
  'parent-width'?: number;
33
33
  'parent-height'?: number;
34
+ 'keyboard-type'?: string;
34
35
  'adjust-position': boolean;
36
+ 'hold-keyboard'?: boolean;
35
37
  bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void;
36
38
  bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
37
39
  bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
@@ -47,4 +49,3 @@ export interface PrivateInputProps {
47
49
  type FinalInputProps = InputProps & PrivateInputProps;
48
50
  declare const Input: import("react").ForwardRefExoticComponent<InputProps & PrivateInputProps & import("react").RefAttributes<HandlerRef<TextInput, FinalInputProps>>>;
49
51
  export default Input;
50
- //# sourceMappingURL=mpx-input.d.ts.map
@@ -18,7 +18,7 @@
18
18
  * ✔ selection-start
19
19
  * ✔ selection-end
20
20
  * ✔ adjust-position
21
- * hold-keyboard
21
+ * hold-keyboard
22
22
  * ✘ safe-password-cert-path
23
23
  * ✘ safe-password-length
24
24
  * ✘ safe-password-time-stamp
@@ -40,19 +40,19 @@
40
40
  import { forwardRef, useRef, useState, useContext, useEffect, createElement } from 'react';
41
41
  import { TextInput } from 'react-native';
42
42
  import { warn } from '@mpxjs/utils';
43
- import { useUpdateEffect, useTransformStyle, useLayout, extendObject, isIOS } from './utils';
43
+ import { useUpdateEffect, useTransformStyle, useLayout, extendObject, isAndroid } from './utils';
44
44
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
45
45
  import useNodesRef from './useNodesRef';
46
46
  import { FormContext, KeyboardAvoidContext } from './context';
47
47
  import Portal from './mpx-portal';
48
- const keyboardTypeMap = {
49
- text: 'default',
48
+ const inputModeMap = {
49
+ text: 'text',
50
50
  number: 'numeric',
51
- idcard: 'default',
52
- digit: isIOS ? 'decimal-pad' : 'numeric'
51
+ idcard: 'text',
52
+ digit: 'decimal'
53
53
  };
54
54
  const Input = forwardRef((props, ref) => {
55
- const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
55
+ const { style = {}, allowFontScaling = false, type = 'text', value, password, 'placeholder-style': placeholderStyle = {}, disabled, maxlength = 140, 'cursor-spacing': cursorSpacing = 0, 'auto-focus': autoFocus, focus, 'confirm-type': confirmType = 'done', 'confirm-hold': confirmHold = false, cursor, 'cursor-color': cursorColor, 'selection-start': selectionStart = -1, 'selection-end': selectionEnd = -1, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'adjust-position': adjustPosition = true, 'keyboard-type': originalKeyboardType, 'hold-keyboard': holdKeyboard = false, bindinput, bindfocus, bindblur, bindconfirm, bindselectionchange,
56
56
  // private
57
57
  multiline, 'auto-height': autoHeight, bindlinechange } = props;
58
58
  const formContext = useContext(FormContext);
@@ -72,18 +72,18 @@ const Input = forwardRef((props, ref) => {
72
72
  return value + '';
73
73
  return '';
74
74
  };
75
- const keyboardType = keyboardTypeMap[type];
76
75
  const defaultValue = parseValue(value);
76
+ // 微信小程序的 input 永远是单行,textAlignVertical 固定为 auto
77
+ // multiline 为 true 时表示是 textarea 组件复用此逻辑
77
78
  const textAlignVertical = multiline ? 'top' : 'auto';
79
+ const isAutoFocus = !!autoFocus || !!focus;
78
80
  const tmpValue = useRef(defaultValue);
79
81
  const cursorIndex = useRef(0);
80
82
  const lineCount = useRef(0);
81
83
  const [inputValue, setInputValue] = useState(defaultValue);
82
84
  const [contentHeight, setContentHeight] = useState(0);
83
85
  const [selection, setSelection] = useState({ start: -1, end: tmpValue.current.length });
84
- const styleObj = extendObject({ padding: 0, backgroundColor: '#fff' }, style, multiline && autoHeight
85
- ? { height: 'auto', minHeight: Math.max(style?.minHeight || 35, contentHeight) }
86
- : {});
86
+ const styleObj = extendObject({ padding: 0, backgroundColor: '#fff' }, style, multiline && autoHeight ? { height: 'auto' } : {});
87
87
  const { hasPositionFixed, hasSelfPercent, normalStyle, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
88
88
  const nodeRef = useRef(null);
89
89
  useNodesRef(props, ref, nodeRef, {
@@ -145,47 +145,54 @@ const Input = forwardRef((props, ref) => {
145
145
  };
146
146
  const setKeyboardAvoidContext = () => {
147
147
  if (keyboardAvoid) {
148
- keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition };
148
+ keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition, holdKeyboard, readyToShow: true };
149
149
  }
150
150
  };
151
151
  const onTouchStart = () => {
152
- // sometimes the focus event occurs later than the keyboardWillShow event
152
+ // 手动聚焦时初始化 keyboardAvoid 上下文
153
+ // auto-focus/focus 不会触发而是在 useEffect 中初始化
153
154
  setKeyboardAvoidContext();
154
155
  };
155
156
  const onTouchEnd = (evt) => {
156
157
  evt.nativeEvent.origin = 'input';
157
158
  };
158
159
  const onFocus = (evt) => {
159
- setKeyboardAvoidContext();
160
- if (bindfocus) {
161
- const focusAction = () => {
162
- bindfocus(getCustomEvent('focus', evt, {
163
- detail: {
164
- value: tmpValue.current || '',
165
- height: keyboardAvoid?.current?.keyboardHeight
166
- },
167
- layoutRef
168
- }, props));
169
- if (keyboardAvoid?.current?.onKeyboardShow) {
170
- keyboardAvoid.current.onKeyboardShow = undefined;
171
- }
172
- };
173
- if (keyboardAvoid?.current) {
174
- // keyboardAvoiding
175
- if (keyboardAvoid.current.keyboardHeight) {
176
- // iOS: keyboard 获取高度时机 keyboardWillShow 在 input focus 之前,可以立即执行
177
- focusAction();
178
- }
179
- else {
180
- // Android,Harmony: keyboard 获取高度时机 keyboardDidShow 在 input focus 之后,需要延迟回调
181
- evt.persist();
182
- keyboardAvoid.current.onKeyboardShow = focusAction;
183
- }
160
+ if (!keyboardAvoid?.current) {
161
+ // Android:从一个正聚焦状态 input,聚焦到另一个新的 input 时,正常会触发如下时序:
162
+ // 新的 Input `onTouchStart` -> 旧输入框键盘 `keyboardDidHide` -> 新的 Input `onFocus`
163
+ // 导致这里的 keyboardAvoid.current 为 null,所以需要判空重新初始化。
164
+ setKeyboardAvoidContext();
165
+ }
166
+ const focusAction = () => {
167
+ bindfocus?.(getCustomEvent('focus', evt, {
168
+ detail: {
169
+ value: tmpValue.current || '',
170
+ height: keyboardAvoid?.current?.keyboardHeight
171
+ },
172
+ layoutRef
173
+ }, props));
174
+ if (keyboardAvoid?.current?.onKeyboardShow) {
175
+ keyboardAvoid.current.onKeyboardShow = undefined;
184
176
  }
185
- else {
186
- // keyboardAvoiding,直接执行 focus 回调
177
+ };
178
+ if (keyboardAvoid?.current) {
179
+ // 有 keyboardAvoiding
180
+ if (keyboardAvoid.current.keyboardHeight) {
181
+ // 仅以下场景触发顺序:先 keyboardWillShow 获取高度 -> 后 onFocus,可以立即执行
182
+ // - iOS + 手动点击聚焦
187
183
  focusAction();
188
184
  }
185
+ else {
186
+ // 其他场景触发顺序:先 onFocus -> 后 keyboardWillShow 获取高度 -> 执行回调
187
+ // - iOS + auto-focus/focus=true 自动聚焦
188
+ // - Android 手动点击聚焦/自动聚焦 都一样
189
+ evt.persist();
190
+ keyboardAvoid.current.onKeyboardShow = focusAction;
191
+ }
192
+ }
193
+ else {
194
+ // 兜底:无 keyboardAvoiding 直接执行 focus 回调
195
+ focusAction();
189
196
  }
190
197
  };
191
198
  const onBlur = (evt) => {
@@ -260,36 +267,45 @@ const Input = forwardRef((props, ref) => {
260
267
  };
261
268
  }, []);
262
269
  useEffect(() => {
263
- if (focus) {
270
+ if (isAutoFocus) {
271
+ // auto-focus/focus=true 初始化 keyboardAvoidContext
264
272
  setKeyboardAvoidContext();
265
273
  }
266
- }, [focus]);
274
+ }, [isAutoFocus]);
267
275
  useUpdateEffect(() => {
268
276
  if (!nodeRef?.current) {
269
277
  return;
270
278
  }
271
- focus
279
+ // RN autoFocus 属性仅在初次渲染时生效
280
+ // 后续更新需要手动调用 focus/blur 方法,和微信小程序对齐
281
+ isAutoFocus
272
282
  ? nodeRef.current?.focus()
273
283
  : nodeRef.current?.blur();
274
- }, [focus]);
284
+ }, [isAutoFocus]);
285
+ // 使用 multiline 来修复光标位置问题
286
+ // React Native 的 TextInput 在 textAlign center + placeholder 时光标会跑到右边
287
+ // 这个问题只在 Android 上出现
288
+ // 参考:https://github.com/facebook/react-native/issues/28794 (Android only)
289
+ const needMultilineFix = isAndroid && !multiline;
275
290
  const innerProps = useInnerProps(extendObject({}, props, layoutProps, {
276
291
  ref: nodeRef,
277
292
  style: extendObject({}, normalStyle, layoutStyle),
278
293
  allowFontScaling,
279
- keyboardType: keyboardType,
294
+ inputMode: originalKeyboardType ? undefined : inputModeMap[type],
295
+ keyboardType: originalKeyboardType,
280
296
  secureTextEntry: !!password,
281
297
  defaultValue: defaultValue,
282
298
  value: inputValue,
283
299
  maxLength: maxlength === -1 ? undefined : maxlength,
284
300
  editable: !disabled,
285
- autoFocus: !!autoFocus || !!focus,
301
+ autoFocus: isAutoFocus,
286
302
  selection: selectionStart > -1 || typeof cursor === 'number' ? selection : undefined,
287
303
  selectionColor: cursorColor,
288
- blurOnSubmit: !multiline && !confirmHold,
304
+ blurOnSubmit: multiline ? confirmType !== 'return' : !confirmHold,
289
305
  underlineColorAndroid: 'rgba(0,0,0,0)',
290
306
  textAlignVertical: textAlignVertical,
291
307
  placeholderTextColor: placeholderStyle?.color,
292
- multiline: !!multiline,
308
+ multiline: multiline || needMultilineFix,
293
309
  onTouchStart,
294
310
  onTouchEnd,
295
311
  onFocus,
@@ -297,8 +313,8 @@ const Input = forwardRef((props, ref) => {
297
313
  onChange,
298
314
  onSelectionChange,
299
315
  onContentSizeChange,
300
- onSubmitEditing: bindconfirm && !multiline && onSubmitEditing
301
- }, !!multiline && confirmType === 'return' ? {} : { enterKeyHint: confirmType }), [
316
+ onSubmitEditing: bindconfirm && onSubmitEditing
317
+ }, needMultilineFix ? { numberOfLines: 1 } : {}, !!multiline && confirmType === 'return' ? {} : { enterKeyHint: confirmType }), [
302
318
  'type',
303
319
  'password',
304
320
  'placeholder-style',
@@ -10,4 +10,3 @@ declare const KeyboardAvoidingView: {
10
10
  displayName: string;
11
11
  };
12
12
  export default KeyboardAvoidingView;
13
- //# sourceMappingURL=mpx-keyboard-avoiding-view.d.ts.map