@mpxjs/webpack-plugin 2.10.16 → 2.10.17

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 (226) hide show
  1. package/lib/dependencies/AppEntryDependency.js +2 -2
  2. package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
  3. package/lib/dependencies/ResolveDependency.js +1 -1
  4. package/lib/helpers.js +2 -0
  5. package/lib/index.js +40 -15
  6. package/lib/json-compiler/helper.js +72 -2
  7. package/lib/json-compiler/index.js +14 -54
  8. package/lib/json-compiler/plugin.js +2 -2
  9. package/lib/loader.js +10 -4
  10. package/lib/native-loader.js +6 -3
  11. package/lib/platform/json/wx/index.js +24 -29
  12. package/lib/platform/style/wx/index.js +8 -1
  13. package/lib/platform/template/wx/component-config/button.js +12 -3
  14. package/lib/platform/template/wx/component-config/component.js +31 -33
  15. package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
  16. package/lib/react/index.js +2 -0
  17. package/lib/react/processJSON.js +39 -71
  18. package/lib/react/processStyles.js +3 -2
  19. package/lib/react/processTemplate.js +8 -6
  20. package/lib/react/script-helper.js +6 -16
  21. package/lib/react/style-helper.js +10 -2
  22. package/lib/runtime/components/react/context.ts +12 -6
  23. package/lib/runtime/components/react/dist/context.d.ts +75 -0
  24. package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
  25. package/lib/runtime/components/react/dist/context.js +1 -0
  26. package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
  27. package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
  28. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
  29. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
  30. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
  31. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
  32. package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
  33. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
  34. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
  35. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
  36. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
  37. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
  38. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
  39. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
  40. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
  41. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
  42. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
  43. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
  44. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
  45. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
  46. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
  47. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
  48. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
  49. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
  50. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  51. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
  52. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
  53. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
  54. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
  55. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
  56. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
  57. package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
  58. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
  59. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
  60. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
  61. package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
  62. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
  63. package/lib/runtime/components/react/dist/mpx-image.jsx +107 -57
  64. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
  65. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
  66. package/lib/runtime/components/react/dist/mpx-input.d.ts +50 -0
  67. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
  68. package/lib/runtime/components/react/dist/mpx-input.jsx +32 -8
  69. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
  70. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
  71. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +58 -50
  72. package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
  73. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
  74. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
  75. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
  76. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
  77. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
  78. package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
  79. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
  80. package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
  81. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
  82. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
  83. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
  84. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
  85. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
  86. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
  87. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
  88. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
  89. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
  90. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
  91. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
  92. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
  93. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
  94. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
  95. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
  96. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
  97. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
  98. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
  99. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
  100. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
  101. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
  102. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
  103. package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
  104. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
  105. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
  106. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
  107. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
  108. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
  109. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
  110. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
  111. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
  112. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
  113. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
  114. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
  115. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
  116. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
  117. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
  118. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
  119. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
  120. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
  121. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
  122. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
  123. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
  124. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
  125. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
  126. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
  127. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
  128. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
  129. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
  130. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
  131. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
  132. package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
  133. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
  134. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
  135. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
  136. package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
  137. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
  138. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
  139. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
  140. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
  141. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
  142. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
  143. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
  144. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
  145. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
  146. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
  147. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
  148. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
  149. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
  150. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
  151. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
  152. package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
  153. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
  154. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
  155. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
  156. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
  157. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
  158. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
  159. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
  160. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
  161. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
  162. package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
  163. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
  164. package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
  165. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
  166. package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
  167. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
  168. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
  169. package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
  170. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
  171. package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
  172. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
  173. package/lib/runtime/components/react/dist/mpx-view.jsx +1 -1
  174. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
  175. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
  176. package/lib/runtime/components/react/dist/mpx-web-view.jsx +10 -2
  177. package/lib/runtime/components/react/dist/parser.d.ts +40 -0
  178. package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
  179. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
  180. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
  181. package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
  182. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
  183. package/lib/runtime/components/react/dist/utils.d.ts +123 -0
  184. package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
  185. package/lib/runtime/components/react/dist/utils.jsx +16 -6
  186. package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
  187. package/lib/runtime/components/react/mpx-image.tsx +130 -77
  188. package/lib/runtime/components/react/mpx-input.tsx +38 -15
  189. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +66 -49
  190. package/lib/runtime/components/react/mpx-nav.tsx +155 -0
  191. package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
  192. package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
  193. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
  194. package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
  195. package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
  196. package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
  197. package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
  198. package/lib/runtime/components/react/mpx-text.tsx +38 -5
  199. package/lib/runtime/components/react/mpx-view.tsx +1 -1
  200. package/lib/runtime/components/react/mpx-web-view.tsx +13 -4
  201. package/lib/runtime/components/react/types/common.d.ts +19 -0
  202. package/lib/runtime/components/react/utils.tsx +15 -6
  203. package/lib/script-setup-compiler/index.js +2 -2
  204. package/lib/style-compiler/index.js +3 -2
  205. package/lib/style-compiler/load-postcss-config.js +1 -1
  206. package/lib/style-compiler/plugins/trans-special.js +10 -2
  207. package/lib/style-compiler/strip-conditional-loader.js +177 -15
  208. package/lib/template-compiler/compiler.js +268 -70
  209. package/lib/template-compiler/gen-node-react.js +18 -6
  210. package/lib/template-compiler/index.js +6 -4
  211. package/lib/template-compiler/parse-exps.js +1 -1
  212. package/lib/utils/const.js +2 -1
  213. package/lib/utils/dom-tag-config.js +5 -5
  214. package/lib/utils/env.js +6 -1
  215. package/lib/utils/get-build-tag-component.js +35 -0
  216. package/lib/utils/merge-visitors.js +55 -0
  217. package/lib/utils/pre-process-json.js +5 -0
  218. package/lib/web/index.js +2 -0
  219. package/lib/web/processJSON.js +44 -16
  220. package/lib/web/processScript.js +1 -1
  221. package/lib/web/processTemplate.js +6 -4
  222. package/lib/web/script-helper.js +19 -9
  223. package/lib/wxs/pre-loader.js +9 -6
  224. package/lib/wxss/loader.js +1 -9
  225. package/package.json +15 -5
  226. package/lib/utils/chain-assign.js +0 -47
