@mpxjs/webpack-plugin 2.10.15 → 2.10.16-beta.11
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.
- package/lib/config.js +60 -0
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/DynamicEntryDependency.js +1 -1
- package/lib/dependencies/ImportDependency.js +102 -0
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/{retry-runtime-module.js → dependencies/RetryRuntimeModule.js} +1 -1
- package/lib/file-loader.js +13 -3
- package/lib/helpers.js +2 -0
- package/lib/index.js +51 -25
- package/lib/json-compiler/helper.js +72 -2
- package/lib/json-compiler/index.js +16 -56
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +10 -4
- package/lib/native-loader.js +6 -3
- package/lib/platform/json/wx/index.js +30 -29
- package/lib/platform/style/wx/index.js +8 -1
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +21 -5
- package/lib/platform/template/wx/component-config/camera.js +25 -3
- package/lib/platform/template/wx/component-config/canvas.js +8 -1
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/form.js +27 -2
- package/lib/platform/template/wx/component-config/image.js +5 -0
- package/lib/platform/template/wx/component-config/input.js +10 -0
- package/lib/platform/template/wx/component-config/label.js +10 -2
- package/lib/platform/template/wx/component-config/map.js +11 -0
- package/lib/platform/template/wx/component-config/movable-area.js +4 -1
- package/lib/platform/template/wx/component-config/movable-view.js +17 -2
- package/lib/platform/template/wx/component-config/navigator.js +26 -0
- package/lib/platform/template/wx/component-config/picker-view.js +12 -0
- package/lib/platform/template/wx/component-config/picker.js +3 -1
- package/lib/platform/template/wx/component-config/progress.js +11 -1
- package/lib/platform/template/wx/component-config/rich-text.js +5 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
- package/lib/platform/template/wx/component-config/slider.js +20 -0
- package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
- package/lib/platform/template/wx/component-config/swiper.js +10 -0
- package/lib/platform/template/wx/component-config/text.js +5 -0
- package/lib/platform/template/wx/component-config/textarea.js +19 -2
- package/lib/platform/template/wx/component-config/unsupported.js +10 -1
- package/lib/platform/template/wx/component-config/video.js +10 -0
- package/lib/platform/template/wx/index.js +21 -1
- package/lib/react/index.js +2 -0
- package/lib/react/processJSON.js +39 -71
- package/lib/react/processStyles.js +3 -2
- package/lib/react/processTemplate.js +8 -6
- package/lib/react/script-helper.js +6 -16
- package/lib/react/style-helper.js +10 -2
- package/lib/resolver/AddEnvPlugin.js +13 -0
- package/lib/resolver/AddModePlugin.js +18 -0
- package/lib/runtime/components/react/context.ts +13 -6
- package/lib/runtime/components/react/dist/context.d.ts +76 -0
- package/lib/runtime/components/react/dist/context.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +8 -0
- package/lib/runtime/components/react/dist/event.config.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +8 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +69 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +197 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +28 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +81 -37
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +40 -12
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +61 -50
- package/lib/runtime/components/react/dist/mpx-label.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +66 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +3 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +107 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +33 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +30 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-progress.jsx +26 -22
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +25 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +55 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-slider.jsx +321 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +19 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +53 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +9 -5
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +102 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/parser.d.ts +40 -0
- package/lib/runtime/components/react/dist/parser.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +33 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +12 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.d.ts +123 -0
- package/lib/runtime/components/react/dist/utils.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/utils.jsx +16 -6
- package/lib/runtime/components/react/mpx-camera.tsx +275 -0
- package/lib/runtime/components/react/mpx-image.tsx +89 -42
- package/lib/runtime/components/react/mpx-input.tsx +50 -18
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +69 -49
- package/lib/runtime/components/react/mpx-nav.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
- package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
- package/lib/runtime/components/react/mpx-progress.tsx +26 -24
- package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
- package/lib/runtime/components/react/mpx-slider.tsx +444 -0
- package/lib/runtime/components/react/mpx-swiper.tsx +9 -5
- package/lib/runtime/components/react/mpx-text.tsx +38 -5
- package/lib/runtime/components/react/mpx-view.tsx +8 -11
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/utils.tsx +15 -6
- package/lib/runtime/components/web/mpx-input.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +7 -1
- package/lib/runtime/components/web/mpx-video.vue +12 -1
- package/lib/runtime/optionProcessor.js +3 -1
- package/lib/runtime/optionProcessorReact.js +4 -2
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/script-setup-compiler/index.js +2 -2
- package/lib/style-compiler/index.js +3 -2
- package/lib/style-compiler/load-postcss-config.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +10 -2
- package/lib/style-compiler/strip-conditional-loader.js +178 -15
- package/lib/template-compiler/bind-this.js +2 -2
- package/lib/template-compiler/compiler.js +277 -77
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +12 -10
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/chain-assign.js +47 -0
- package/lib/utils/check-core-version-match.js +75 -15
- package/lib/utils/const.js +2 -1
- package/lib/utils/dom-tag-config.js +6 -6
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -0
- package/lib/utils/pre-process-json.js +5 -0
- package/lib/web/index.js +2 -0
- package/lib/web/processJSON.js +44 -16
- package/lib/web/processScript.js +1 -1
- package/lib/web/processTemplate.js +6 -4
- package/lib/web/script-helper.js +19 -9
- package/lib/wxs/pre-loader.js +6 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +17 -5
- package/LICENSE +0 -433
- package/lib/dependencies/ImportDependencyTemplate.js +0 -50
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import React, { forwardRef, useRef, useCallback, useContext, useState, useEffect } from 'react'
|
|
2
|
+
// import { Camera, useCameraDevice, useCodeScanner, useCameraFormat } from 'react-native-vision-camera'
|
|
3
|
+
import { 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
|
+
}
|
|
26
|
+
|
|
27
|
+
interface TakePhotoOptions {
|
|
28
|
+
quality?: 'high' | 'normal' | 'low' | 'original'
|
|
29
|
+
success?: (result: { errMsg: string, tempImagePath: string }) => void
|
|
30
|
+
fail?: (result: { errMsg: string }) => void
|
|
31
|
+
complete?: (result: { errMsg: string, tempImagePath?: string }) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface RecordOptions {
|
|
35
|
+
timeout?: number
|
|
36
|
+
success?: (result: { errMsg: string }) => void
|
|
37
|
+
fail?: (result: { errMsg: string, error?: any }) => void
|
|
38
|
+
complete?: (result: { errMsg: string }) => void
|
|
39
|
+
timeoutCallback?: (result: { errMsg: string, error?: any }) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface StopRecordOptions {
|
|
43
|
+
success?: (result: { errMsg: string, tempVideoPath: string, duration: number }) => void
|
|
44
|
+
fail?: (result: { errMsg: string }) => void
|
|
45
|
+
complete?: (result: { errMsg: string, tempVideoPath?: string, duration?: number }) => void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface CameraRef {
|
|
49
|
+
setZoom: (zoom: number) => void
|
|
50
|
+
takePhoto: (options?: TakePhotoOptions) => void
|
|
51
|
+
startRecord: (options?: RecordOptions) => void
|
|
52
|
+
stopRecord: (options?: StopRecordOptions) => void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type HandlerRef<T, P> = {
|
|
56
|
+
current: T | null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let RecordRes: any = null
|
|
60
|
+
|
|
61
|
+
const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: CameraProps, ref): JSX.Element | null => {
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
63
|
+
const { Camera, useCameraDevice, useCodeScanner, useCameraFormat } = require('react-native-vision-camera')
|
|
64
|
+
const cameraRef = useRef<any>(null)
|
|
65
|
+
const {
|
|
66
|
+
mode = 'normal',
|
|
67
|
+
resolution = 'medium',
|
|
68
|
+
devicePosition = 'back',
|
|
69
|
+
flash = 'auto',
|
|
70
|
+
frameSize = 'medium',
|
|
71
|
+
bindinitdone,
|
|
72
|
+
bindstop,
|
|
73
|
+
bindscancode
|
|
74
|
+
} = props
|
|
75
|
+
|
|
76
|
+
const isPhoto = mode === 'normal'
|
|
77
|
+
const device = useCameraDevice(devicePosition || 'back')
|
|
78
|
+
const { navigation } = useContext(RouteContext) || {}
|
|
79
|
+
const [zoomValue, setZoomValue] = useState<number>(1)
|
|
80
|
+
const [hasPermission, setHasPermission] = useState<boolean | null>(null)
|
|
81
|
+
const hasCamera = useRef(false)
|
|
82
|
+
|
|
83
|
+
// 先定义常量,避免在条件判断后使用
|
|
84
|
+
const maxZoom = device?.maxZoom || 1
|
|
85
|
+
const RESOLUTION_MAPPING: Record<string, { width: number, height: number }> = {
|
|
86
|
+
low: { width: 640, height: 480 },
|
|
87
|
+
medium: { width: 1280, height: 720 },
|
|
88
|
+
high: { width: 1920, height: 1080 }
|
|
89
|
+
}
|
|
90
|
+
const FRAME_SIZE_MAPPING: Record<string, { width: number, height: number }> = {
|
|
91
|
+
small: { width: 480, height: 360 },
|
|
92
|
+
medium: { width: 720, height: 540 },
|
|
93
|
+
large: { width: 1080, height: 810 }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 所有 Hooks 必须在条件判断之前调用
|
|
97
|
+
const format = useCameraFormat(device, [
|
|
98
|
+
{
|
|
99
|
+
photoResolution: RESOLUTION_MAPPING[resolution],
|
|
100
|
+
videoResolution: FRAME_SIZE_MAPPING[frameSize] || RESOLUTION_MAPPING[resolution]
|
|
101
|
+
}
|
|
102
|
+
])
|
|
103
|
+
|
|
104
|
+
const codeScanner = useCodeScanner({
|
|
105
|
+
codeTypes: ['qr', 'ean-13'],
|
|
106
|
+
onCodeScanned: (codes: any[]) => {
|
|
107
|
+
const result = codes.map(code => code.value).join(',')
|
|
108
|
+
bindscancode && bindscancode(getCustomEvent('scancode', {}, {
|
|
109
|
+
detail: {
|
|
110
|
+
result: codes.map(code => code.value).join(',')
|
|
111
|
+
}
|
|
112
|
+
}))
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const onInitialized = useCallback(() => {
|
|
117
|
+
bindinitdone && bindinitdone(getCustomEvent('initdone', {}, {
|
|
118
|
+
detail: {
|
|
119
|
+
maxZoom
|
|
120
|
+
}
|
|
121
|
+
}))
|
|
122
|
+
}, [bindinitdone, maxZoom])
|
|
123
|
+
|
|
124
|
+
const onStopped = useCallback(() => {
|
|
125
|
+
bindstop && bindstop()
|
|
126
|
+
}, [bindstop])
|
|
127
|
+
|
|
128
|
+
const camera: CameraRef = {
|
|
129
|
+
setZoom: (zoom: number) => {
|
|
130
|
+
setZoomValue(zoom)
|
|
131
|
+
},
|
|
132
|
+
takePhoto: (options: TakePhotoOptions = {}) => {
|
|
133
|
+
const { success = noop, fail = noop, complete = noop } = options
|
|
134
|
+
cameraRef.current?.takePhoto?.({
|
|
135
|
+
quality: qualityValue[options.quality || 'normal'] as number
|
|
136
|
+
} as any).then((res: { path: any }) => {
|
|
137
|
+
const result = {
|
|
138
|
+
errMsg: 'takePhoto:ok',
|
|
139
|
+
tempImagePath: res.path
|
|
140
|
+
}
|
|
141
|
+
success(result)
|
|
142
|
+
complete(result)
|
|
143
|
+
}).catch(() => {
|
|
144
|
+
const result = {
|
|
145
|
+
errMsg: 'takePhoto:fail'
|
|
146
|
+
}
|
|
147
|
+
fail(result)
|
|
148
|
+
complete(result)
|
|
149
|
+
})
|
|
150
|
+
},
|
|
151
|
+
startRecord: (options: RecordOptions = {}) => {
|
|
152
|
+
let { timeout = 30, success = noop, fail = noop, complete = noop, timeoutCallback = noop } = options
|
|
153
|
+
timeout = timeout > 300 ? 300 : timeout
|
|
154
|
+
let recordTimer: NodeJS.Timeout | null = null
|
|
155
|
+
let isTimeout = false
|
|
156
|
+
try {
|
|
157
|
+
const result = {
|
|
158
|
+
errMsg: 'startRecord:ok'
|
|
159
|
+
}
|
|
160
|
+
success(result)
|
|
161
|
+
complete(result)
|
|
162
|
+
|
|
163
|
+
cameraRef.current?.startRecording?.({
|
|
164
|
+
onRecordingError: (error: any) => {
|
|
165
|
+
if (recordTimer) clearTimeout(recordTimer)
|
|
166
|
+
const errorResult = {
|
|
167
|
+
errMsg: 'startRecord:fail during recording',
|
|
168
|
+
error: error
|
|
169
|
+
}
|
|
170
|
+
timeoutCallback(errorResult)
|
|
171
|
+
},
|
|
172
|
+
onRecordingFinished: (video: any) => {
|
|
173
|
+
RecordRes = video
|
|
174
|
+
if (recordTimer) clearTimeout(recordTimer)
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
recordTimer = setTimeout(() => { // 超时自动停止
|
|
179
|
+
isTimeout = true
|
|
180
|
+
cameraRef.current?.stopRecording().catch(() => {
|
|
181
|
+
// 忽略停止录制时的错误
|
|
182
|
+
})
|
|
183
|
+
}, timeout * 1000)
|
|
184
|
+
} catch (error: any) {
|
|
185
|
+
if (recordTimer) clearTimeout(recordTimer)
|
|
186
|
+
const result = {
|
|
187
|
+
errMsg: 'startRecord:fail ' + (error.message || 'unknown error')
|
|
188
|
+
}
|
|
189
|
+
fail(result)
|
|
190
|
+
complete(result)
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
stopRecord: (options: StopRecordOptions = {}) => {
|
|
194
|
+
const { success = noop, fail = noop, complete = noop } = options
|
|
195
|
+
try {
|
|
196
|
+
cameraRef.current?.stopRecording().then(() => {
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
if (RecordRes) {
|
|
199
|
+
const result = {
|
|
200
|
+
errMsg: 'stopRecord:ok',
|
|
201
|
+
tempVideoPath: RecordRes?.path,
|
|
202
|
+
duration: RecordRes.duration * 1000 // 转成ms
|
|
203
|
+
}
|
|
204
|
+
RecordRes = null
|
|
205
|
+
success(result)
|
|
206
|
+
complete(result)
|
|
207
|
+
}
|
|
208
|
+
}, 200) // 延时200ms,确保录制结果已准备好
|
|
209
|
+
}).catch((e: any) => {
|
|
210
|
+
const result = {
|
|
211
|
+
errMsg: 'stopRecord:fail ' + (e.message || 'promise rejected')
|
|
212
|
+
}
|
|
213
|
+
fail(result)
|
|
214
|
+
complete(result)
|
|
215
|
+
})
|
|
216
|
+
} catch (error: any) {
|
|
217
|
+
const result = {
|
|
218
|
+
errMsg: 'stopRecord:fail ' + (error.message || 'unknown error')
|
|
219
|
+
}
|
|
220
|
+
fail(result)
|
|
221
|
+
complete(result)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (navigation) {
|
|
227
|
+
if (navigation && !navigation.camera) {
|
|
228
|
+
navigation.camera = camera
|
|
229
|
+
} else {
|
|
230
|
+
hasCamera.current = true
|
|
231
|
+
navigation.camera.multi = true
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const checkCameraPermission = async () => {
|
|
235
|
+
try {
|
|
236
|
+
const cameraPermission = global?.__mpx?.config?.rnConfig?.cameraPermission
|
|
237
|
+
if (typeof cameraPermission === 'function') {
|
|
238
|
+
const permissionResult = await cameraPermission()
|
|
239
|
+
setHasPermission(permissionResult === true)
|
|
240
|
+
} else {
|
|
241
|
+
setHasPermission(true)
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
setHasPermission(false)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
checkCameraPermission()
|
|
248
|
+
}, [])
|
|
249
|
+
|
|
250
|
+
if (!hasPermission || hasCamera.current || !device) {
|
|
251
|
+
return null
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<Camera
|
|
256
|
+
ref={cameraRef}
|
|
257
|
+
isActive={true}
|
|
258
|
+
photo={true}
|
|
259
|
+
video={true}
|
|
260
|
+
onInitialized={onInitialized}
|
|
261
|
+
onStopped={onStopped}
|
|
262
|
+
device={device}
|
|
263
|
+
flash={flash}
|
|
264
|
+
format={format}
|
|
265
|
+
codeScanner={!isPhoto ? codeScanner : undefined}
|
|
266
|
+
style={{ flex: 1 }}
|
|
267
|
+
zoom={zoomValue}
|
|
268
|
+
{...props}
|
|
269
|
+
/>
|
|
270
|
+
)
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
_camera.displayName = 'MpxCamera'
|
|
274
|
+
|
|
275
|
+
export default _camera
|
|
@@ -62,8 +62,8 @@ export interface ImageProps {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
interface ImageState {
|
|
65
|
-
viewWidth
|
|
66
|
-
viewHeight
|
|
65
|
+
viewWidth: number
|
|
66
|
+
viewHeight: number
|
|
67
67
|
imageWidth?: number
|
|
68
68
|
imageHeight?: number
|
|
69
69
|
ratio?: number
|
|
@@ -93,9 +93,20 @@ const ModeMap = new Map<Mode, ImageResizeMode | undefined>([
|
|
|
93
93
|
...cropMode.map<[Mode, ImageResizeMode]>(mode => [mode, 'stretch'])
|
|
94
94
|
])
|
|
95
95
|
|
|
96
|
-
const isNumber = (value: DimensionValue) => typeof value === 'number'
|
|
96
|
+
const isNumber = (value: DimensionValue): value is number => typeof value === 'number'
|
|
97
97
|
|
|
98
|
-
const relativeCenteredSize = (viewSize: number, imageSize: number) =>
|
|
98
|
+
const relativeCenteredSize = (viewSize: number, imageSize: number) => {
|
|
99
|
+
return (viewSize - imageSize) / 2
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 获取能完全显示图片的缩放比例:长宽方向的缩放比例最小值即为能完全展示的比例
|
|
103
|
+
function getFitScale (width1: number, height1: number, width2: number, height2: number) {
|
|
104
|
+
return Math.min(width2 / width1, height2 / height1)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getFillScale (width1: number, height1: number, width2: number, height2: number) {
|
|
108
|
+
return Math.max(width2 / width1, height2 / height1)
|
|
109
|
+
}
|
|
99
110
|
|
|
100
111
|
function noMeetCalcRule (isSvg: boolean, mode: Mode, viewWidth: number, viewHeight: number, ratio: number) {
|
|
101
112
|
const isMeetSize = viewWidth && viewHeight && ratio
|
|
@@ -104,6 +115,17 @@ function noMeetCalcRule (isSvg: boolean, mode: Mode, viewWidth: number, viewHeig
|
|
|
104
115
|
return false
|
|
105
116
|
}
|
|
106
117
|
|
|
118
|
+
const getFixedWidth = (viewWidth: number, viewHeight: number, ratio: number) => {
|
|
119
|
+
if (!ratio) return viewWidth
|
|
120
|
+
const fixed = viewHeight / ratio
|
|
121
|
+
return !fixed ? viewWidth : fixed
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const getFixedHeight = (viewWidth: number, viewHeight: number, ratio: number) => {
|
|
125
|
+
const fixed = viewWidth * ratio
|
|
126
|
+
return !fixed ? viewHeight : fixed
|
|
127
|
+
}
|
|
128
|
+
|
|
107
129
|
const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, ref): JSX.Element => {
|
|
108
130
|
const {
|
|
109
131
|
src = '',
|
|
@@ -131,8 +153,6 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
131
153
|
{ overflow: 'hidden' }
|
|
132
154
|
)
|
|
133
155
|
|
|
134
|
-
const state = useRef<ImageState>({})
|
|
135
|
-
|
|
136
156
|
const nodeRef = useRef(null)
|
|
137
157
|
useNodesRef(props, ref, nodeRef, {
|
|
138
158
|
defaultStyle
|
|
@@ -148,14 +168,18 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
148
168
|
const onLayout = ({ nativeEvent: { layout: { width, height } } }: LayoutChangeEvent) => {
|
|
149
169
|
state.current.viewWidth = width
|
|
150
170
|
state.current.viewHeight = height
|
|
151
|
-
|
|
171
|
+
// 实际渲染尺寸可能会指定的值不一致,误差低于 0.5 则认为没有变化
|
|
172
|
+
if (Math.abs(viewHeight - height) < 0.5 && Math.abs(viewWidth - width) < 0.5) {
|
|
173
|
+
if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
|
|
174
|
+
if (!loaded) setLoaded(true)
|
|
175
|
+
}
|
|
176
|
+
return
|
|
177
|
+
}
|
|
152
178
|
if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
|
|
153
|
-
setViewWidth(width)
|
|
154
|
-
setViewHeight(height)
|
|
155
179
|
setRatio(state.current.ratio)
|
|
156
180
|
setImageWidth(state.current.imageWidth)
|
|
157
181
|
setImageHeight(state.current.imageHeight)
|
|
158
|
-
state.current
|
|
182
|
+
setViewSize(state.current.viewWidth!, state.current.viewHeight!, state.current.ratio!)
|
|
159
183
|
setLoaded(true)
|
|
160
184
|
}
|
|
161
185
|
}
|
|
@@ -186,43 +210,57 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
186
210
|
const [ratio, setRatio] = useState(0)
|
|
187
211
|
const [loaded, setLoaded] = useState(!isLayoutMode)
|
|
188
212
|
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
213
|
+
const state = useRef<ImageState>({
|
|
214
|
+
viewWidth,
|
|
215
|
+
viewHeight
|
|
216
|
+
})
|
|
193
217
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
218
|
+
function setViewSize (viewWidth: number, viewHeight: number, ratio: number) {
|
|
219
|
+
// 在特定模式下可预测 view 的变化,在onLayout触发时能以此避免重复render
|
|
220
|
+
switch (mode) {
|
|
221
|
+
case 'widthFix': {
|
|
222
|
+
setViewWidth(viewWidth)
|
|
223
|
+
const fixedHeight = getFixedHeight(viewWidth, viewHeight, ratio)
|
|
224
|
+
setViewHeight(fixedHeight)
|
|
225
|
+
break
|
|
226
|
+
}
|
|
227
|
+
case 'heightFix': {
|
|
228
|
+
setViewHeight(viewHeight)
|
|
229
|
+
const fixedWidth = getFixedWidth(viewWidth, viewHeight, ratio)
|
|
230
|
+
setViewWidth(fixedWidth)
|
|
231
|
+
break
|
|
232
|
+
}
|
|
233
|
+
default:
|
|
234
|
+
setViewHeight(viewHeight)
|
|
235
|
+
setViewWidth(viewWidth)
|
|
236
|
+
break
|
|
237
|
+
}
|
|
238
|
+
}
|
|
199
239
|
|
|
200
240
|
const modeStyle: ImageStyle = useMemo(() => {
|
|
201
241
|
if (noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio)) return {}
|
|
202
242
|
switch (mode) {
|
|
203
|
-
case 'scaleToFill':
|
|
243
|
+
case 'scaleToFill': // wx 中 svg 图片的 scaleToFill 模式效果与 aspectFit 一致,不会就行图片缩放,此处保持一致
|
|
204
244
|
case 'aspectFit':
|
|
205
245
|
if (isSvg) {
|
|
206
|
-
const scale =
|
|
207
|
-
? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
|
|
208
|
-
: imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight
|
|
246
|
+
const scale = getFitScale(imageWidth, imageHeight, viewWidth, viewHeight)
|
|
209
247
|
return {
|
|
210
248
|
transform: [
|
|
211
|
-
{ scale },
|
|
212
|
-
|
|
249
|
+
{ translateY: relativeCenteredSize(viewHeight, imageHeight * scale) },
|
|
250
|
+
{ translateX: relativeCenteredSize(viewWidth, imageWidth * scale) },
|
|
251
|
+
{ scale }
|
|
213
252
|
]
|
|
214
253
|
}
|
|
215
254
|
}
|
|
216
255
|
return {}
|
|
217
256
|
case 'aspectFill':
|
|
218
257
|
if (isSvg) {
|
|
219
|
-
const scale =
|
|
220
|
-
? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
|
|
221
|
-
: imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight
|
|
258
|
+
const scale = getFillScale(imageWidth, imageHeight, viewWidth, viewHeight)
|
|
222
259
|
return {
|
|
223
260
|
transform: [
|
|
224
|
-
{ scale },
|
|
225
|
-
|
|
261
|
+
{ translateY: relativeCenteredSize(viewHeight, imageHeight * scale) },
|
|
262
|
+
{ translateX: relativeCenteredSize(viewWidth, imageWidth * scale) },
|
|
263
|
+
{ scale }
|
|
226
264
|
]
|
|
227
265
|
}
|
|
228
266
|
}
|
|
@@ -230,9 +268,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
230
268
|
case 'widthFix':
|
|
231
269
|
case 'heightFix':
|
|
232
270
|
if (isSvg) {
|
|
233
|
-
const scale =
|
|
234
|
-
? imageWidth >= fixedWidth ? fixedWidth / imageWidth : imageWidth / fixedWidth
|
|
235
|
-
: imageHeight >= fixedHeight ? fixedHeight / imageHeight : imageHeight / fixedHeight
|
|
271
|
+
const scale = getFitScale(imageWidth, imageHeight, viewWidth, viewHeight)
|
|
236
272
|
return {
|
|
237
273
|
transform: [{ scale }]
|
|
238
274
|
}
|
|
@@ -295,13 +331,25 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
295
331
|
default:
|
|
296
332
|
return {}
|
|
297
333
|
}
|
|
298
|
-
}, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio
|
|
334
|
+
}, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio])
|
|
299
335
|
|
|
300
336
|
const onSvgLoad = (evt: LayoutChangeEvent) => {
|
|
301
337
|
const { width, height } = evt.nativeEvent.layout
|
|
302
|
-
|
|
303
|
-
setImageWidth(width)
|
|
338
|
+
state.current.imageHeight = height
|
|
304
339
|
setImageHeight(height)
|
|
340
|
+
state.current.ratio = !width ? 0 : height / width
|
|
341
|
+
|
|
342
|
+
if (isWidthFixMode
|
|
343
|
+
? state.current.viewWidth
|
|
344
|
+
: isHeightFixMode
|
|
345
|
+
? state.current.viewHeight
|
|
346
|
+
: state.current.viewWidth && state.current.viewHeight) {
|
|
347
|
+
setRatio(state.current.ratio)
|
|
348
|
+
setImageWidth(width)
|
|
349
|
+
setImageHeight(height)
|
|
350
|
+
setViewSize(state.current.viewWidth!, state.current.viewHeight!, state.current.ratio)
|
|
351
|
+
setLoaded(true)
|
|
352
|
+
}
|
|
305
353
|
|
|
306
354
|
bindload && bindload(
|
|
307
355
|
getCustomEvent(
|
|
@@ -375,12 +423,11 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
375
423
|
: isHeightFixMode
|
|
376
424
|
? state.current.viewHeight
|
|
377
425
|
: state.current.viewWidth && state.current.viewHeight) {
|
|
378
|
-
|
|
379
|
-
state.current.viewHeight && setViewHeight(state.current.viewHeight)
|
|
380
|
-
setRatio(!width ? 0 : height / width)
|
|
426
|
+
setRatio(state.current.ratio)
|
|
381
427
|
setImageWidth(width)
|
|
382
428
|
setImageHeight(height)
|
|
383
|
-
state.current
|
|
429
|
+
setViewSize(state.current.viewWidth!, state.current.viewHeight!, state.current.ratio!)
|
|
430
|
+
|
|
384
431
|
setLoaded(true)
|
|
385
432
|
}
|
|
386
433
|
},
|
|
@@ -402,8 +449,8 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
402
449
|
{},
|
|
403
450
|
normalStyle,
|
|
404
451
|
layoutStyle,
|
|
405
|
-
isHeightFixMode ? { width:
|
|
406
|
-
isWidthFixMode ? { height:
|
|
452
|
+
isHeightFixMode ? { width: viewWidth } : {},
|
|
453
|
+
isWidthFixMode ? { height: viewHeight } : {}
|
|
407
454
|
)
|
|
408
455
|
}
|
|
409
456
|
),
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* ✔ selection-start
|
|
19
19
|
* ✔ selection-end
|
|
20
20
|
* ✔ adjust-position
|
|
21
|
-
*
|
|
21
|
+
* ✔ hold-keyboard
|
|
22
22
|
* ✘ safe-password-cert-path
|
|
23
23
|
* ✘ safe-password-length
|
|
24
24
|
* ✘ safe-password-time-stamp
|
|
@@ -102,6 +102,7 @@ export interface InputProps {
|
|
|
102
102
|
'parent-width'?: number
|
|
103
103
|
'parent-height'?: number
|
|
104
104
|
'adjust-position': boolean,
|
|
105
|
+
'hold-keyboard'?: boolean
|
|
105
106
|
bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
|
|
106
107
|
bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
|
|
107
108
|
bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
|
|
@@ -150,6 +151,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
150
151
|
'parent-width': parentWidth,
|
|
151
152
|
'parent-height': parentHeight,
|
|
152
153
|
'adjust-position': adjustPosition = true,
|
|
154
|
+
'hold-keyboard': holdKeyboard = false,
|
|
153
155
|
bindinput,
|
|
154
156
|
bindfocus,
|
|
155
157
|
bindblur,
|
|
@@ -198,7 +200,12 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
198
200
|
{ padding: 0, backgroundColor: '#fff' },
|
|
199
201
|
style,
|
|
200
202
|
multiline && autoHeight
|
|
201
|
-
?
|
|
203
|
+
? extendObject(
|
|
204
|
+
{ height: 'auto' },
|
|
205
|
+
(style as any)?.minHeight
|
|
206
|
+
? { minHeight: (style as any)?.minHeight } // 用户设置了 minHeight 才会透传
|
|
207
|
+
: {}
|
|
208
|
+
)
|
|
202
209
|
: {}
|
|
203
210
|
)
|
|
204
211
|
|
|
@@ -280,8 +287,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
280
287
|
}
|
|
281
288
|
|
|
282
289
|
const setKeyboardAvoidContext = () => {
|
|
283
|
-
if (
|
|
284
|
-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef }
|
|
290
|
+
if (keyboardAvoid) {
|
|
291
|
+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition, holdKeyboard }
|
|
285
292
|
}
|
|
286
293
|
}
|
|
287
294
|
|
|
@@ -295,20 +302,45 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
295
302
|
}
|
|
296
303
|
|
|
297
304
|
const onFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
305
|
+
if (!keyboardAvoid?.current) {
|
|
306
|
+
setKeyboardAvoidContext()
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (bindfocus) {
|
|
310
|
+
const focusAction = () => {
|
|
311
|
+
bindfocus(
|
|
312
|
+
getCustomEvent(
|
|
313
|
+
'focus',
|
|
314
|
+
evt,
|
|
315
|
+
{
|
|
316
|
+
detail: {
|
|
317
|
+
value: tmpValue.current || '',
|
|
318
|
+
height: keyboardAvoid?.current?.keyboardHeight
|
|
319
|
+
},
|
|
320
|
+
layoutRef
|
|
321
|
+
},
|
|
322
|
+
props
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
if (keyboardAvoid?.current?.onKeyboardShow) {
|
|
326
|
+
keyboardAvoid.current.onKeyboardShow = undefined
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (keyboardAvoid?.current) {
|
|
330
|
+
// 有 keyboardAvoiding
|
|
331
|
+
if (keyboardAvoid.current.keyboardHeight) {
|
|
332
|
+
// iOS: keyboard 获取高度时机 keyboardWillShow 在 input focus 之前,可以立即执行
|
|
333
|
+
focusAction()
|
|
334
|
+
} else {
|
|
335
|
+
// Android,Harmony: keyboard 获取高度时机 keyboardDidShow 在 input focus 之后,需要延迟回调
|
|
336
|
+
evt.persist()
|
|
337
|
+
keyboardAvoid.current.onKeyboardShow = focusAction
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
// 无 keyboardAvoiding,直接执行 focus 回调
|
|
341
|
+
focusAction()
|
|
342
|
+
}
|
|
343
|
+
}
|
|
312
344
|
}
|
|
313
345
|
|
|
314
346
|
const onBlur = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|