@mpxjs/webpack-plugin 2.10.17 → 2.10.18-beta.1
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/file-loader.js +4 -1
- package/lib/global.d.ts +231 -0
- package/lib/index.js +70 -73
- package/lib/init.js +3 -0
- package/lib/json-compiler/index.js +13 -4
- package/lib/loader.js +4 -0
- package/lib/platform/json/wx/index.js +6 -0
- package/lib/platform/style/wx/index.js +102 -72
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +10 -3
- 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/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- 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/LoadAsyncChunkModule.js +1 -1
- package/lib/react/processStyles.js +21 -9
- package/lib/react/script-helper.js +2 -2
- package/lib/react/style-helper.js +76 -13
- package/lib/resolver/AddModePlugin.js +17 -7
- package/lib/resolver/ExtendComponentsPlugin.js +60 -0
- package/lib/runtime/components/ali/mpx-section-list.mpx +566 -0
- package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
- package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
- package/lib/runtime/components/react/animationHooks/index.ts +75 -0
- package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
- package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
- package/lib/runtime/components/react/context.ts +12 -3
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
- package/lib/runtime/components/react/dist/context.d.ts +10 -3
- package/lib/runtime/components/react/dist/context.js +1 -2
- package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
- package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
- package/lib/runtime/components/react/dist/mpx-section-list.d.ts +48 -0
- package/lib/runtime/components/react/dist/mpx-section-list.jsx +292 -0
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +11 -1
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +136 -83
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
- package/lib/runtime/components/react/dist/parser.d.ts +0 -1
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts +10 -9
- package/lib/runtime/components/react/dist/utils.jsx +47 -24
- package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-image.tsx +2 -2
- package/lib/runtime/components/react/mpx-input.tsx +77 -54
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
- package/lib/runtime/components/react/mpx-section-list.tsx +439 -0
- package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
- package/lib/runtime/components/react/mpx-swiper.tsx +156 -81
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
- package/lib/runtime/components/react/mpx-view.tsx +27 -12
- package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
- package/lib/runtime/components/react/tsconfig.json +26 -0
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +51 -27
- package/lib/runtime/components/web/mpx-scroll-view.vue +5 -2
- package/lib/runtime/components/web/mpx-section-list.vue +551 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +26 -0
- package/lib/runtime/components/wx/mpx-section-list.mpx +209 -0
- package/lib/runtime/components/wx/mpx-sticky-header.mpx +40 -0
- package/lib/runtime/components/wx/mpx-sticky-section.mpx +31 -0
- package/lib/runtime/optionProcessor.js +5 -0
- package/lib/runtime/optionProcessorReact.js +7 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/script-setup-compiler/index.js +1 -2
- package/lib/style-compiler/strip-conditional.js +243 -0
- package/lib/template-compiler/compiler.js +9 -8
- package/lib/utils/const.js +29 -0
- package/lib/utils/dom-tag-config.js +1 -1
- package/lib/utils/string.js +25 -1
- package/lib/wxss/loader.js +4 -1
- package/lib/wxss/utils.js +7 -2
- package/package.json +7 -14
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
- package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
- package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
- package/lib/style-compiler/strip-conditional-loader.js +0 -289
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode, ReactElement, Dispatch, SetStateAction, MutableRefObject } from 'react';
|
|
2
2
|
import { LayoutChangeEvent, TextStyle, ImageProps } from 'react-native';
|
|
3
|
-
import { FastImageProps } from '@d11/react-native-fast-image';
|
|
3
|
+
import type { FastImageProps } from '@d11/react-native-fast-image';
|
|
4
4
|
import type { AnyFunc } from './types/common';
|
|
5
5
|
export declare const TEXT_STYLE_REGEX: RegExp;
|
|
6
6
|
export declare const PERCENT_REGEX: RegExp;
|
|
@@ -15,6 +15,12 @@ export declare const HIDDEN_STYLE: {
|
|
|
15
15
|
export declare const isIOS: boolean;
|
|
16
16
|
export declare const isAndroid: boolean;
|
|
17
17
|
export declare const isHarmony: boolean;
|
|
18
|
+
export declare const extendObject: {
|
|
19
|
+
<T extends {}, U>(target: T, source: U): T & U;
|
|
20
|
+
<T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
|
|
21
|
+
<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;
|
|
22
|
+
(target: object, ...sources: any[]): any;
|
|
23
|
+
};
|
|
18
24
|
export declare function useNavigation(): Record<string, any> | undefined;
|
|
19
25
|
export declare function omit<T, K extends string>(obj: T, fields: K[]): Omit<T, K>;
|
|
20
26
|
/**
|
|
@@ -32,14 +38,16 @@ export declare function splitStyle<T extends Record<string, any>>(styleObj: T):
|
|
|
32
38
|
backgroundStyle?: Partial<T>;
|
|
33
39
|
innerStyle?: Partial<T>;
|
|
34
40
|
};
|
|
41
|
+
export declare function parseValues(str: string, char?: string): string[];
|
|
35
42
|
interface TransformStyleConfig {
|
|
36
43
|
enableVar?: boolean;
|
|
37
44
|
externalVarContext?: Record<string, any>;
|
|
38
45
|
parentFontSize?: number;
|
|
39
46
|
parentWidth?: number;
|
|
40
47
|
parentHeight?: number;
|
|
48
|
+
transformRadiusPercent?: boolean;
|
|
41
49
|
}
|
|
42
|
-
export declare function useTransformStyle(styleObj: Record<string, any> | undefined, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig): {
|
|
50
|
+
export declare function useTransformStyle(styleObj: Record<string, any> | undefined, { enableVar, transformRadiusPercent, externalVarContext, parentFontSize, parentWidth, parentHeight }: TransformStyleConfig): {
|
|
43
51
|
hasVarDec: boolean;
|
|
44
52
|
varContextRef: MutableRefObject<{}>;
|
|
45
53
|
setWidth: Dispatch<SetStateAction<number>>;
|
|
@@ -97,12 +105,6 @@ export interface GestureHandler {
|
|
|
97
105
|
current?: unknown;
|
|
98
106
|
}
|
|
99
107
|
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
108
|
export declare function getCurrentPage(pageId: number | null | undefined): any;
|
|
107
109
|
export declare function renderImage(imageProps: ImageProps | FastImageProps, enableFastImage?: boolean): ReactElement<ImageProps | FastImageProps, string | import("react").JSXElementConstructor<any>>;
|
|
108
110
|
export declare function pickStyle(styleObj: Record<string, any> | undefined, pickedKeys: Array<string>, callback?: (key: string, val: number | string) => number | string): Record<string, any>;
|
|
@@ -120,4 +122,3 @@ export declare function useHover({ enableHover, hoverStartTime, hoverStayTime, d
|
|
|
120
122
|
};
|
|
121
123
|
export declare function useRunOnJSCallback(callbackMapRef: MutableRefObject<Record<string, AnyFunc>>): (key: string, ...args: any) => any;
|
|
122
124
|
export {};
|
|
123
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -4,7 +4,6 @@ import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } fr
|
|
|
4
4
|
import { VarContext, ScrollViewContext, RouteContext } from './context';
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser';
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
7
|
-
import FastImage from '@d11/react-native-fast-image';
|
|
8
7
|
import { Gesture } from 'react-native-gesture-handler';
|
|
9
8
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
|
|
10
9
|
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
|
|
@@ -24,6 +23,7 @@ const varUseRegExp = /var\(/;
|
|
|
24
23
|
const unoVarDecRegExp = /^--un-/;
|
|
25
24
|
const unoVarUseRegExp = /var\(--un-/;
|
|
26
25
|
const calcUseRegExp = /calc\(/;
|
|
26
|
+
const calcPercentExp = /^calc\(.*-?\d+(\.\d+)?%.*\)$/;
|
|
27
27
|
const envUseRegExp = /env\(/;
|
|
28
28
|
const filterRegExp = /(calc|env|%)/;
|
|
29
29
|
const safeAreaInsetMap = {
|
|
@@ -32,6 +32,7 @@ const safeAreaInsetMap = {
|
|
|
32
32
|
'safe-area-inset-bottom': 'bottom',
|
|
33
33
|
'safe-area-inset-left': 'left'
|
|
34
34
|
};
|
|
35
|
+
export const extendObject = Object.assign;
|
|
35
36
|
function getSafeAreaInset(name, navigation) {
|
|
36
37
|
const insets = extendObject({}, initialWindowMetrics?.insets, navigation?.insets);
|
|
37
38
|
return insets[safeAreaInsetMap[name]];
|
|
@@ -110,15 +111,17 @@ export function splitStyle(styleObj) {
|
|
|
110
111
|
}
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
|
-
const
|
|
114
|
-
translateX: 'width',
|
|
115
|
-
translateY: 'height',
|
|
114
|
+
const radiusPercentRule = {
|
|
116
115
|
borderTopLeftRadius: 'width',
|
|
117
116
|
borderBottomLeftRadius: 'width',
|
|
118
117
|
borderBottomRightRadius: 'width',
|
|
119
118
|
borderTopRightRadius: 'width',
|
|
120
119
|
borderRadius: 'width'
|
|
121
120
|
};
|
|
121
|
+
const selfPercentRule = extendObject({
|
|
122
|
+
translateX: 'width',
|
|
123
|
+
translateY: 'height'
|
|
124
|
+
}, radiusPercentRule);
|
|
122
125
|
const parentHeightPercentRule = {
|
|
123
126
|
height: true,
|
|
124
127
|
minHeight: true,
|
|
@@ -170,19 +173,22 @@ function resolveVar(input, varContext) {
|
|
|
170
173
|
const parsed = parseFunc(input, 'var');
|
|
171
174
|
const replaced = new ReplaceSource(input);
|
|
172
175
|
for (const { start, end, args } of parsed) {
|
|
176
|
+
// NOTE:
|
|
177
|
+
// - CSS var() fallback 允许包含空格、逗号等字符(如 font-family 的 fallback)
|
|
178
|
+
// - parseFunc 会按逗号分割 args,因此这里把 args[1..] 重新 join 回 fallback
|
|
173
179
|
const varName = args[0];
|
|
174
|
-
const fallback = args
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
varValue = resolveVar(varValue, varContext);
|
|
180
|
-
if (varValue === undefined)
|
|
181
|
-
return;
|
|
180
|
+
const fallback = args.length > 1 ? args.slice(1).join(',').trim() : undefined;
|
|
181
|
+
// 先处理 varValue
|
|
182
|
+
let varValue = hasOwn(varContext, varName) ? varContext[varName] : undefined;
|
|
183
|
+
if (varValue !== undefined) {
|
|
184
|
+
varValue = varUseRegExp.test(varValue) ? resolveVar(varValue, varContext) : global.__formatValue(varValue);
|
|
182
185
|
}
|
|
183
|
-
|
|
184
|
-
|
|
186
|
+
// 再处理 fallback
|
|
187
|
+
if (varValue === undefined && fallback !== undefined) {
|
|
188
|
+
varValue = varUseRegExp.test(fallback) ? resolveVar(fallback, varContext) : global.__formatValue(fallback);
|
|
185
189
|
}
|
|
190
|
+
if (varValue === undefined)
|
|
191
|
+
return;
|
|
186
192
|
replaced.replace(start, end - 1, varValue);
|
|
187
193
|
}
|
|
188
194
|
return global.__formatValue(replaced.source());
|
|
@@ -241,6 +247,10 @@ function transformStringify(styleObj) {
|
|
|
241
247
|
if (isNumber(styleObj.fontWeight)) {
|
|
242
248
|
styleObj.fontWeight = '' + styleObj.fontWeight;
|
|
243
249
|
}
|
|
250
|
+
// transformOrigin 20px 需要转换为 transformOrigin '20'
|
|
251
|
+
if (isNumber(styleObj.transformOrigin)) {
|
|
252
|
+
styleObj.transformOrigin = '' + styleObj.transformOrigin;
|
|
253
|
+
}
|
|
244
254
|
}
|
|
245
255
|
function transformPosition(styleObj, meta) {
|
|
246
256
|
if (styleObj.position === 'fixed') {
|
|
@@ -249,7 +259,7 @@ function transformPosition(styleObj, meta) {
|
|
|
249
259
|
}
|
|
250
260
|
}
|
|
251
261
|
// 多value解析
|
|
252
|
-
function parseValues(str, char = ' ') {
|
|
262
|
+
export function parseValues(str, char = ' ') {
|
|
253
263
|
let stack = 0;
|
|
254
264
|
let temp = '';
|
|
255
265
|
const result = [];
|
|
@@ -261,11 +271,11 @@ function parseValues(str, char = ' ') {
|
|
|
261
271
|
stack--;
|
|
262
272
|
}
|
|
263
273
|
// 非括号内 或者 非分隔字符且非空
|
|
264
|
-
if (stack !== 0 ||
|
|
274
|
+
if (stack !== 0 || str[i] !== char) {
|
|
265
275
|
temp += str[i];
|
|
266
276
|
}
|
|
267
277
|
if ((stack === 0 && str[i] === char) || i === str.length - 1) {
|
|
268
|
-
result.push(temp);
|
|
278
|
+
result.push(temp.trim());
|
|
269
279
|
temp = '';
|
|
270
280
|
}
|
|
271
281
|
}
|
|
@@ -274,6 +284,8 @@ function parseValues(str, char = ' ') {
|
|
|
274
284
|
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
|
|
275
285
|
function parseTransform(transformStr) {
|
|
276
286
|
const values = parseValues(transformStr);
|
|
287
|
+
// Todo transform 排序不一致时,transform动画会闪烁,故这里同样的排序输出 transform
|
|
288
|
+
values.sort();
|
|
277
289
|
const transform = [];
|
|
278
290
|
values.forEach(item => {
|
|
279
291
|
const match = item.match(/([/\w]+)\((.+)\)/);
|
|
@@ -337,7 +349,7 @@ function transformBoxShadow(styleObj) {
|
|
|
337
349
|
return `${res}${idx === 0 ? '' : ' '}${global.__formatValue(i)}`;
|
|
338
350
|
}, '');
|
|
339
351
|
}
|
|
340
|
-
export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
352
|
+
export function useTransformStyle(styleObj = {}, { enableVar, transformRadiusPercent, externalVarContext, parentFontSize, parentWidth, parentHeight }) {
|
|
341
353
|
const varStyle = {};
|
|
342
354
|
const unoVarStyle = {};
|
|
343
355
|
const normalStyle = {};
|
|
@@ -386,13 +398,20 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
386
398
|
envKeyPaths.push(keyPath.slice());
|
|
387
399
|
}
|
|
388
400
|
}
|
|
389
|
-
function calcVisitor({ value, keyPath }) {
|
|
401
|
+
function calcVisitor({ key, value, keyPath }) {
|
|
390
402
|
if (calcUseRegExp.test(value)) {
|
|
403
|
+
// calc translate & border-radius 的百分比计算
|
|
404
|
+
if (hasOwn(selfPercentRule, key) && calcPercentExp.test(value)) {
|
|
405
|
+
hasSelfPercent = true;
|
|
406
|
+
percentKeyPaths.push(keyPath.slice());
|
|
407
|
+
}
|
|
391
408
|
calcKeyPaths.push(keyPath.slice());
|
|
392
409
|
}
|
|
393
410
|
}
|
|
394
411
|
function percentVisitor({ key, value, keyPath }) {
|
|
395
|
-
|
|
412
|
+
// fixme 去掉 translate & border-radius 的百分比计算
|
|
413
|
+
// fixme Image 组件 borderRadius 仅支持 number
|
|
414
|
+
if (transformRadiusPercent && hasOwn(radiusPercentRule, key) && PERCENT_REGEX.test(value)) {
|
|
396
415
|
hasSelfPercent = true;
|
|
397
416
|
percentKeyPaths.push(keyPath.slice());
|
|
398
417
|
}
|
|
@@ -467,7 +486,7 @@ export function useTransformStyle(styleObj = {}, { enableVar, externalVarContext
|
|
|
467
486
|
transformStringify(normalStyle);
|
|
468
487
|
// transform rpx to px
|
|
469
488
|
transformBoxShadow(normalStyle);
|
|
470
|
-
// transform 字符串格式转化数组格式
|
|
489
|
+
// transform 字符串格式转化数组格式(先转数组再处理css var)
|
|
471
490
|
transformTransform(normalStyle);
|
|
472
491
|
return {
|
|
473
492
|
hasVarDec,
|
|
@@ -612,15 +631,19 @@ export function flatGesture(gestures = []) {
|
|
|
612
631
|
return gesture?.current ? [gesture] : [];
|
|
613
632
|
})) || [];
|
|
614
633
|
}
|
|
615
|
-
export const extendObject = Object.assign;
|
|
616
634
|
export function getCurrentPage(pageId) {
|
|
617
635
|
if (!global.getCurrentPages)
|
|
618
636
|
return;
|
|
619
637
|
const pages = global.getCurrentPages();
|
|
620
638
|
return pages.find((page) => isFunction(page.getPageId) && page.getPageId() === pageId);
|
|
621
639
|
}
|
|
622
|
-
export function renderImage(imageProps, enableFastImage =
|
|
623
|
-
|
|
640
|
+
export function renderImage(imageProps, enableFastImage = true) {
|
|
641
|
+
let Component = Image;
|
|
642
|
+
if (enableFastImage) {
|
|
643
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
644
|
+
const fastImageModule = require('@d11/react-native-fast-image');
|
|
645
|
+
Component = fastImageModule.default || fastImageModule;
|
|
646
|
+
}
|
|
624
647
|
return createElement(Component, imageProps);
|
|
625
648
|
}
|
|
626
649
|
export function pickStyle(styleObj = {}, pickedKeys, callback) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useState, ComponentType, useEffect, useCallback, useRef, ReactNode, createElement } from 'react'
|
|
2
2
|
import { View, Image, StyleSheet, Text, TouchableOpacity } from 'react-native'
|
|
3
|
-
import FastImage from '@d11/react-native-fast-image'
|
|
4
3
|
import { AnyFunc } from './types/common'
|
|
5
4
|
|
|
6
5
|
const asyncChunkMap = new Map()
|
|
@@ -82,6 +81,9 @@ const DefaultFallback = ({ onReload }: DefaultFallbackProps) => {
|
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
const DefaultLoading = () => {
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
85
|
+
const FastImageModule = require('@d11/react-native-fast-image')
|
|
86
|
+
const FastImage = FastImageModule.default || FastImageModule
|
|
85
87
|
return (
|
|
86
88
|
<View style={styles.container}>
|
|
87
89
|
<FastImage
|
|
@@ -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
|
|
@@ -26,7 +26,7 @@ import { noop } from '@mpxjs/utils'
|
|
|
26
26
|
import { SvgCssUri } from 'react-native-svg/css'
|
|
27
27
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
28
28
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
29
|
-
import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject } from './utils'
|
|
29
|
+
import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject, isAndroid } from './utils'
|
|
30
30
|
import Portal from './mpx-portal'
|
|
31
31
|
|
|
32
32
|
export type Mode =
|
|
@@ -190,7 +190,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
190
190
|
normalStyle,
|
|
191
191
|
setWidth,
|
|
192
192
|
setHeight
|
|
193
|
-
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
193
|
+
} = useTransformStyle(styleObj, { enableVar, transformRadiusPercent: isAndroid && !isSvg && !isLayoutMode, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
194
194
|
|
|
195
195
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({
|
|
196
196
|
props,
|