@@ -40,7 +40,16 @@ const ModeMap = new Map([
40
40
  ...cropMode.map(mode => [mode, 'stretch'])
41
41
  ]);
42
42
  const isNumber = (value) => typeof value === 'number';
43
- const relativeCenteredSize = (viewSize, imageSize) => (viewSize - imageSize) / 2;
43
+ const relativeCenteredSize = (viewSize, imageSize) => {
44
+ return (viewSize - imageSize) / 2;
45
+ };
46
+ // 获取能完全显示图片的缩放比例:长宽方向的缩放比例最小值即为能完全展示的比例
47
+ function getFitScale(width1, height1, width2, height2) {
48
+ return Math.min(width2 / width1, height2 / height1);
49
+ }
50
+ function getFillScale(width1, height1, width2, height2) {
51
+ return Math.max(width2 / width1, height2 / height1);
52
+ }
44
53
  function noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio) {
45
54
  const isMeetSize = viewWidth && viewHeight && ratio;
46
55
  if (isSvg && !isMeetSize)
@@ -49,6 +58,16 @@ function noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio) {
49
58
  return true;
50
59
  return false;
51
60
  }
61
+ const getFixedWidth = (viewWidth, viewHeight, ratio) => {
62
+ if (!ratio)
63
+ return viewWidth;
64
+ const fixed = viewHeight / ratio;
65
+ return !fixed ? viewWidth : fixed;
66
+ };
67
+ const getFixedHeight = (viewWidth, viewHeight, ratio) => {
68
+ const fixed = viewWidth * ratio;
69
+ return !fixed ? viewHeight : fixed;
70
+ };
52
71
  const Image = forwardRef((props, ref) => {
53
72
  const { src = '', mode = 'scaleToFill', style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'enable-fast-image': enableFastImage, 'parent-width': parentWidth, 'parent-height': parentHeight, bindload, binderror } = props;
54
73
  const defaultStyle = {
@@ -56,7 +75,6 @@ const Image = forwardRef((props, ref) => {
56
75
  height: DEFAULT_IMAGE_HEIGHT
57
76
  };
58
77
  const styleObj = extendObject({}, defaultStyle, style, { overflow: 'hidden' });
59
- const state = useRef({});
60
78
  const nodeRef = useRef(null);
61
79
  useNodesRef(props, ref, nodeRef, {
62
80
  defaultStyle
@@ -70,13 +88,19 @@ const Image = forwardRef((props, ref) => {
70
88
  const onLayout = ({ nativeEvent: { layout: { width, height } } }) => {
71
89
  state.current.viewWidth = width;
72
90
  state.current.viewHeight = height;
91
+ // 实际渲染尺寸可能会指定的值不一致,误差低于 0.5 则认为没有变化
92
+ if (Math.abs(viewHeight - height) < 0.5 && Math.abs(viewWidth - width) < 0.5) {
93
+ if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
94
+ if (!loaded)
95
+ setLoaded(true);
96
+ }
97
+ return;
98
+ }
73
99
  if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
74
- setViewWidth(width);
75
- setViewHeight(height);
76
100
  setRatio(state.current.ratio);
77
101
  setImageWidth(state.current.imageWidth);
78
102
  setImageHeight(state.current.imageHeight);
79
- state.current = {};
103
+ setViewSize(state.current.viewWidth, state.current.viewHeight, state.current.ratio);
80
104
  setLoaded(true);
81
105
  }
82
106
  };
@@ -96,43 +120,56 @@ const Image = forwardRef((props, ref) => {
96
120
  const [imageHeight, setImageHeight] = useState(0);
97
121
  const [ratio, setRatio] = useState(0);
98
122
  const [loaded, setLoaded] = useState(!isLayoutMode);
99
- const fixedHeight = useMemo(() => {
100
- const fixed = viewWidth * ratio;
101
- return !fixed ? viewHeight : fixed;
102
- }, [ratio, viewWidth, viewHeight]);
103
- const fixedWidth = useMemo(() => {
104
- if (!ratio)
105
- return viewWidth;
106
- const fixed = viewHeight / ratio;
107
- return !fixed ? viewWidth : fixed;
108
- }, [ratio, viewWidth, viewHeight]);
123
+ const state = useRef({
124
+ viewWidth,
125
+ viewHeight
126
+ });
127
+ function setViewSize(viewWidth, viewHeight, ratio) {
128
+ // 在特定模式下可预测 view 的变化,在onLayout触发时能以此避免重复render
129
+ switch (mode) {
130
+ case 'widthFix': {
131
+ setViewWidth(viewWidth);
132
+ const fixedHeight = getFixedHeight(viewWidth, viewHeight, ratio);
133
+ setViewHeight(fixedHeight);
134
+ break;
135
+ }
136
+ case 'heightFix': {
137
+ setViewHeight(viewHeight);
138
+ const fixedWidth = getFixedWidth(viewWidth, viewHeight, ratio);
139
+ setViewWidth(fixedWidth);
140
+ break;
141
+ }
142
+ default:
143
+ setViewHeight(viewHeight);
144
+ setViewWidth(viewWidth);
145
+ break;
146
+ }
147
+ }
109
148
  const modeStyle = useMemo(() => {
110
149
  if (noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio))
111
150
  return {};
112
151
  switch (mode) {
113
- case 'scaleToFill':
152
+ case 'scaleToFill': // wx 中 svg 图片的 scaleToFill 模式效果与 aspectFit 一致,不会就行图片缩放,此处保持一致
114
153
  case 'aspectFit':
115
154
  if (isSvg) {
116
- const scale = ratio <= 1
117
- ? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
118
- : imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight;
155
+ const scale = getFitScale(imageWidth, imageHeight, viewWidth, viewHeight);
119
156
  return {
120
157
  transform: [
121
- { scale },
122
- ratio <= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
158
+ { translateY: relativeCenteredSize(viewHeight, imageHeight * scale) },
159
+ { translateX: relativeCenteredSize(viewWidth, imageWidth * scale) },
160
+ { scale }
123
161
  ]
124
162
  };
125
163
  }
126
164
  return {};
127
165
  case 'aspectFill':
128
166
  if (isSvg) {
129
- const scale = ratio >= 1
130
- ? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
131
- : imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight;
167
+ const scale = getFillScale(imageWidth, imageHeight, viewWidth, viewHeight);
132
168
  return {
133
169
  transform: [
134
- { scale },
135
- ratio >= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
170
+ { translateY: relativeCenteredSize(viewHeight, imageHeight * scale) },
171
+ { translateX: relativeCenteredSize(viewWidth, imageWidth * scale) },
172
+ { scale }
136
173
  ]
137
174
  };
138
175
  }
@@ -140,9 +177,7 @@ const Image = forwardRef((props, ref) => {
140
177
  case 'widthFix':
141
178
  case 'heightFix':
142
179
  if (isSvg) {
143
- const scale = ratio >= 1
144
- ? imageWidth >= fixedWidth ? fixedWidth / imageWidth : imageWidth / fixedWidth
145
- : imageHeight >= fixedHeight ? fixedHeight / imageHeight : imageHeight / fixedHeight;
180
+ const scale = getFitScale(imageWidth, imageHeight, viewWidth, viewHeight);
146
181
  return {
147
182
  transform: [{ scale }]
148
183
  };
@@ -205,12 +240,23 @@ const Image = forwardRef((props, ref) => {
205
240
  default:
206
241
  return {};
207
242
  }
208
- }, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio, fixedWidth, fixedHeight]);
243
+ }, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio]);
209
244
  const onSvgLoad = (evt) => {
210
245
  const { width, height } = evt.nativeEvent.layout;
211
- setRatio(!width ? 0 : height / width);
212
- setImageWidth(width);
246
+ state.current.imageHeight = height;
213
247
  setImageHeight(height);
248
+ state.current.ratio = !width ? 0 : height / width;
249
+ if (isWidthFixMode
250
+ ? state.current.viewWidth
251
+ : isHeightFixMode
252
+ ? state.current.viewHeight
253
+ : state.current.viewWidth && state.current.viewHeight) {
254
+ setRatio(state.current.ratio);
255
+ setImageWidth(width);
256
+ setImageHeight(height);
257
+ setViewSize(state.current.viewWidth, state.current.viewHeight, state.current.ratio);
258
+ setLoaded(true);
259
+ }
214
260
  bindload && bindload(getCustomEvent('load', evt, {
215
261
  detail: { width, height },
216
262
  layoutRef
@@ -248,12 +294,10 @@ const Image = forwardRef((props, ref) => {
248
294
  : isHeightFixMode
249
295
  ? state.current.viewHeight
250
296
  : state.current.viewWidth && state.current.viewHeight) {
251
- state.current.viewWidth && setViewWidth(state.current.viewWidth);
252
- state.current.viewHeight && setViewHeight(state.current.viewHeight);
253
- setRatio(!width ? 0 : height / width);
297
+ setRatio(state.current.ratio);
254
298
  setImageWidth(width);
255
299
  setImageHeight(height);
256
- state.current = {};
300
+ setViewSize(state.current.viewWidth, state.current.viewHeight, state.current.ratio);
257
301
  setLoaded(true);
258
302
  }
259
303
  }, () => {
@@ -263,7 +307,7 @@ const Image = forwardRef((props, ref) => {
263
307
  }, [src, isSvg, isLayoutMode]);
264
308
  const innerProps = useInnerProps(extendObject({}, props, layoutProps, {
265
309
  ref: nodeRef,
266
- style: extendObject({}, normalStyle, layoutStyle, isHeightFixMode ? { width: fixedWidth } : {}, isWidthFixMode ? { height: fixedHeight } : {})
310
+ style: extendObject({}, normalStyle, layoutStyle, isHeightFixMode ? { width: viewWidth } : {}, isWidthFixMode ? { height: viewHeight } : {})
267
311
  }), [
268
312
  'src',
269
313
  'mode',
@@ -271,29 +315,35 @@ const Image = forwardRef((props, ref) => {
271
315
  ], {
272
316
  layoutRef
273
317
  });
274
- const SvgImage = createElement(View, innerProps, createElement(SvgCssUri, {
275
- uri: src,
276
- onLayout: onSvgLoad,
277
- onError: binderror && onSvgError,
278
- style: extendObject({ transformOrigin: 'left top' }, modeStyle)
279
- }));
280
- const BaseImage = renderImage(extendObject({
281
- source: { uri: src },
282
- resizeMode: resizeMode,
283
- onLoad: bindload && onImageLoad,
284
- onError: binderror && onImageError,
285
- style: extendObject({
286
- transformOrigin: 'left top',
287
- width: isCropMode ? imageWidth : '100%',
288
- height: isCropMode ? imageHeight : '100%'
289
- }, isCropMode ? modeStyle : {})
290
- }, isLayoutMode ? {} : innerProps), enableFastImage);
291
- const LayoutImage = createElement(View, innerProps, loaded && BaseImage);
292
- const finalComponent = isSvg ? SvgImage : isLayoutMode ? LayoutImage : BaseImage;
318
+ function renderSvgImage() {
319
+ return createElement(View, innerProps, createElement(SvgCssUri, {
320
+ uri: src,
321
+ onLayout: onSvgLoad,
322
+ onError: binderror && onSvgError,
323
+ style: extendObject({ transformOrigin: 'left top' }, modeStyle)
324
+ }));
325
+ }
326
+ function renderBaseImage() {
327
+ return renderImage(extendObject({
328
+ source: { uri: src },
329
+ resizeMode: resizeMode,
330
+ onLoad: bindload && onImageLoad,
331
+ onError: binderror && onImageError,
332
+ style: extendObject({
333
+ transformOrigin: 'left top',
334
+ width: isCropMode ? imageWidth : '100%',
335
+ height: isCropMode ? imageHeight : '100%'
336
+ }, isCropMode ? modeStyle : {})
337
+ }, isLayoutMode ? {} : innerProps), enableFastImage);
338
+ }
339
+ function renderLayoutImage() {
340
+ return createElement(View, innerProps, loaded && renderBaseImage());
341
+ }
342
+ const finalComponent = isSvg ? renderSvgImage() : isLayoutMode ? renderLayoutImage() : renderBaseImage();
293
343
  if (hasPositionFixed) {
294
344
  return createElement(Portal, null, finalComponent);
295
345
  }
296
346
  return finalComponent;
297
347
  });
298
- Image.displayName = 'mpx-image';
348
+ Image.displayName = 'MpxImage';
299
349
  export default Image;
@@ -0,0 +1,8 @@
1
+ import { TextProps } from 'react-native';
2
+ import { JSX } from 'react';
3
+ declare const InlineText: {
4
+ (props: TextProps): JSX.Element;
5
+ displayName: string;
6
+ };
7
+ export default InlineText;
8
+ //# sourceMappingURL=mpx-inline-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mpx-inline-text.d.ts","sourceRoot":"","sources":["../mpx-inline-text.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAQ,SAAS,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAiB,MAAM,OAAO,CAAA;AAI1C,QAAA,MAAM,UAAU;YAAW,SAAS,GAAG,WAAW;;CAQjD,CAAA;AAID,eAAe,UAAU,CAAA"}
@@ -0,0 +1,50 @@
1
+ /// <reference types="react" />
2
+ import { TextInput, TextStyle, ViewStyle, NativeSyntheticEvent, TextInputTextInputEventData, TextInputKeyPressEventData, TextInputContentSizeChangeEventData, FlexStyle, TextInputSelectionChangeEventData, TextInputFocusEventData, TextInputSubmitEditingEventData } from 'react-native';
3
+ import { HandlerRef } from './useNodesRef';
4
+ type InputStyle = Omit<TextStyle & ViewStyle & Pick<FlexStyle, 'minHeight'>, 'borderLeftWidth' | 'borderTopWidth' | 'borderRightWidth' | 'borderBottomWidth' | 'borderTopLeftRadius' | 'borderTopRightRadius' | 'borderBottomRightRadius' | 'borderBottomLeftRadius'>;
5
+ type Type = 'text' | 'number' | 'idcard' | 'digit';
6
+ type ConfirmType = 'done' | 'send' | 'search' | 'next' | 'go' | 'return';
7
+ export interface InputProps {
8
+ name?: string;
9
+ style?: InputStyle & Record<string, any>;
10
+ value?: string | number;
11
+ type?: Type;
12
+ password?: boolean;
13
+ placeholder?: string;
14
+ disabled?: boolean;
15
+ 'cursor-spacing'?: number;
16
+ maxlength?: number;
17
+ 'auto-focus'?: boolean;
18
+ focus?: boolean;
19
+ 'confirm-type'?: ConfirmType;
20
+ 'confirm-hold'?: boolean;
21
+ cursor?: number;
22
+ 'cursor-color'?: string;
23
+ 'selection-start'?: number;
24
+ 'selection-end'?: number;
25
+ 'placeholder-style'?: {
26
+ color?: string;
27
+ };
28
+ 'enable-offset'?: boolean;
29
+ 'enable-var'?: boolean;
30
+ 'external-var-context'?: Record<string, any>;
31
+ 'parent-font-size'?: number;
32
+ 'parent-width'?: number;
33
+ 'parent-height'?: number;
34
+ 'adjust-position': boolean;
35
+ bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void;
36
+ bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
37
+ bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void;
38
+ bindconfirm?: (evt: NativeSyntheticEvent<TextInputSubmitEditingEventData | TextInputKeyPressEventData> | unknown) => void;
39
+ bindselectionchange?: (evt: NativeSyntheticEvent<TextInputSelectionChangeEventData> | unknown) => void;
40
+ }
41
+ export interface PrivateInputProps {
42
+ allowFontScaling?: boolean;
43
+ multiline?: boolean;
44
+ 'auto-height'?: boolean;
45
+ bindlinechange?: (evt: NativeSyntheticEvent<TextInputContentSizeChangeEventData> | unknown) => void;
46
+ }
47
+ type FinalInputProps = InputProps & PrivateInputProps;
48
+ declare const Input: import("react").ForwardRefExoticComponent<InputProps & PrivateInputProps & import("react").RefAttributes<HandlerRef<TextInput, FinalInputProps>>>;
49
+ export default Input;
50
+ //# sourceMappingURL=mpx-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mpx-input.d.ts","sourceRoot":"","sources":["../mpx-input.tsx"],"names":[],"mappings":"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"}
@@ -144,8 +144,8 @@ const Input = forwardRef((props, ref) => {
144
144
  }
145
145
  };
146
146
  const setKeyboardAvoidContext = () => {
147
- if (adjustPosition && keyboardAvoid) {
148
- keyboardAvoid.current = { cursorSpacing, ref: nodeRef };
147
+ if (keyboardAvoid) {
148
+ keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition };
149
149
  }
150
150
  };
151
151
  const onTouchStart = () => {
@@ -157,12 +157,36 @@ const Input = forwardRef((props, ref) => {
157
157
  };
158
158
  const onFocus = (evt) => {
159
159
  setKeyboardAvoidContext();
160
- bindfocus && bindfocus(getCustomEvent('focus', evt, {
161
- detail: {
162
- value: tmpValue.current || ''
163
- },
164
- layoutRef
165
- }, props));
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
+ }
184
+ }
185
+ else {
186
+ // 无 keyboardAvoiding,直接执行 focus 回调
187
+ focusAction();
188
+ }
189
+ }
166
190
  };
167
191
  const onBlur = (evt) => {
168
192
  bindblur && bindblur(getCustomEvent('blur', evt, {
@@ -0,0 +1,13 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { ViewStyle } from 'react-native';
3
+ type KeyboardAvoidViewProps = {
4
+ children?: ReactNode;
5
+ style?: ViewStyle;
6
+ contentContainerStyle?: ViewStyle;
7
+ };
8
+ declare const KeyboardAvoidingView: {
9
+ ({ children, style, contentContainerStyle }: KeyboardAvoidViewProps): React.JSX.Element;
10
+ displayName: string;
11
+ };
12
+ export default KeyboardAvoidingView;
13
+ //# sourceMappingURL=mpx-keyboard-avoiding-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mpx-keyboard-avoiding-view.d.ts","sourceRoot":"","sources":["../mpx-keyboard-avoiding-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAiC,MAAM,OAAO,CAAA;AACvE,OAAO,EAAuD,SAAS,EAA0C,MAAM,cAAc,CAAA;AAKrI,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,qBAAqB,CAAC,EAAE,SAAS,CAAA;CAClC,CAAA;AAED,QAAA,MAAM,oBAAoB;iDAAgD,sBAAsB;;CA8G/F,CAAA;AAID,eAAe,oBAAoB,CAAA"}
@@ -1,22 +1,38 @@
1
- import React, { useContext, useEffect } from 'react';
1
+ /* eslint-disable space-before-function-paren */
2
+ import React, { useContext, useEffect, useRef } from 'react';
2
3
  import { Keyboard, View } from 'react-native';
3
- import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing } from 'react-native-reanimated';
4
+ import Animated, { useSharedValue, useAnimatedStyle, withTiming, Easing, cancelAnimation } from 'react-native-reanimated';
4
5
  import { KeyboardAvoidContext } from './context';
5
- import { isIOS } from './utils';
6
+ import { isAndroid, isIOS } from './utils';
6
7
  const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
7
8
  const duration = isIOS ? 250 : 300;
8
9
  const easing = isIOS ? Easing.inOut(Easing.ease) : Easing.out(Easing.quad);
9
10
  const offset = useSharedValue(0);
10
11
  const basic = useSharedValue('auto');
11
12
  const keyboardAvoid = useContext(KeyboardAvoidContext);
13
+ // fix: 某些特殊机型下隐藏键盘可能会先触发一次 keyboardWillShow,
14
+ // 比如机型 iPhone 11 Pro,可能会导致显隐动画冲突
15
+ // 因此增加状态标记 + cancelAnimation 来优化
16
+ const isShow = useRef(false);
12
17
  const animatedStyle = useAnimatedStyle(() => ({
13
- transform: [{ translateY: -offset.value }],
18
+ // translate/position top可能会导致底部渲染区域缺失
19
+ marginTop: -offset.value,
14
20
  flexBasis: basic.value
15
21
  }));
16
22
  const resetKeyboard = () => {
23
+ if (!isShow.current) {
24
+ return;
25
+ }
26
+ isShow.current = false;
17
27
  if (keyboardAvoid?.current) {
28
+ const inputRef = keyboardAvoid.current.ref?.current;
29
+ if (inputRef && inputRef.isFocused()) {
30
+ // 修复 Android 点击键盘收起按钮时当前 input 没触发失焦的问题
31
+ inputRef.blur();
32
+ }
18
33
  keyboardAvoid.current = null;
19
34
  }
35
+ cancelAnimation(offset);
20
36
  offset.value = withTiming(0, { duration, easing });
21
37
  basic.value = 'auto';
22
38
  };
@@ -27,66 +43,58 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }) => {
27
43
  };
28
44
  useEffect(() => {
29
45
  let subscriptions = [];
30
- if (isIOS) {
31
- subscriptions = [
32
- Keyboard.addListener('keyboardWillShow', (evt) => {
33
- if (!keyboardAvoid?.current)
34
- return;
35
- const { endCoordinates } = evt;
36
- const { ref, cursorSpacing = 0 } = keyboardAvoid.current;
37
- setTimeout(() => {
38
- ref?.current?.measure((x, y, width, height, pageX, pageY) => {
46
+ function keybaordAvoding(evt) {
47
+ if (!keyboardAvoid?.current || isShow.current) {
48
+ return;
49
+ }
50
+ isShow.current = true;
51
+ const { endCoordinates } = evt;
52
+ const { ref, cursorSpacing = 0, adjustPosition, onKeyboardShow } = keyboardAvoid.current;
53
+ keyboardAvoid.current.keyboardHeight = endCoordinates.height;
54
+ onKeyboardShow?.();
55
+ if (adjustPosition) {
56
+ // 默认沿用旧版本逻辑,在 android 原生关闭键盘避让的情况下应该将该配置设置为 false,走 mpx 的键盘避让逻辑,否则bundle内的所有input都会无法避让键盘
57
+ const enableNativeKeyboardAvoiding = mpxGlobal?.__mpx?.config?.rnConfig?.enableNativeKeyboardAvoiding ?? true;
58
+ const callback = () => {
59
+ ref?.current?.measure((x, y, width, height, pageX, pageY) => {
60
+ function calculateOffset() {
61
+ // enableNativeKeyboardAvoding 默认开启
62
+ if (enableNativeKeyboardAvoiding && isAndroid) {
63
+ const aboveOffset = pageY + height - endCoordinates.screenY;
64
+ const belowOffset = endCoordinates.height - aboveOffset;
65
+ const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
66
+ const belowValue = Math.min(belowOffset, cursorSpacing);
67
+ return aboveOffset > 0 ? belowValue : aboveValue;
68
+ }
39
69
  const aboveOffset = offset.value + pageY + height - endCoordinates.screenY;
40
70
  const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
41
71
  const belowValue = Math.min(endCoordinates.height, aboveOffset + cursorSpacing);
42
- const value = aboveOffset > 0 ? belowValue : aboveValue;
43
- offset.value = withTiming(value, { duration, easing }, (finished) => {
44
- if (finished) {
45
- // Set flexBasic after animation to trigger re-layout and reset layout information
46
- basic.value = '99.99%';
47
- }
48
- });
49
- });
50
- });
51
- }),
52
- Keyboard.addListener('keyboardWillHide', resetKeyboard)
53
- ];
54
- }
55
- else {
56
- subscriptions = [
57
- Keyboard.addListener('keyboardDidShow', (evt) => {
58
- if (!keyboardAvoid?.current)
59
- return;
60
- const { endCoordinates } = evt;
61
- const { ref, cursorSpacing = 0 } = keyboardAvoid.current;
62
- ref?.current?.measure((x, y, width, height, pageX, pageY) => {
63
- const aboveOffset = pageY + height - endCoordinates.screenY;
64
- const belowOffset = endCoordinates.height - aboveOffset;
65
- const aboveValue = -aboveOffset >= cursorSpacing ? 0 : aboveOffset + cursorSpacing;
66
- const belowValue = Math.min(belowOffset, cursorSpacing);
67
- const value = aboveOffset > 0 ? belowValue : aboveValue;
68
- offset.value = withTiming(value, { duration, easing }, (finished) => {
72
+ return aboveOffset > 0 ? belowValue : aboveValue;
73
+ }
74
+ cancelAnimation(offset);
75
+ offset.value = withTiming(calculateOffset(), { duration, easing }, finished => {
69
76
  if (finished) {
70
77
  // Set flexBasic after animation to trigger re-layout and reset layout information
71
78
  basic.value = '99.99%';
72
79
  }
73
80
  });
74
81
  });
75
- }),
76
- Keyboard.addListener('keyboardDidHide', resetKeyboard)
77
- ];
82
+ };
83
+ (isIOS ? () => setTimeout(callback) : callback)();
84
+ }
85
+ }
86
+ if (isIOS) {
87
+ subscriptions = [Keyboard.addListener('keyboardWillShow', keybaordAvoding), Keyboard.addListener('keyboardWillHide', resetKeyboard)];
88
+ }
89
+ else {
90
+ subscriptions = [Keyboard.addListener('keyboardDidShow', keybaordAvoding), Keyboard.addListener('keyboardDidHide', resetKeyboard)];
78
91
  }
79
92
  return () => {
80
93
  subscriptions.forEach(subscription => subscription.remove());
81
94
  };
82
95
  }, [keyboardAvoid]);
83
- return (<View style={style} onTouchEnd={onTouchEnd}>
84
- <Animated.View style={[
85
- contentContainerStyle,
86
- animatedStyle
87
- ]}>
88
- {children}
89
- </Animated.View>
96
+ return (<View style={style} onTouchEnd={onTouchEnd} onTouchMove={onTouchEnd}>
97
+ <Animated.View style={[contentContainerStyle, animatedStyle]}>{children}</Animated.View>
90
98
  </View>);
91
99
  };
92
100
  KeyboardAvoidingView.displayName = 'MpxKeyboardAvoidingView';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * ✘ for
3
+ */
4
+ import { ReactNode } from 'react';
5
+ import { View, ViewStyle, NativeSyntheticEvent } from 'react-native';
6
+ import { HandlerRef } from './useNodesRef';
7
+ export interface LabelProps {
8
+ for?: string;
9
+ style?: ViewStyle & Record<string, any>;
10
+ 'enable-offset'?: boolean;
11
+ 'enable-var'?: boolean;
12
+ 'external-var-context'?: Record<string, any>;
13
+ 'parent-font-size'?: number;
14
+ 'parent-width'?: number;
15
+ 'parent-height'?: number;
16
+ children: ReactNode;
17
+ bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void;
18
+ }
19
+ declare const Label: import("react").ForwardRefExoticComponent<LabelProps & import("react").RefAttributes<HandlerRef<View, LabelProps>>>;
20
+ export default Label;
21
+ //# sourceMappingURL=mpx-label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mpx-label.d.ts","sourceRoot":"","sources":["../mpx-label.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAA2B,SAAS,EAA8B,MAAM,OAAO,CAAA;AACtF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAGpE,OAAoB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAKvD,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACvC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5C,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,SAAS,CAAA;IACnB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,CAAC,UAAU,CAAC,GAAG,OAAO,KAAK,IAAI,CAAA;CACpE;AAED,QAAA,MAAM,KAAK,qHA0FV,CAAA;AAID,eAAe,KAAK,CAAA"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * ✘ scale-area
3
+ */
4
+ import { View } from 'react-native';
5
+ import { ReactNode } from 'react';
6
+ import { HandlerRef } from './useNodesRef';
7
+ interface MovableAreaProps {
8
+ style?: Record<string, any>;
9
+ children: ReactNode;
10
+ width?: number;
11
+ height?: number;
12
+ 'enable-offset'?: boolean;
13
+ 'enable-var'?: boolean;
14
+ 'external-var-context'?: Record<string, any>;
15
+ 'parent-font-size'?: number;
16
+ 'parent-width'?: number;
17
+ 'parent-height'?: number;
18
+ }
19
+ declare const _MovableArea: import("react").ForwardRefExoticComponent<MovableAreaProps & import("react").RefAttributes<HandlerRef<View, MovableAreaProps>>>;
20
+ export default _MovableArea;
21
+ //# sourceMappingURL=mpx-movable-area.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mpx-movable-area.d.ts","sourceRoot":"","sources":["../mpx-movable-area.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAmB,SAAS,EAAkC,MAAM,OAAO,CAAA;AAClF,OAAoB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAMvD,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,QAAQ,EAAE,SAAS,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5C,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,QAAA,MAAM,YAAY,iIAsDhB,CAAA;AAIF,eAAe,YAAY,CAAA"}