@mpxjs/webpack-plugin 2.10.16 → 2.10.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- 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 +14 -54
- 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 +24 -29
- package/lib/platform/style/wx/index.js +8 -1
- package/lib/platform/template/wx/component-config/button.js +12 -3
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- 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 +12 -6
- package/lib/runtime/components/react/dist/context.d.ts +75 -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-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/index.jsx +1 -1
- 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 +107 -57
- 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 +50 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts.map +1 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +32 -8
- 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 +58 -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-rich-text/index.jsx +1 -1
- 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-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 +10 -2
- 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-canvas/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-image.tsx +130 -77
- package/lib/runtime/components/react/mpx-input.tsx +38 -15
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +66 -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-rich-text/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +6 -17
- 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 +13 -4
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/utils.tsx +15 -6
- 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 +177 -15
- package/lib/template-compiler/compiler.js +268 -70
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +6 -4
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +2 -1
- package/lib/utils/dom-tag-config.js +5 -5
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -0
- package/lib/utils/merge-visitors.js +55 -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 +9 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +15 -5
- package/lib/utils/chain-assign.js +0 -47
|
@@ -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,wB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A;CAClB;AAED,wBAAgB,WAAW,CAAE,QAAQ,GAAE,KAAK,CAAC,cAAc,CAAM,SAQhE;AAED,eAAO,MAAM,YAAY;;;;;CAAgB,CAAA;AAEzC,wBAAgB,cAAc,CAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,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
|
});
|
|
@@ -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
|
),
|
|
@@ -417,44 +464,50 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
417
464
|
}
|
|
418
465
|
)
|
|
419
466
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
{ transformOrigin: 'left top' },
|
|
429
|
-
modeStyle
|
|
430
|
-
)
|
|
431
|
-
})
|
|
432
|
-
)
|
|
433
|
-
|
|
434
|
-
const BaseImage = renderImage(
|
|
435
|
-
extendObject(
|
|
436
|
-
{
|
|
437
|
-
source: { uri: src },
|
|
438
|
-
resizeMode: resizeMode,
|
|
439
|
-
onLoad: bindload && onImageLoad,
|
|
440
|
-
onError: binderror && onImageError,
|
|
467
|
+
function renderSvgImage () {
|
|
468
|
+
return createElement(
|
|
469
|
+
View,
|
|
470
|
+
innerProps,
|
|
471
|
+
createElement(SvgCssUri, {
|
|
472
|
+
uri: src,
|
|
473
|
+
onLayout: onSvgLoad,
|
|
474
|
+
onError: binderror && onSvgError,
|
|
441
475
|
style: extendObject(
|
|
442
|
-
{
|
|
443
|
-
|
|
444
|
-
width: isCropMode ? imageWidth : '100%',
|
|
445
|
-
height: isCropMode ? imageHeight : '100%'
|
|
446
|
-
},
|
|
447
|
-
isCropMode ? modeStyle : {}
|
|
476
|
+
{ transformOrigin: 'left top' },
|
|
477
|
+
modeStyle
|
|
448
478
|
)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
)
|
|
479
|
+
})
|
|
480
|
+
)
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function renderBaseImage () {
|
|
484
|
+
return renderImage(
|
|
485
|
+
extendObject(
|
|
486
|
+
{
|
|
487
|
+
source: { uri: src },
|
|
488
|
+
resizeMode: resizeMode,
|
|
489
|
+
onLoad: bindload && onImageLoad,
|
|
490
|
+
onError: binderror && onImageError,
|
|
491
|
+
style: extendObject(
|
|
492
|
+
{
|
|
493
|
+
transformOrigin: 'left top',
|
|
494
|
+
width: isCropMode ? imageWidth : '100%',
|
|
495
|
+
height: isCropMode ? imageHeight : '100%'
|
|
496
|
+
},
|
|
497
|
+
isCropMode ? modeStyle : {}
|
|
498
|
+
)
|
|
499
|
+
},
|
|
500
|
+
isLayoutMode ? {} : innerProps
|
|
501
|
+
),
|
|
502
|
+
enableFastImage
|
|
503
|
+
)
|
|
504
|
+
}
|
|
454
505
|
|
|
455
|
-
|
|
506
|
+
function renderLayoutImage () {
|
|
507
|
+
return createElement(View, innerProps, loaded && renderBaseImage())
|
|
508
|
+
}
|
|
456
509
|
|
|
457
|
-
const finalComponent = isSvg ?
|
|
510
|
+
const finalComponent = isSvg ? renderSvgImage() : isLayoutMode ? renderLayoutImage() : renderBaseImage()
|
|
458
511
|
|
|
459
512
|
if (hasPositionFixed) {
|
|
460
513
|
return createElement(Portal, null, finalComponent)
|
|
@@ -463,6 +516,6 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
463
516
|
return finalComponent
|
|
464
517
|
})
|
|
465
518
|
|
|
466
|
-
Image.displayName = '
|
|
519
|
+
Image.displayName = 'MpxImage'
|
|
467
520
|
|
|
468
521
|
export default Image
|
|
@@ -280,8 +280,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
const setKeyboardAvoidContext = () => {
|
|
283
|
-
if (
|
|
284
|
-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef }
|
|
283
|
+
if (keyboardAvoid) {
|
|
284
|
+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition }
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
|
|
@@ -296,19 +296,42 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
296
296
|
|
|
297
297
|
const onFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
298
298
|
setKeyboardAvoidContext()
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
299
|
+
|
|
300
|
+
if (bindfocus) {
|
|
301
|
+
const focusAction = () => {
|
|
302
|
+
bindfocus(
|
|
303
|
+
getCustomEvent(
|
|
304
|
+
'focus',
|
|
305
|
+
evt,
|
|
306
|
+
{
|
|
307
|
+
detail: {
|
|
308
|
+
value: tmpValue.current || '',
|
|
309
|
+
height: keyboardAvoid?.current?.keyboardHeight
|
|
310
|
+
},
|
|
311
|
+
layoutRef
|
|
312
|
+
},
|
|
313
|
+
props
|
|
314
|
+
)
|
|
315
|
+
)
|
|
316
|
+
if (keyboardAvoid?.current?.onKeyboardShow) {
|
|
317
|
+
keyboardAvoid.current.onKeyboardShow = undefined
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (keyboardAvoid?.current) {
|
|
321
|
+
// 有 keyboardAvoiding
|
|
322
|
+
if (keyboardAvoid.current.keyboardHeight) {
|
|
323
|
+
// iOS: keyboard 获取高度时机 keyboardWillShow 在 input focus 之前,可以立即执行
|
|
324
|
+
focusAction()
|
|
325
|
+
} else {
|
|
326
|
+
// Android,Harmony: keyboard 获取高度时机 keyboardDidShow 在 input focus 之后,需要延迟回调
|
|
327
|
+
evt.persist()
|
|
328
|
+
keyboardAvoid.current.onKeyboardShow = focusAction
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
// 无 keyboardAvoiding,直接执行 focus 回调
|
|
332
|
+
focusAction()
|
|
333
|
+
}
|
|
334
|
+
}
|
|
312
335
|
}
|
|
313
336
|
|
|
314
337
|
const onBlur = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|