@mpxjs/webpack-plugin 2.10.15-prelease.1 → 2.10.16-beta.10
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/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/file-loader.js +13 -3
- package/lib/helpers.js +2 -0
- package/lib/index.js +40 -15
- 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 +8 -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/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 +37 -11
- 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-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-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 +1 -1
- 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 +44 -17
- 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-scroll-view.tsx +6 -17
- 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 +1 -1
- 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 +0 -14
- 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 +267 -71
- 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/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 +1 -1
- package/lib/wxss/loader.js +1 -9
- package/package.json +15 -4
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ReactNode, ReactElement, Dispatch, SetStateAction, MutableRefObject } from 'react';
|
|
2
|
+
import { LayoutChangeEvent, TextStyle, ImageProps } from 'react-native';
|
|
3
|
+
import { FastImageProps } from '@d11/react-native-fast-image';
|
|
4
|
+
import type { AnyFunc } from './types/common';
|
|
5
|
+
export declare const TEXT_STYLE_REGEX: RegExp;
|
|
6
|
+
export declare const PERCENT_REGEX: RegExp;
|
|
7
|
+
export declare const URL_REGEX: RegExp;
|
|
8
|
+
export declare const SVG_REGEXP: RegExp;
|
|
9
|
+
export declare const BACKGROUND_REGEX: RegExp;
|
|
10
|
+
export declare const TEXT_PROPS_REGEX: RegExp;
|
|
11
|
+
export declare const DEFAULT_FONT_SIZE = 16;
|
|
12
|
+
export declare const HIDDEN_STYLE: {
|
|
13
|
+
opacity: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const isIOS: boolean;
|
|
16
|
+
export declare const isAndroid: boolean;
|
|
17
|
+
export declare const isHarmony: boolean;
|
|
18
|
+
export declare function useNavigation(): Record<string, any> | undefined;
|
|
19
|
+
export declare function omit<T, K extends string>(obj: T, fields: K[]): Omit<T, K>;
|
|
20
|
+
/**
|
|
21
|
+
* 用法等同于 useEffect,但是会忽略首次执行,只在依赖更新时执行
|
|
22
|
+
*/
|
|
23
|
+
export declare const useUpdateEffect: (effect: any, deps: any) => void;
|
|
24
|
+
export declare const parseUrl: (cssUrl?: string) => string | undefined;
|
|
25
|
+
export declare const getRestProps: (transferProps?: any, originProps?: any, deletePropsKey?: any) => any;
|
|
26
|
+
export declare function isText(ele: ReactNode): ele is ReactElement;
|
|
27
|
+
export declare function every(children: ReactNode, callback: (children: ReactNode) => boolean): boolean;
|
|
28
|
+
type GroupData<T> = Record<string, Partial<T>>;
|
|
29
|
+
export declare function groupBy<T extends Record<string, any>>(obj: T, callback: (key: string, val: T[keyof T]) => string, group?: GroupData<T>): GroupData<T>;
|
|
30
|
+
export declare function splitStyle<T extends Record<string, any>>(styleObj: T): {
|
|
31
|
+
textStyle?: Partial<T>;
|
|
32
|
+
backgroundStyle?: Partial<T>;
|
|
33
|
+
innerStyle?: Partial<T>;
|
|
34
|
+
};
|
|
35
|
+
interface TransformStyleConfig {
|
|
36
|
+
enableVar?: boolean;
|
|
37
|
+
externalVarContext?: Record<string, any>;
|
|
38
|
+
parentFontSize?: number;
|
|
39
|
+
parentWidth?: number;
|
|
40
|
+
parentHeight?: number;
|
|
41
|
+
}
|
|
42
|
+
export declare function useTransformStyle(styleObj: Record<string, any> | undefined, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig): {
|
|
43
|
+
hasVarDec: boolean;
|
|
44
|
+
varContextRef: MutableRefObject<{}>;
|
|
45
|
+
setWidth: Dispatch<SetStateAction<number>>;
|
|
46
|
+
setHeight: Dispatch<SetStateAction<number>>;
|
|
47
|
+
normalStyle: Record<string, any>;
|
|
48
|
+
hasSelfPercent: boolean;
|
|
49
|
+
hasPositionFixed: boolean;
|
|
50
|
+
};
|
|
51
|
+
export interface VisitorArg {
|
|
52
|
+
target: Record<string, any>;
|
|
53
|
+
key: string;
|
|
54
|
+
value: any;
|
|
55
|
+
keyPath: Array<string>;
|
|
56
|
+
}
|
|
57
|
+
export declare function traverseStyle(styleObj: Record<string, any>, visitors: Array<(arg: VisitorArg) => void>): void;
|
|
58
|
+
export declare function setStyle(styleObj: Record<string, any>, keyPath: Array<string>, setter: (arg: VisitorArg) => void): void;
|
|
59
|
+
export declare function splitProps<T extends Record<string, any>>(props: T): {
|
|
60
|
+
textProps?: Partial<T>;
|
|
61
|
+
innerProps?: Partial<T>;
|
|
62
|
+
};
|
|
63
|
+
interface LayoutConfig {
|
|
64
|
+
props: Record<string, any>;
|
|
65
|
+
hasSelfPercent: boolean;
|
|
66
|
+
setWidth?: Dispatch<SetStateAction<number>>;
|
|
67
|
+
setHeight?: Dispatch<SetStateAction<number>>;
|
|
68
|
+
onLayout?: (event?: LayoutChangeEvent) => void;
|
|
69
|
+
nodeRef: React.RefObject<any>;
|
|
70
|
+
}
|
|
71
|
+
export declare const useLayout: ({ props, hasSelfPercent, setWidth, setHeight, onLayout, nodeRef }: LayoutConfig) => {
|
|
72
|
+
layoutRef: MutableRefObject<{}>;
|
|
73
|
+
layoutStyle: {};
|
|
74
|
+
layoutProps: Record<string, any>;
|
|
75
|
+
};
|
|
76
|
+
export interface WrapChildrenConfig {
|
|
77
|
+
hasVarDec: boolean;
|
|
78
|
+
varContext?: Record<string, any>;
|
|
79
|
+
textStyle?: TextStyle;
|
|
80
|
+
textProps?: Record<string, any>;
|
|
81
|
+
}
|
|
82
|
+
export declare function wrapChildren(props: Record<string, any> | undefined, { hasVarDec, varContext, textStyle, textProps }: WrapChildrenConfig): any;
|
|
83
|
+
export declare const debounce: <T extends AnyFunc>(func: T, delay: number) => ((...args: Parameters<T>) => void) & {
|
|
84
|
+
clear: () => void;
|
|
85
|
+
};
|
|
86
|
+
export declare const useDebounceCallback: <T extends AnyFunc>(func: T, delay: number) => ((...args: Parameters<T>) => void) & {
|
|
87
|
+
clear: () => void;
|
|
88
|
+
};
|
|
89
|
+
export declare const useStableCallback: <T extends AnyFunc | null | undefined>(callback: T) => T extends AnyFunc ? T : () => void;
|
|
90
|
+
export declare function usePrevious<T>(value: T): T | undefined;
|
|
91
|
+
export interface GestureHandler {
|
|
92
|
+
nodeRefs?: Array<{
|
|
93
|
+
getNodeInstance: () => {
|
|
94
|
+
nodeRef: unknown;
|
|
95
|
+
};
|
|
96
|
+
}>;
|
|
97
|
+
current?: unknown;
|
|
98
|
+
}
|
|
99
|
+
export declare function flatGesture(gestures?: Array<GestureHandler>): any[];
|
|
100
|
+
export declare const extendObject: {
|
|
101
|
+
<T extends {}, U>(target: T, source: U): T & U;
|
|
102
|
+
<T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
|
|
103
|
+
<T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
|
|
104
|
+
(target: object, ...sources: any[]): any;
|
|
105
|
+
};
|
|
106
|
+
export declare function getCurrentPage(pageId: number | null | undefined): any;
|
|
107
|
+
export declare function renderImage(imageProps: ImageProps | FastImageProps, enableFastImage?: boolean): ReactElement<ImageProps | FastImageProps, string | import("react").JSXElementConstructor<any>>;
|
|
108
|
+
export declare function pickStyle(styleObj: Record<string, any> | undefined, pickedKeys: Array<string>, callback?: (key: string, val: number | string) => number | string): Record<string, any>;
|
|
109
|
+
export declare function useHover({ enableHover, hoverStartTime, hoverStayTime, disabled }: {
|
|
110
|
+
enableHover: boolean;
|
|
111
|
+
hoverStartTime: number;
|
|
112
|
+
hoverStayTime: number;
|
|
113
|
+
disabled?: boolean;
|
|
114
|
+
}): {
|
|
115
|
+
isHover: boolean;
|
|
116
|
+
gesture?: undefined;
|
|
117
|
+
} | {
|
|
118
|
+
isHover: boolean;
|
|
119
|
+
gesture: import("react-native-gesture-handler/lib/typescript/handlers/gestures/panGesture").PanGesture;
|
|
120
|
+
};
|
|
121
|
+
export declare function useRunOnJSCallback(callbackMapRef: MutableRefObject<Record<string, AnyFunc>>): (key: string, ...args: any) => any;
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA2C,SAAS,EAAE,YAAY,EAAwC,QAAQ,EAAE,cAAc,EAAyC,gBAAgB,EAAE,MAAM,OAAO,CAAA;AACjN,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAS,MAAM,cAAc,CAAA;AAK9E,OAAkB,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,KAAK,EAAE,OAAO,EAA6B,MAAM,gBAAgB,CAAA;AAIxE,eAAO,MAAM,gBAAgB,QAAqF,CAAA;AAClH,eAAO,MAAM,aAAa,QAA2B,CAAA;AACrD,eAAO,MAAM,SAAS,QAAmC,CAAA;AACzD,eAAO,MAAM,UAAU,QAA4B,CAAA;AACnD,eAAO,MAAM,gBAAgB,QAA6C,CAAA;AAC1E,eAAO,MAAM,gBAAgB,QAAiD,CAAA;AAC9E,eAAO,MAAM,iBAAiB,KAAK,CAAA;AACnC,eAAO,MAAM,YAAY;;CAExB,CAAA;AAID,eAAO,MAAM,KAAK,SAAyB,CAAA;AAC3C,eAAO,MAAM,SAAS,SAA6B,CAAA;AACnD,eAAO,MAAM,SAAS,SAA6B,CAAA;AAsBnD,wBAAgB,aAAa,IAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAGhE;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAG,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,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SAAS,OAIhE;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,UAAU,GAAG,cAAc,EACvC,eAAe,UAAQ,kGAIxB;AAED,wBAAgB,SAAS,CAAE,QAAQ,iCAA0B,EAAE,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,GAAG,MAAM,uBAO1J;AAED,wBAAgB,QAAQ,CAAE,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE;IAAE,WAAW,EAAE,OAAO,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE;;;;;;EA4D9K;AAED,wBAAgB,kBAAkB,CAAE,cAAc,EAAE,gBAAgB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,SAClD,MAAM,WAAW,GAAG,SAa9D"}
|
|
@@ -169,24 +169,34 @@ function transformPercent(styleObj, percentKeyPaths, percentConfig) {
|
|
|
169
169
|
function resolveVar(input, varContext) {
|
|
170
170
|
const parsed = parseFunc(input, 'var');
|
|
171
171
|
const replaced = new ReplaceSource(input);
|
|
172
|
-
|
|
172
|
+
for (const { start, end, args } of parsed) {
|
|
173
173
|
const varName = args[0];
|
|
174
|
-
const fallback = args[1]
|
|
174
|
+
const fallback = args[1];
|
|
175
175
|
let varValue = hasOwn(varContext, varName) ? varContext[varName] : fallback;
|
|
176
|
+
if (varValue === undefined)
|
|
177
|
+
return;
|
|
176
178
|
if (varUseRegExp.test(varValue)) {
|
|
177
|
-
varValue =
|
|
179
|
+
varValue = resolveVar(varValue, varContext);
|
|
180
|
+
if (varValue === undefined)
|
|
181
|
+
return;
|
|
178
182
|
}
|
|
179
183
|
else {
|
|
180
|
-
varValue =
|
|
184
|
+
varValue = global.__formatValue(varValue);
|
|
181
185
|
}
|
|
182
186
|
replaced.replace(start, end - 1, varValue);
|
|
183
|
-
}
|
|
187
|
+
}
|
|
184
188
|
return global.__formatValue(replaced.source());
|
|
185
189
|
}
|
|
186
190
|
function transformVar(styleObj, varKeyPaths, varContext, visitOther) {
|
|
187
191
|
varKeyPaths.forEach((varKeyPath) => {
|
|
188
192
|
setStyle(styleObj, varKeyPath, ({ target, key, value }) => {
|
|
189
|
-
|
|
193
|
+
const resolved = resolveVar(value, varContext);
|
|
194
|
+
if (resolved === undefined) {
|
|
195
|
+
delete target[key];
|
|
196
|
+
error(`Can not resolve css var at ${varKeyPath.join('.')}:${value}.`);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
target[key] = resolved;
|
|
190
200
|
visitOther({ target, key, value: target[key], keyPath: varKeyPath });
|
|
191
201
|
});
|
|
192
202
|
});
|
|
@@ -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
|
),
|