@mpxjs/webpack-plugin 2.10.17-beta.3 → 2.10.17-beta.6

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 (228) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/file-loader.js +4 -1
  3. package/lib/global.d.ts +245 -0
  4. package/lib/index.js +29 -2
  5. package/lib/json-compiler/index.js +13 -4
  6. package/lib/loader.js +4 -0
  7. package/lib/platform/json/wx/index.js +6 -0
  8. package/lib/platform/style/wx/index.js +57 -33
  9. package/lib/platform/template/wx/component-config/ad.js +5 -0
  10. package/lib/platform/template/wx/component-config/button.js +10 -3
  11. package/lib/platform/template/wx/component-config/camera.js +25 -3
  12. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  13. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  14. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  15. package/lib/platform/template/wx/component-config/form.js +27 -2
  16. package/lib/platform/template/wx/component-config/image.js +5 -0
  17. package/lib/platform/template/wx/component-config/input.js +11 -1
  18. package/lib/platform/template/wx/component-config/label.js +10 -2
  19. package/lib/platform/template/wx/component-config/map.js +11 -0
  20. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  21. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  22. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  23. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  24. package/lib/platform/template/wx/component-config/picker.js +3 -1
  25. package/lib/platform/template/wx/component-config/progress.js +11 -1
  26. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  27. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  28. package/lib/platform/template/wx/component-config/slider.js +8 -0
  29. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  30. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  31. package/lib/platform/template/wx/component-config/text.js +5 -0
  32. package/lib/platform/template/wx/component-config/textarea.js +20 -3
  33. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  34. package/lib/platform/template/wx/component-config/video.js +10 -0
  35. package/lib/platform/template/wx/index.js +21 -1
  36. package/lib/react/LoadAsyncChunkModule.js +1 -1
  37. package/lib/react/processStyles.js +21 -9
  38. package/lib/react/style-helper.js +76 -13
  39. package/lib/resolver/AddModePlugin.js +23 -8
  40. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  41. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
  42. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +297 -0
  43. package/lib/runtime/components/react/animationHooks/utils.ts +196 -0
  44. package/lib/runtime/components/react/context.ts +7 -1
  45. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  46. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  47. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  48. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
  49. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  50. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +274 -0
  51. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  52. package/lib/runtime/components/react/dist/animationHooks/utils.js +150 -0
  53. package/lib/runtime/components/react/dist/context.d.ts +6 -2
  54. package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
  55. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
  56. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
  57. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  58. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  59. package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
  60. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
  61. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
  62. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
  63. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
  64. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
  65. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
  67. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  68. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  73. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
  75. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
  76. package/lib/runtime/components/react/dist/mpx-input.jsx +10 -9
  77. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +7 -2
  79. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  80. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  81. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  82. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
  83. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
  84. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
  85. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
  86. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
  87. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
  88. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
  89. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
  90. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
  91. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
  92. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
  93. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
  94. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
  95. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  96. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
  97. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
  98. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
  99. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
  100. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
  101. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
  102. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
  103. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
  104. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
  105. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
  106. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  107. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  108. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  109. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  110. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
  111. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  112. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
  113. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  114. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
  115. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  116. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  117. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  118. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  119. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  120. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +11 -1
  121. package/lib/runtime/components/react/dist/mpx-swiper.jsx +71 -39
  122. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  123. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  124. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
  125. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  126. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
  127. package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
  128. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
  129. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  130. package/lib/runtime/components/react/dist/parser.d.ts +0 -1
  131. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
  132. package/lib/runtime/components/react/dist/utils.d.ts +1 -1
  133. package/lib/runtime/components/react/dist/utils.jsx +34 -13
  134. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  135. package/lib/runtime/components/react/mpx-input.tsx +15 -9
  136. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +7 -2
  137. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  138. package/lib/runtime/components/react/mpx-swiper.tsx +86 -37
  139. package/lib/runtime/components/react/mpx-view.tsx +27 -12
  140. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  141. package/lib/runtime/components/react/tsconfig.json +26 -0
  142. package/lib/runtime/components/react/types/global.d.ts +1 -0
  143. package/lib/runtime/components/react/utils.tsx +34 -16
  144. package/lib/runtime/optionProcessor.js +5 -0
  145. package/lib/runtime/optionProcessorReact.js +7 -0
  146. package/lib/runtime/stringify.wxs +2 -2
  147. package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
  148. package/lib/style-compiler/strip-conditional-loader.js +76 -185
  149. package/lib/template-compiler/compiler.js +1 -3
  150. package/lib/utils/dom-tag-config.js +1 -1
  151. package/lib/utils/string.js +25 -1
  152. package/package.json +6 -4
  153. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  154. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  155. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  156. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  157. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  158. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  159. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  160. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  161. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  162. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  163. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  164. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  165. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  166. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  167. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  168. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  169. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  170. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  171. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  172. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  173. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  174. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  175. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  176. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  177. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  178. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  179. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  180. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  181. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  182. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  183. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  184. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  185. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  186. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  187. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  189. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  190. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  192. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  194. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  196. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  198. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  200. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  202. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  204. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  206. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  208. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  210. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  212. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  214. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  216. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  218. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  220. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  222. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  224. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  226. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  228. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
