@mpxjs/webpack-plugin 2.8.25-alpha.22 → 2.8.25-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/lib/template-compiler/compiler.js +9 -4
  2. package/package.json +1 -1
  3. package/lib/runtime/components/react/dist/KeyboardAvoidingView.jsx +0 -89
  4. package/lib/runtime/components/react/dist/context.js +0 -14
  5. package/lib/runtime/components/react/dist/event.config.js +0 -27
  6. package/lib/runtime/components/react/dist/getInnerListeners.js +0 -262
  7. package/lib/runtime/components/react/dist/mpx-button.jsx +0 -271
  8. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +0 -60
  9. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +0 -15
  10. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +0 -84
  11. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +0 -87
  12. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +0 -15
  13. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +0 -28
  14. package/lib/runtime/components/react/dist/mpx-canvas/html.js +0 -341
  15. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +0 -236
  16. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +0 -89
  17. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +0 -90
  18. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +0 -131
  19. package/lib/runtime/components/react/dist/mpx-form.jsx +0 -68
  20. package/lib/runtime/components/react/dist/mpx-icon/icons/cancel.png +0 -0
  21. package/lib/runtime/components/react/dist/mpx-icon/icons/clear.png +0 -0
  22. package/lib/runtime/components/react/dist/mpx-icon/icons/download.png +0 -0
  23. package/lib/runtime/components/react/dist/mpx-icon/icons/info.png +0 -0
  24. package/lib/runtime/components/react/dist/mpx-icon/icons/search.png +0 -0
  25. package/lib/runtime/components/react/dist/mpx-icon/icons/success.png +0 -0
  26. package/lib/runtime/components/react/dist/mpx-icon/icons/success_no_circle.png +0 -0
  27. package/lib/runtime/components/react/dist/mpx-icon/icons/waiting.png +0 -0
  28. package/lib/runtime/components/react/dist/mpx-icon/icons/warn.png +0 -0
  29. package/lib/runtime/components/react/dist/mpx-icon/index.jsx +0 -50
  30. package/lib/runtime/components/react/dist/mpx-image.jsx +0 -292
  31. package/lib/runtime/components/react/dist/mpx-input.jsx +0 -292
  32. package/lib/runtime/components/react/dist/mpx-label.jsx +0 -52
  33. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +0 -32
  34. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +0 -468
  35. package/lib/runtime/components/react/dist/mpx-navigator.jsx +0 -33
  36. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +0 -74
  37. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +0 -141
  38. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +0 -147
  39. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +0 -99
  40. package/lib/runtime/components/react/dist/mpx-picker/regionData.js +0 -6099
  41. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +0 -81
  42. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +0 -242
  43. package/lib/runtime/components/react/dist/mpx-picker/type.js +0 -1
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +0 -35
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +0 -193
  46. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +0 -125
  47. package/lib/runtime/components/react/dist/mpx-portal/index.jsx +0 -30
  48. package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +0 -112
  49. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +0 -41
  50. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +0 -86
  51. package/lib/runtime/components/react/dist/mpx-radio.jsx +0 -140
  52. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +0 -39
  53. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +0 -62
  54. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +0 -17
  55. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +0 -372
  56. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +0 -11
  57. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +0 -59
  58. package/lib/runtime/components/react/dist/mpx-swiper.jsx +0 -671
  59. package/lib/runtime/components/react/dist/mpx-switch.jsx +0 -97
  60. package/lib/runtime/components/react/dist/mpx-text.jsx +0 -41
  61. package/lib/runtime/components/react/dist/mpx-textarea.jsx +0 -40
  62. package/lib/runtime/components/react/dist/mpx-video.jsx +0 -248
  63. package/lib/runtime/components/react/dist/mpx-view.jsx +0 -611
  64. package/lib/runtime/components/react/dist/mpx-web-view.jsx +0 -289
  65. package/lib/runtime/components/react/dist/parser.js +0 -218
  66. package/lib/runtime/components/react/dist/pickerFaces.js +0 -76
  67. package/lib/runtime/components/react/dist/pickerVIewContext.js +0 -14
  68. package/lib/runtime/components/react/dist/pickerViewIndicator.jsx +0 -23
  69. package/lib/runtime/components/react/dist/pickerViewMask.jsx +0 -18
  70. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -346
  71. package/lib/runtime/components/react/dist/useNodesRef.js +0 -16
  72. package/lib/runtime/components/react/dist/utils.jsx +0 -599