@@ -0,0 +1,327 @@
1
+ import React, { createElement, forwardRef, useRef, useCallback, useContext, useState, useEffect } from 'react'
2
+ import { useTransformStyle, useLayout, extendObject } from './utils'
3
+ import useInnerProps, { getCustomEvent } from './getInnerListeners'
4
+ import { noop } from '@mpxjs/utils'
5
+ import { RouteContext } from './context'
6
+
7
+ const qualityValue = {
8
+ high: 90,
9
+ normal: 75,
10
+ low: 50,
11
+ original: 100
12
+ }
13
+
14
+ interface CameraProps {
15
+ mode?: 'normal' | 'scanCode'
16
+ resolution?: 'low' | 'medium' | 'high'
17
+ devicePosition?: 'front' | 'back'
18
+ flash?: 'auto' | 'on' | 'off'
19
+ frameSize?: 'small' | 'medium' | 'large'
20
+ style?: Record<string, any>
21
+ bindstop?: () => void
22
+ binderror?: (error: { message: string }) => void
23
+ bindinitdone?: (result: { type: string, data: string }) => void
24
+ bindscancode?: (result: { type: string, data: string }) => void
25
+ 'parent-font-size'?: number
26
+ 'parent-width'?: number
27
+ 'parent-height'?: number
28
+ 'enable-var'?: boolean
29
+ 'external-var-context'?: any
30
+ }
31
+
32
+ interface TakePhotoOptions {
33
+ quality?: 'high' | 'normal' | 'low' | 'original'
34
+ success?: (result: { errMsg: string, tempImagePath: string }) => void
35
+ fail?: (result: { errMsg: string }) => void
36
+ complete?: (result: { errMsg: string, tempImagePath?: string }) => void
37
+ }
38
+
39
+ interface RecordOptions {
40
+ timeout?: number
41
+ success?: (result: { errMsg: string }) => void
42
+ fail?: (result: { errMsg: string, error?: any }) => void
43
+ complete?: (result: { errMsg: string }) => void
44
+ timeoutCallback?: (result: { errMsg: string, error?: any }) => void
45
+ }
46
+
47
+ interface StopRecordOptions {
48
+ success?: (result: { errMsg: string, tempVideoPath: string, duration: number }) => void
49
+ fail?: (result: { errMsg: string }) => void
50
+ complete?: (result: { errMsg: string, tempVideoPath?: string, duration?: number }) => void
51
+ }
52
+
53
+ interface CameraRef {
54
+ setZoom: (zoom: number) => void
55
+ takePhoto: (options?: TakePhotoOptions) => void
56
+ startRecord: (options?: RecordOptions) => void
57
+ stopRecord: (options?: StopRecordOptions) => void
58
+ }
59
+
60
+ type HandlerRef<T, P> = {
61
+ current: T | null
62
+ }
63
+
64
+ let RecordRes: any = null
65
+
66
+ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: CameraProps, ref): JSX.Element | null => {
67
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
68
+ const { Camera, useCameraDevice, useCodeScanner, useCameraFormat } = require('react-native-vision-camera')
69
+ const cameraRef = useRef<any>(null)
70
+ const {
71
+ mode = 'normal',
72
+ resolution = 'medium',
73
+ devicePosition = 'back',
74
+ flash = 'auto',
75
+ frameSize = 'medium',
76
+ bindinitdone,
77
+ bindstop,
78
+ bindscancode,
79
+ 'parent-font-size': parentFontSize,
80
+ 'parent-width': parentWidth,
81
+ 'parent-height': parentHeight,
82
+ 'enable-var': enableVar,
83
+ 'external-var-context': externalVarContext,
84
+ style = {}
85
+ } = props
86
+ const styleObj = extendObject(
87
+ {},
88
+ style
89
+ )
90
+ const {
91
+ normalStyle,
92
+ hasSelfPercent,
93
+ setWidth,
94
+ setHeight
95
+ } = useTransformStyle(styleObj, {
96
+ enableVar,
97
+ externalVarContext,
98
+ parentFontSize,
99
+ parentWidth,
100
+ parentHeight
101
+ })
102
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: cameraRef })
103
+ const isPhoto = mode === 'normal'
104
+ const device = useCameraDevice(devicePosition || 'back')
105
+ const { navigation } = useContext(RouteContext) || {}
106
+ const [zoomValue, setZoomValue] = useState<number>(1)
107
+ const [hasPermission, setHasPermission] = useState<boolean | null>(null)
108
+ const hasCamera = useRef(false)
109
+
110
+ // 先定义常量,避免在条件判断后使用
111
+ const maxZoom = device?.maxZoom || 1
112
+ const RESOLUTION_MAPPING: Record<string, { width: number, height: number }> = {
113
+ low: { width: 640, height: 480 },
114
+ medium: { width: 1280, height: 720 },
115
+ high: { width: 1920, height: 1080 }
116
+ }
117
+ const FRAME_SIZE_MAPPING: Record<string, { width: number, height: number }> = {
118
+ small: { width: 480, height: 360 },
119
+ medium: { width: 720, height: 540 },
120
+ large: { width: 1080, height: 810 }
121
+ }
122
+
123
+ const format = useCameraFormat(device, [
124
+ {
125
+ photoResolution: RESOLUTION_MAPPING[resolution],
126
+ videoResolution: FRAME_SIZE_MAPPING[frameSize] || RESOLUTION_MAPPING[resolution]
127
+ }
128
+ ])
129
+
130
+ const codeScanner = useCodeScanner({
131
+ codeTypes: ['qr', 'ean-13'],
132
+ onCodeScanned: (codes: any[]) => {
133
+ const result = codes.map(code => code.value).join(',')
134
+ bindscancode && bindscancode(getCustomEvent('scancode', {}, {
135
+ detail: {
136
+ result: codes.map(code => code.value).join(',')
137
+ }
138
+ }))
139
+ }
140
+ })
141
+
142
+ const onInitialized = useCallback(() => {
143
+ bindinitdone && bindinitdone(getCustomEvent('initdone', {}, {
144
+ detail: {
145
+ maxZoom
146
+ }
147
+ }))
148
+ }, [bindinitdone, maxZoom])
149
+
150
+ const onStopped = useCallback(() => {
151
+ bindstop && bindstop()
152
+ }, [bindstop])
153
+
154
+ const camera: CameraRef = {
155
+ setZoom: (zoom: number) => {
156
+ setZoomValue(zoom)
157
+ },
158
+ takePhoto: (options: TakePhotoOptions = {}) => {
159
+ const { success = noop, fail = noop, complete = noop } = options
160
+ cameraRef.current?.takePhoto?.({
161
+ flash,
162
+ quality: qualityValue[options.quality || 'normal'] as number
163
+ } as any).then((res: { path: any }) => {
164
+ const result = {
165
+ errMsg: 'takePhoto:ok',
166
+ tempImagePath: res.path
167
+ }
168
+ success(result)
169
+ complete(result)
170
+ }).catch(() => {
171
+ const result = {
172
+ errMsg: 'takePhoto:fail'
173
+ }
174
+ fail(result)
175
+ complete(result)
176
+ })
177
+ },
178
+ startRecord: (options: RecordOptions = {}) => {
179
+ let { timeout = 30, success = noop, fail = noop, complete = noop, timeoutCallback = noop } = options
180
+ timeout = timeout > 300 ? 300 : timeout
181
+ let recordTimer: NodeJS.Timeout | null = null
182
+ let isTimeout = false
183
+ try {
184
+ const result = {
185
+ errMsg: 'startRecord:ok'
186
+ }
187
+ success(result)
188
+ complete(result)
189
+
190
+ cameraRef.current?.startRecording?.({
191
+ flash,
192
+ onRecordingError: (error: any) => {
193
+ if (recordTimer) clearTimeout(recordTimer)
194
+ const errorResult = {
195
+ errMsg: 'startRecord:fail during recording',
196
+ error: error
197
+ }
198
+ timeoutCallback(errorResult)
199
+ },
200
+ onRecordingFinished: (video: any) => {
201
+ RecordRes = video
202
+ if (recordTimer) clearTimeout(recordTimer)
203
+ }
204
+ })
205
+
206
+ recordTimer = setTimeout(() => { // 超时自动停止
207
+ isTimeout = true
208
+ cameraRef.current?.stopRecording().catch(() => {
209
+ // 忽略停止录制时的错误
210
+ })
211
+ }, timeout * 1000)
212
+ } catch (error: any) {
213
+ if (recordTimer) clearTimeout(recordTimer)
214
+ const result = {
215
+ errMsg: 'startRecord:fail ' + (error.message || 'unknown error')
216
+ }
217
+ fail(result)
218
+ complete(result)
219
+ }
220
+ },
221
+ stopRecord: (options: StopRecordOptions = {}) => {
222
+ const { success = noop, fail = noop, complete = noop } = options
223
+ try {
224
+ cameraRef.current?.stopRecording().then(() => {
225
+ setTimeout(() => {
226
+ if (RecordRes) {
227
+ const result = {
228
+ errMsg: 'stopRecord:ok',
229
+ tempVideoPath: RecordRes?.path,
230
+ duration: RecordRes.duration * 1000 // 转成ms
231
+ }
232
+ RecordRes = null
233
+ success(result)
234
+ complete(result)
235
+ }
236
+ }, 200) // 延时200ms,确保录制结果已准备好
237
+ }).catch((e: any) => {
238
+ const result = {
239
+ errMsg: 'stopRecord:fail ' + (e.message || 'promise rejected')
240
+ }
241
+ fail(result)
242
+ complete(result)
243
+ })
244
+ } catch (error: any) {
245
+ const result = {
246
+ errMsg: 'stopRecord:fail ' + (error.message || 'unknown error')
247
+ }
248
+ fail(result)
249
+ complete(result)
250
+ }
251
+ }
252
+ }
253
+
254
+ useEffect(() => {
255
+ if (navigation) {
256
+ if (navigation && !navigation.camera) {
257
+ navigation.camera = camera
258
+ } else {
259
+ hasCamera.current = true
260
+ navigation.camera.multi = true
261
+ }
262
+ }
263
+ const checkCameraPermission = async () => {
264
+ try {
265
+ const cameraPermission = global?.__mpx?.config?.rnConfig?.cameraPermission
266
+ if (typeof cameraPermission === 'function') {
267
+ const permissionResult = await cameraPermission()
268
+ setHasPermission(permissionResult === true)
269
+ } else {
270
+ setHasPermission(true)
271
+ }
272
+ } catch (error) {
273
+ setHasPermission(false)
274
+ }
275
+ }
276
+ checkCameraPermission()
277
+ return () => {
278
+ if (navigation && navigation.camera) {
279
+ navigation.camera = null
280
+ }
281
+ }
282
+ }, [])
283
+
284
+ const innerProps = useInnerProps(
285
+ extendObject(
286
+ {},
287
+ props,
288
+ layoutProps,
289
+ {
290
+ ref: cameraRef,
291
+ style: extendObject({}, normalStyle, layoutStyle),
292
+ isActive: true,
293
+ photo: true,
294
+ video: true,
295
+ onInitialized,
296
+ onStopped,
297
+ device,
298
+ format,
299
+ codeScanner: !isPhoto ? codeScanner : undefined,
300
+ zoom: zoomValue
301
+ }
302
+ ),
303
+ [
304
+ 'mode',
305
+ 'resolution',
306
+ 'frame-size',
307
+ 'bindinitdone',
308
+ 'bindstop',
309
+ 'flash',
310
+ 'bindscancode',
311
+ 'binderror'
312
+ ],
313
+ {
314
+ layoutRef
315
+ }
316
+ )
317
+
318
+ if (!hasPermission || hasCamera.current || !device) {
319
+ return null
320
+ }
321
+
322
+ return createElement(Camera, innerProps)
323
+ })
324
+
325
+ _camera.displayName = 'MpxCamera'
326
+
327
+ export default _camera
@@ -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
@@ -95,13 +95,16 @@ export interface InputProps {
95
95
  'selection-start'?: number
96
96
  'selection-end'?: number
97
97
  'placeholder-style'?: { color?: string }
98
- 'enable-offset'?: boolean,
98
+ 'enable-offset'?: boolean
99
99
  'enable-var'?: boolean
100
100
  'external-var-context'?: Record<string, any>
101
101
  'parent-font-size'?: number
102
102
  'parent-width'?: number
103
103
  'parent-height'?: number
104
- 'adjust-position': boolean,
104
+ // 只有 RN 环境读取
105
+ 'keyboard-type'?: string
106
+ 'adjust-position': boolean
107
+ 'hold-keyboard'?: boolean
105
108
  bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
106
109
  bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
107
110
  bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
@@ -118,11 +121,11 @@ export interface PrivateInputProps {
118
121
 
119
122
  type FinalInputProps = InputProps & PrivateInputProps
120
123
 
121
- const keyboardTypeMap: Record<Type, string> = {
122
- text: 'default',
124
+ const inputModeMap: Record<Type, string> = {
125
+ text: 'text',
123
126
  number: 'numeric',
124
- idcard: 'default',
125
- digit: isIOS ? 'decimal-pad' : 'numeric'
127
+ idcard: 'text',
128
+ digit: 'decimal'
126
129
  }
127
130
 
128
131
  const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps>((props: FinalInputProps, ref): JSX.Element => {
@@ -150,6 +153,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
150
153
  'parent-width': parentWidth,
151
154
  'parent-height': parentHeight,
152
155
  'adjust-position': adjustPosition = true,
156
+ 'keyboard-type': originalKeyboardType,
157
+ 'hold-keyboard': holdKeyboard = false,
153
158
  bindinput,
154
159
  bindfocus,
155
160
  bindblur,
@@ -182,7 +187,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
182
187
  return ''
183
188
  }
184
189
 
185
- const keyboardType = keyboardTypeMap[type]
186
190
  const defaultValue = parseValue(value)
187
191
  const textAlignVertical = multiline ? 'top' : 'auto'
188
192
 
@@ -285,6 +289,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
285
289
  cursorSpacing,
286
290
  ref: nodeRef,
287
291
  adjustPosition,
292
+ holdKeyboard,
288
293
  // fix: iOS 会在 onFocus 之前触发 keyboardWillShow 并且赋值 keyboardHeight
289
294
  // 这里手动同步下 keyboardHeight,防止 onFocus setKeyboardAvoidContext 删掉 keyboardHeight
290
295
  keyboardHeight: keyboardAvoid?.current?.keyboardHeight
@@ -473,7 +478,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
473
478
  ref: nodeRef,
474
479
  style: extendObject({}, normalStyle, layoutStyle),
475
480
  allowFontScaling,
476
- keyboardType: keyboardType,
481
+ inputMode: originalKeyboardType ? undefined : inputModeMap[type],
482
+ keyboardType: originalKeyboardType,
477
483
  secureTextEntry: !!password,
478
484
  defaultValue: defaultValue,
479
485
  value: inputValue,
@@ -25,8 +25,10 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
25
25
  const isShow = useRef<boolean>(false)
26
26
 
27
27
  const animatedStyle = useAnimatedStyle(() => ({
28
- // translate/position top可能会导致底部渲染区域缺失
29
- marginTop: -offset.value,
28
+ // translate/position top+ overflow hidden 在 android 上时因为键盘顶起让页面高度变小,同时元素位置上移
29
+ // 此时最底部的区域是超出了页面高度的,hidden生效就被隐藏掉,因此需要 android 配置聚焦时禁用高度缩小
30
+ // margin-top 因为在 react-native 上和 flex 1 同时存在时,负值只会让容器高度整体变高,不会让元素上移
31
+ transform: [{ translateY: -offset.value }],
30
32
  flexBasis: basic.value as DimensionValue
31
33
  }))
32
34
 
@@ -53,6 +55,9 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
53
55
 
54
56
  const onTouchEnd = ({ nativeEvent }: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
55
57
  if (nativeEvent.origin !== 'input') {
58
+ if (keyboardAvoid?.current?.holdKeyboard) {
59
+ return
60
+ }
56
61
  Keyboard.isVisible() && Keyboard.dismiss()
57
62
  }
58
63
  }
@@ -19,7 +19,7 @@ const _PortalManager = forwardRef((props: PortalManagerProps, ref:ForwardedRef<u
19
19
  setState((prevState) => ({
20
20
  portals: [...prevState.portals, { key, children }]
21
21
  }))
22
- }, [state])
22
+ }, [])
23
23
 
24
24
  const update = useCallback((key: number, children: ReactNode) => {
25
25
  setState((prevState) => ({
@@ -30,7 +30,7 @@ const _PortalManager = forwardRef((props: PortalManagerProps, ref:ForwardedRef<u
30
30
  return item
31
31
  })
32
32
  }))
33
- }, [state])
33
+ }, [])
34
34
 
35
35
  const unmount = useCallback((key: number) => {
36
36
  setState((prevState) => ({