@@ -1,90 +0,0 @@
1
- /**
2
- * ✔ bindchange
3
- */
4
- import { useRef, forwardRef, useContext, useMemo, useEffect, createElement } from 'react';
5
- import { View } from 'react-native';
6
- import { warn } from '@mpxjs/utils';
7
- import { FormContext, CheckboxGroupContext } from './context';
8
- import useInnerProps, { getCustomEvent } from './getInnerListeners';
9
- import useNodesRef from './useNodesRef';
10
- import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
11
- const CheckboxGroup = forwardRef((props, ref) => {
12
- const propsRef = useRef({});
13
- propsRef.current = props;
14
- const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
15
- const formContext = useContext(FormContext);
16
- let formValuesMap;
17
- if (formContext) {
18
- formValuesMap = formContext.formValuesMap;
19
- }
20
- const groupValue = useRef({}).current;
21
- const defaultStyle = {
22
- flexDirection: 'row',
23
- flexWrap: 'wrap'
24
- };
25
- const styleObj = extendObject({}, defaultStyle, style);
26
- const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
27
- const nodeRef = useRef(null);
28
- useNodesRef(props, ref, nodeRef, { style: normalStyle });
29
- const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
30
- const getValue = () => {
31
- const arr = [];
32
- for (const key in groupValue) {
33
- if (groupValue[key].checked) {
34
- arr.push(key);
35
- }
36
- }
37
- return arr;
38
- };
39
- const resetValue = () => {
40
- Object.keys(groupValue).forEach((key) => {
41
- groupValue[key].checked = false;
42
- groupValue[key].setValue(false);
43
- });
44
- };
45
- if (formValuesMap) {
46
- if (!props.name) {
47
- warn('If a form component is used, the name attribute is required.');
48
- }
49
- else {
50
- formValuesMap.set(props.name, { getValue, resetValue });
51
- }
52
- }
53
- useEffect(() => {
54
- return () => {
55
- if (formValuesMap && props.name) {
56
- formValuesMap.delete(props.name);
57
- }
58
- };
59
- }, []);
60
- const innerProps = useInnerProps(props, extendObject({
61
- ref: nodeRef,
62
- style: extendObject({}, normalStyle, layoutStyle)
63
- }, layoutProps), [
64
- 'name'
65
- ], {
66
- layoutRef
67
- });
68
- const contextValue = useMemo(() => {
69
- const notifyChange = (evt) => {
70
- const { bindchange } = propsRef.current;
71
- bindchange &&
72
- bindchange(getCustomEvent('tap', evt, {
73
- layoutRef,
74
- detail: {
75
- value: getValue()
76
- }
77
- }, propsRef.current));
78
- };
79
- return {
80
- groupValue,
81
- notifyChange
82
- };
83
- }, []);
84
- return createElement(View, innerProps, createElement(CheckboxGroupContext.Provider, { value: contextValue }, wrapChildren(props, {
85
- hasVarDec,
86
- varContext: varContextRef.current
87
- })));
88
- });
89
- CheckboxGroup.displayName = 'MpxCheckboxGroup';
90
- export default CheckboxGroup;
@@ -1,131 +0,0 @@
1
- /**
2
- * ✔ value
3
- * ✔ disabled
4
- * ✔ checked
5
- * ✔ color
6
- */
7
- import { useState, useRef, forwardRef, useEffect, useContext, createElement } from 'react';
8
- import { View, StyleSheet } from 'react-native';
9
- import { warn } from '@mpxjs/utils';
10
- import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
- import useNodesRef from './useNodesRef';
12
- import Icon from './mpx-icon';
13
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
14
- import { CheckboxGroupContext, LabelContext } from './context';
15
- const styles = StyleSheet.create({
16
- container: {
17
- flexDirection: 'row',
18
- alignItems: 'center'
19
- },
20
- wrapper: {
21
- alignItems: 'center',
22
- justifyContent: 'center',
23
- width: 24,
24
- height: 24,
25
- borderColor: '#D1D1D1',
26
- borderWidth: 1,
27
- borderRadius: 3,
28
- backgroundColor: '#ffffff',
29
- marginRight: 5
30
- },
31
- wrapperDisabled: {
32
- backgroundColor: '#E1E1E1'
33
- },
34
- icon: {
35
- opacity: 0
36
- },
37
- iconChecked: {
38
- opacity: 1
39
- }
40
- });
41
- const Checkbox = forwardRef((checkboxProps, ref) => {
42
- const { textProps, innerProps: props = {} } = splitProps(checkboxProps);
43
- const { value = '', disabled = false, checked = false, color = '#09BB07', style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap, _onChange } = props;
44
- const [isChecked, setIsChecked] = useState(!!checked);
45
- const groupContext = useContext(CheckboxGroupContext);
46
- let groupValue;
47
- let notifyChange;
48
- const defaultStyle = extendObject({}, styles.wrapper, disabled ? styles.wrapperDisabled : null);
49
- const styleObj = extendObject({}, styles.container, style);
50
- const onChange = (evt) => {
51
- if (disabled)
52
- return;
53
- const checked = !isChecked;
54
- setIsChecked(checked);
55
- if (groupValue) {
56
- groupValue[value].checked = checked;
57
- }
58
- notifyChange && notifyChange(evt);
59
- // Called when the switch type attribute is checkbox
60
- _onChange && _onChange(evt, { checked });
61
- };
62
- const onTap = (evt) => {
63
- bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props));
64
- onChange(evt);
65
- };
66
- const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
67
- const nodeRef = useRef(null);
68
- useNodesRef(props, ref, nodeRef, {
69
- style: extendObject({}, defaultStyle, normalStyle),
70
- change: onChange
71
- });
72
- const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
73
- const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
74
- if (backgroundStyle) {
75
- warn('Checkbox does not support background image-related styles!');
76
- }
77
- const labelContext = useContext(LabelContext);
78
- if (groupContext) {
79
- groupValue = groupContext.groupValue;
80
- notifyChange = groupContext.notifyChange;
81
- }
82
- if (labelContext) {
83
- labelContext.current.triggerChange = onChange;
84
- }
85
- const innerProps = useInnerProps(props, extendObject({
86
- ref: nodeRef,
87
- style: extendObject({}, innerStyle, layoutStyle)
88
- }, layoutProps, {
89
- bindtap: !disabled && onTap
90
- }), [
91
- 'value',
92
- 'disabled',
93
- 'checked'
94
- ], {
95
- layoutRef
96
- });
97
- useEffect(() => {
98
- if (groupValue) {
99
- groupValue[value] = {
100
- checked: checked,
101
- setValue: setIsChecked
102
- };
103
- }
104
- return () => {
105
- if (groupValue) {
106
- delete groupValue[value];
107
- }
108
- };
109
- }, []);
110
- useEffect(() => {
111
- if (checked !== isChecked) {
112
- setIsChecked(checked);
113
- if (groupValue) {
114
- groupValue[value].checked = checked;
115
- }
116
- }
117
- }, [checked]);
118
- return createElement(View, innerProps, createElement(View, { style: defaultStyle }, createElement(Icon, {
119
- type: 'success_no_circle',
120
- size: 18,
121
- color: disabled ? '#ADADAD' : color,
122
- style: isChecked ? styles.iconChecked : styles.icon
123
- })), wrapChildren(props, {
124
- hasVarDec,
125
- varContext: varContextRef.current,
126
- textStyle,
127
- textProps
128
- }));
129
- });
130
- Checkbox.displayName = 'MpxCheckbox';
131
- export default Checkbox;
@@ -1,68 +0,0 @@
1
- /**
2
- * ✘ report-submit
3
- * ✘ report-submit-timeout
4
- * ✔ bindsubmit
5
- * ✔ bindreset
6
- */
7
- import { View } from 'react-native';
8
- import { useRef, forwardRef, useMemo, createElement } from 'react';
9
- import useNodesRef from './useNodesRef';
10
- import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
- import { FormContext } from './context';
12
- import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren, extendObject } from './utils';
13
- const _Form = forwardRef((fromProps, ref) => {
14
- const { textProps, innerProps: props = {} } = splitProps(fromProps);
15
- const { style, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
16
- const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
17
- const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
18
- const formRef = useRef(null);
19
- useNodesRef(props, ref, formRef, {
20
- style: normalStyle
21
- });
22
- const propsRef = useRef({});
23
- propsRef.current = props;
24
- const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef });
25
- const innerProps = useInnerProps(props, extendObject({
26
- style: extendObject({}, innerStyle, layoutStyle),
27
- ref: formRef
28
- }, layoutProps), [
29
- 'bindsubmit',
30
- 'bindreset'
31
- ], { layoutRef });
32
- const contextValue = useMemo(() => {
33
- const formValuesMap = new Map();
34
- const submit = () => {
35
- const { bindsubmit } = propsRef.current;
36
- const formValue = {};
37
- for (const name of formValuesMap.keys()) {
38
- if (formValuesMap.get(name).getValue) {
39
- formValue[name] = formValuesMap.get(name).getValue();
40
- }
41
- }
42
- bindsubmit && bindsubmit(getCustomEvent('submit', {}, {
43
- detail: {
44
- value: formValue
45
- },
46
- layoutRef
47
- }, propsRef.current));
48
- };
49
- const reset = () => {
50
- const { bindreset } = propsRef.current;
51
- bindreset && bindreset();
52
- formValuesMap.forEach(item => item.resetValue());
53
- };
54
- return {
55
- formValuesMap,
56
- submit,
57
- reset
58
- };
59
- }, []);
60
- return createElement(View, innerProps, createElement(FormContext.Provider, { value: contextValue }, wrapChildren(props, {
61
- hasVarDec,
62
- varContext: varContextRef.current,
63
- textStyle,
64
- textProps
65
- })));
66
- });
67
- _Form.displayName = 'MpxForm';
68
- export default _Form;
@@ -1,50 +0,0 @@
1
- /**
2
- * ✔ type
3
- * ✔ size
4
- * ✔ color
5
- */
6
- import { forwardRef, useRef, createElement } from 'react';
7
- import { Image } from 'react-native';
8
- import useInnerProps from '../getInnerListeners';
9
- import useNodesRef from '../useNodesRef';
10
- import { useLayout, useTransformStyle, extendObject } from '../utils';
11
- import Success from './icons/success.png';
12
- import SuccessNoCircle from './icons/success_no_circle.png';
13
- import Info from './icons/info.png';
14
- import Warn from './icons/warn.png';
15
- import Waiting from './icons/waiting.png';
16
- import Cancel from './icons/cancel.png';
17
- import Download from './icons/download.png';
18
- import Search from './icons/search.png';
19
- import Clear from './icons/clear.png';
20
- const IconTypeMap = new Map([
21
- ['success', Success],
22
- ['success_no_circle', SuccessNoCircle],
23
- ['info', Info],
24
- ['warn', Warn],
25
- ['waiting', Waiting],
26
- ['cancel', Cancel],
27
- ['download', Download],
28
- ['search', Search],
29
- ['clear', Clear]
30
- ]);
31
- const Icon = forwardRef((props, ref) => {
32
- const { type, size = 23, color, style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
33
- const source = IconTypeMap.get(type);
34
- const defaultStyle = { width: ~~size, height: ~~size };
35
- const styleObj = extendObject({}, defaultStyle, style);
36
- const { hasSelfPercent, normalStyle, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
37
- const nodeRef = useRef(null);
38
- useNodesRef(props, ref, nodeRef, { style: normalStyle });
39
- const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
40
- const innerProps = useInnerProps(props, extendObject({
41
- ref: nodeRef,
42
- source,
43
- style: extendObject({}, normalStyle, layoutStyle, { tintColor: color })
44
- }, layoutProps), [], {
45
- layoutRef
46
- });
47
- return createElement(Image, innerProps);
48
- });
49
- Icon.displayName = 'MpxIcon';
50
- export default Icon;
@@ -1,292 +0,0 @@
1
- /**
2
- * ✔ src
3
- * ✔ mode
4
- * ✘ show-menu-by-longpress
5
- * ✔ binderror
6
- * ✔ bindload
7
- * ✘ fade-in
8
- * ✔ webp
9
- * ✘ lazy-load
10
- * ✔ bindtap
11
- * ✔ DEFAULT_SIZE
12
- */
13
- import { useEffect, useMemo, useState, useRef, forwardRef, createElement } from 'react';
14
- import { Image as RNImage, View } from 'react-native';
15
- import { noop } from '@mpxjs/utils';
16
- import { SvgCssUri } from 'react-native-svg/css';
17
- import useInnerProps, { getCustomEvent } from './getInnerListeners';
18
- import useNodesRef from './useNodesRef';
19
- import { SVG_REGEXP, useLayout, useTransformStyle, renderImage, extendObject } from './utils';
20
- const DEFAULT_IMAGE_WIDTH = 320;
21
- const DEFAULT_IMAGE_HEIGHT = 240;
22
- const cropMode = [
23
- 'top',
24
- 'bottom',
25
- 'center',
26
- 'right',
27
- 'left',
28
- 'top left',
29
- 'top right',
30
- 'bottom left',
31
- 'bottom right'
32
- ];
33
- const ModeMap = new Map([
34
- ['scaleToFill', 'stretch'],
35
- ['aspectFit', 'contain'],
36
- ['aspectFill', 'cover'],
37
- ['widthFix', 'stretch'],
38
- ['heightFix', 'stretch'],
39
- ...cropMode.map(mode => [mode, 'stretch'])
40
- ]);
41
- const isNumber = (value) => typeof value === 'number';
42
- const relativeCenteredSize = (viewSize, imageSize) => (viewSize - imageSize) / 2;
43
- function noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio) {
44
- const isMeetSize = viewWidth && viewHeight && ratio;
45
- if (isSvg && !isMeetSize)
46
- return true;
47
- if (!isSvg && !['scaleToFill', 'aspectFit', 'aspectFill'].includes(mode) && !isMeetSize)
48
- return true;
49
- return false;
50
- }
51
- const Image = forwardRef((props, ref) => {
52
- const { src = '', mode = 'scaleToFill', style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'enable-fast-image': enableFastImage, 'parent-width': parentWidth, 'parent-height': parentHeight, bindload, binderror } = props;
53
- const defaultStyle = {
54
- width: DEFAULT_IMAGE_WIDTH,
55
- height: DEFAULT_IMAGE_HEIGHT
56
- };
57
- const styleObj = extendObject({}, defaultStyle, style, { overflow: 'hidden' });
58
- const state = useRef({});
59
- const nodeRef = useRef(null);
60
- useNodesRef(props, ref, nodeRef, {
61
- defaultStyle
62
- });
63
- const isSvg = SVG_REGEXP.test(src);
64
- const isWidthFixMode = mode === 'widthFix';
65
- const isHeightFixMode = mode === 'heightFix';
66
- const isCropMode = cropMode.includes(mode);
67
- const isLayoutMode = isWidthFixMode || isHeightFixMode || isCropMode;
68
- const resizeMode = ModeMap.get(mode) || 'stretch';
69
- const onLayout = ({ nativeEvent: { layout: { width, height } } }) => {
70
- state.current.viewWidth = width;
71
- state.current.viewHeight = height;
72
- if (state.current.imageWidth && state.current.imageHeight && state.current.ratio) {
73
- setViewWidth(width);
74
- setViewHeight(height);
75
- setRatio(state.current.ratio);
76
- setImageWidth(state.current.imageWidth);
77
- setImageHeight(state.current.imageHeight);
78
- state.current = {};
79
- setLoaded(true);
80
- }
81
- };
82
- const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
83
- const { layoutRef, layoutStyle, layoutProps } = useLayout({
84
- props,
85
- hasSelfPercent,
86
- setWidth,
87
- setHeight,
88
- nodeRef,
89
- onLayout: isLayoutMode ? onLayout : noop
90
- });
91
- const { width, height } = normalStyle;
92
- const [viewWidth, setViewWidth] = useState(isNumber(width) ? width : 0);
93
- const [viewHeight, setViewHeight] = useState(isNumber(height) ? height : 0);
94
- const [imageWidth, setImageWidth] = useState(0);
95
- const [imageHeight, setImageHeight] = useState(0);
96
- const [ratio, setRatio] = useState(0);
97
- const [loaded, setLoaded] = useState(!isLayoutMode);
98
- const fixedHeight = useMemo(() => {
99
- const fixed = viewWidth * ratio;
100
- return !fixed ? viewHeight : fixed;
101
- }, [ratio, viewWidth, viewHeight]);
102
- const fixedWidth = useMemo(() => {
103
- if (!ratio)
104
- return viewWidth;
105
- const fixed = viewHeight / ratio;
106
- return !fixed ? viewWidth : fixed;
107
- }, [ratio, viewWidth, viewHeight]);
108
- const modeStyle = useMemo(() => {
109
- if (noMeetCalcRule(isSvg, mode, viewWidth, viewHeight, ratio))
110
- return {};
111
- switch (mode) {
112
- case 'scaleToFill':
113
- case 'aspectFit':
114
- if (isSvg) {
115
- const scale = ratio <= 1
116
- ? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
117
- : imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight;
118
- return {
119
- transform: [
120
- { scale },
121
- ratio <= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
122
- ]
123
- };
124
- }
125
- return {};
126
- case 'aspectFill':
127
- if (isSvg) {
128
- const scale = ratio >= 1
129
- ? imageWidth >= viewWidth ? viewWidth / imageWidth : imageWidth / viewWidth
130
- : imageHeight >= viewHeight ? viewHeight / imageHeight : imageHeight / viewHeight;
131
- return {
132
- transform: [
133
- { scale },
134
- ratio >= 1 ? { translateY: -(imageHeight * scale - viewHeight) / 2 / scale } : { translateX: -(imageWidth * scale - viewWidth) / 2 / scale }
135
- ]
136
- };
137
- }
138
- return {};
139
- case 'widthFix':
140
- case 'heightFix':
141
- if (isSvg) {
142
- const scale = ratio >= 1
143
- ? imageWidth >= fixedWidth ? fixedWidth / imageWidth : imageWidth / fixedWidth
144
- : imageHeight >= fixedHeight ? fixedHeight / imageHeight : imageHeight / fixedHeight;
145
- return {
146
- transform: [{ scale }]
147
- };
148
- }
149
- return {};
150
- case 'top':
151
- return {
152
- transform: [
153
- { translateX: relativeCenteredSize(viewWidth, imageWidth) }
154
- ]
155
- };
156
- case 'bottom':
157
- return {
158
- transform: [
159
- { translateY: viewHeight - imageHeight },
160
- { translateX: relativeCenteredSize(viewWidth, imageWidth) }
161
- ]
162
- };
163
- case 'center':
164
- return {
165
- transform: [
166
- { translateY: relativeCenteredSize(viewHeight, imageHeight) },
167
- { translateX: relativeCenteredSize(viewWidth, imageWidth) }
168
- ]
169
- };
170
- case 'left':
171
- return {
172
- transform: [
173
- { translateY: relativeCenteredSize(viewHeight, imageHeight) }
174
- ]
175
- };
176
- case 'right':
177
- return {
178
- transform: [
179
- { translateY: relativeCenteredSize(viewHeight, imageHeight) },
180
- { translateX: viewWidth - imageWidth }
181
- ]
182
- };
183
- case 'top left':
184
- return {};
185
- case 'top right':
186
- return {
187
- transform: [
188
- { translateX: viewWidth - imageWidth }
189
- ]
190
- };
191
- case 'bottom left':
192
- return {
193
- transform: [
194
- { translateY: viewHeight - imageHeight }
195
- ]
196
- };
197
- case 'bottom right':
198
- return {
199
- transform: [
200
- { translateY: viewHeight - imageHeight },
201
- { translateX: viewWidth - imageWidth }
202
- ]
203
- };
204
- default:
205
- return {};
206
- }
207
- }, [isSvg, mode, viewWidth, viewHeight, imageWidth, imageHeight, ratio, fixedWidth, fixedHeight]);
208
- const onSvgLoad = (evt) => {
209
- const { width, height } = evt.nativeEvent.layout;
210
- setRatio(!width ? 0 : height / width);
211
- setImageWidth(width);
212
- setImageHeight(height);
213
- bindload && bindload(getCustomEvent('load', evt, {
214
- detail: { width, height },
215
- layoutRef
216
- }, props));
217
- };
218
- const onSvgError = (evt) => {
219
- binderror(getCustomEvent('error', evt, {
220
- detail: { errMsg: evt?.message },
221
- layoutRef
222
- }, props));
223
- };
224
- const onImageLoad = (evt) => {
225
- evt.persist();
226
- RNImage.getSize(src, (width, height) => {
227
- bindload(getCustomEvent('load', evt, {
228
- detail: { width, height },
229
- layoutRef
230
- }, props));
231
- });
232
- };
233
- const onImageError = (evt) => {
234
- binderror(getCustomEvent('error', evt, {
235
- detail: { errMsg: evt.nativeEvent.error },
236
- layoutRef
237
- }, props));
238
- };
239
- useEffect(() => {
240
- if (!isSvg && isLayoutMode) {
241
- RNImage.getSize(src, (width, height) => {
242
- state.current.imageWidth = width;
243
- state.current.imageHeight = height;
244
- state.current.ratio = !width ? 0 : height / width;
245
- if (isWidthFixMode
246
- ? state.current.viewWidth
247
- : isHeightFixMode
248
- ? state.current.viewHeight
249
- : state.current.viewWidth && state.current.viewHeight) {
250
- state.current.viewWidth && setViewWidth(state.current.viewWidth);
251
- state.current.viewHeight && setViewHeight(state.current.viewHeight);
252
- setRatio(!width ? 0 : height / width);
253
- setImageWidth(width);
254
- setImageHeight(height);
255
- state.current = {};
256
- setLoaded(true);
257
- }
258
- });
259
- }
260
- }, [src, isSvg, isLayoutMode]);
261
- const innerProps = useInnerProps(props, extendObject({
262
- ref: nodeRef,
263
- style: extendObject({}, normalStyle, layoutStyle, isHeightFixMode ? { width: fixedWidth } : {}, isWidthFixMode ? { height: fixedHeight } : {})
264
- }, layoutProps), [
265
- 'src',
266
- 'mode',
267
- 'svg'
268
- ], {
269
- layoutRef
270
- });
271
- const SvgImage = createElement(View, innerProps, createElement(SvgCssUri, {
272
- uri: src,
273
- onLayout: onSvgLoad,
274
- onError: binderror && onSvgError,
275
- style: extendObject({ transformOrigin: 'top left' }, modeStyle)
276
- }));
277
- const BaseImage = renderImage(extendObject({
278
- source: { uri: src },
279
- resizeMode: resizeMode,
280
- onLoad: bindload && onImageLoad,
281
- onError: binderror && onImageError,
282
- style: extendObject({
283
- transformOrigin: 'top left',
284
- width: isCropMode ? imageWidth : '100%',
285
- height: isCropMode ? imageHeight : '100%'
286
- }, isCropMode ? modeStyle : {})
287
- }, isLayoutMode ? {} : innerProps), enableFastImage);
288
- const LayoutImage = createElement(View, innerProps, loaded && BaseImage);
289
- return isSvg ? SvgImage : isLayoutMode ? LayoutImage : BaseImage;
290
- });
291
- Image.displayName = 'mpx-image';
292
- export default Image;