@arco-design/mobile-react 2.29.5 → 2.29.6

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.
@@ -60,22 +60,22 @@ export interface ImageProps {
60
60
  * */
61
61
  bordered?: boolean;
62
62
  /**
63
- * 自定义展示加载中内容,staticLabel=false时有效
63
+ * 自定义展示加载中内容
64
64
  * @en Custom display loading content, valid when staticLabel=false
65
65
  * */
66
66
  loadingArea?: ReactNode;
67
67
  /**
68
- * 自定义展示加载失败内容,staticLabel=false时有效
68
+ * 自定义展示加载失败内容
69
69
  * @en Custom display failed to load content, valid when staticLabel=false
70
70
  * */
71
71
  errorArea?: ReactNode;
72
72
  /**
73
- * 是否展示图片加载中提示,staticLabel=false时有效
73
+ * 是否展示图片加载中提示
74
74
  * @en Whether to display the image loading prompt, valid when staticLabel=false
75
75
  * */
76
76
  showLoading?: boolean;
77
77
  /**
78
- * 是否展示图片加载失败提示,staticLabel=false时有效
78
+ * 是否展示图片加载失败提示
79
79
  * @en Whether to display the image loading failure prompt, valid when staticLabel=false
80
80
  * */
81
81
  showError?: boolean;
@@ -145,17 +145,17 @@ export interface ImageProps {
145
145
  * 图片加载完毕时触发的回调
146
146
  * @en Callback when the image is loaded
147
147
  * */
148
- onLoad?: (e: Event, image: HTMLImageElement) => void;
148
+ onLoad?: (e: Event | null, image: HTMLImageElement) => void;
149
149
  /**
150
150
  * 图片加载失败时触发的回调,如果有自动重试则在重试最终失败后触发
151
151
  * @en Callback when the image fails to load, triggered after the retry finally fails if there is an automatic retry
152
152
  */
153
- onError?: (e: string | Event) => void;
153
+ onError?: (e: string | Event | null) => void;
154
154
  /**
155
155
  * 图片加载失败时自动重试触发的回调
156
156
  * @en Callback triggered by automatic retry when image loading fails
157
157
  */
158
- onAutoRetry?: (e: string | Event) => void;
158
+ onAutoRetry?: (e: string | Event | null) => void;
159
159
  }
160
160
  export interface ImageRef {
161
161
  /**
@@ -14,30 +14,6 @@ import { useSystem, useWindowSize, getStyleWithVendor, useMountedState } from '.
14
14
  * @name_en Image
15
15
  */
16
16
  export var BaseImage = /*#__PURE__*/forwardRef(function (props, ref) {
17
- var system = useSystem();
18
-
19
- var _useWindowSize = useWindowSize(),
20
- windowWidth = _useWindowSize.windowWidth,
21
- windowHeight = _useWindowSize.windowHeight;
22
-
23
- var _useMountedState = useMountedState('init'),
24
- imageStatus = _useMountedState[0],
25
- setImageStatus = _useMountedState[1];
26
-
27
- var _useMountedState2 = useMountedState(''),
28
- wrapClass = _useMountedState2[0],
29
- setWrapClass = _useMountedState2[1];
30
-
31
- var _useMountedState3 = useMountedState(false),
32
- staticRetrying = _useMountedState3[0],
33
- setStaticRetrying = _useMountedState3[1];
34
-
35
- var imageRef = useRef(null);
36
- var imageDomRef = useRef(null);
37
- var wrapRef = useRef(null);
38
- var retryCountRef = useRef(0);
39
- var loadingImageRef = useRef(null);
40
- var hasLoadedRef = useRef(false);
41
17
  var style = props.style,
42
18
  className = props.className,
43
19
  status = props.status,
@@ -74,9 +50,33 @@ export var BaseImage = /*#__PURE__*/forwardRef(function (props, ref) {
74
50
  nativeProps = _props$nativeProps === void 0 ? {} : _props$nativeProps,
75
51
  onChange = props.onChange,
76
52
  onClick = props.onClick,
77
- _onLoad = props.onLoad,
53
+ onLoad = props.onLoad,
78
54
  onError = props.onError,
79
55
  onAutoRetry = props.onAutoRetry;
56
+ var system = useSystem();
57
+
58
+ var _useWindowSize = useWindowSize(),
59
+ windowWidth = _useWindowSize.windowWidth,
60
+ windowHeight = _useWindowSize.windowHeight;
61
+
62
+ var _useMountedState = useMountedState(staticLabel && showLoading ? 'loading' : 'init'),
63
+ imageStatus = _useMountedState[0],
64
+ setImageStatus = _useMountedState[1];
65
+
66
+ var _useMountedState2 = useMountedState(''),
67
+ wrapClass = _useMountedState2[0],
68
+ setWrapClass = _useMountedState2[1];
69
+
70
+ var _useMountedState3 = useMountedState(false),
71
+ staticRetrying = _useMountedState3[0],
72
+ setStaticRetrying = _useMountedState3[1];
73
+
74
+ var imageRef = useRef(null);
75
+ var imageDomRef = useRef(null);
76
+ var wrapRef = useRef(null);
77
+ var retryCountRef = useRef(0);
78
+ var loadingImageRef = useRef(null);
79
+ var hasLoadedRef = useRef(false);
80
80
  var isPreview = Boolean(fit.indexOf('preview') >= 0);
81
81
  var actualBoxWidth = boxWidth || windowWidth;
82
82
  var actualBoxHeight = boxHeight || windowHeight;
@@ -112,6 +112,21 @@ export var BaseImage = /*#__PURE__*/forwardRef(function (props, ref) {
112
112
  retryCountRef.current = 0;
113
113
  loadImage();
114
114
  }, [attrs, width, height, showImage, staticLabel]);
115
+ useEffect(function () {
116
+ var _imageDomRef$current;
117
+
118
+ // 当使用img标签时,onLoad可能加载完成前已经执行完,此时手动触发一次
119
+ // @en When using the img tag, onLoad may have been executed before loading is complete, and it needs to be triggered manually
120
+ if (staticLabel && !hasLoadedRef.current && (_imageDomRef$current = imageDomRef.current) != null && _imageDomRef$current.complete) {
121
+ // 图片有宽高认为正常加载,否则认为加载错误
122
+ // @en If the image has width and height, it is considered to be loaded normally, otherwise it is considered to be a loading error
123
+ if (imageDomRef.current.naturalWidth || imageDomRef.current.naturalHeight) {
124
+ handleImageLoaded(null, imageDomRef.current);
125
+ } else {
126
+ handleStaticImageError(null);
127
+ }
128
+ }
129
+ }, [staticLabel]);
115
130
 
116
131
  function changeStatus(newStatus) {
117
132
  setImageStatus(newStatus);
@@ -132,6 +147,43 @@ export var BaseImage = /*#__PURE__*/forwardRef(function (props, ref) {
132
147
  }
133
148
  }
134
149
 
150
+ function handleImageLoaded(evt, image) {
151
+ hasLoadedRef.current = true;
152
+ changeStatus('loaded');
153
+ var _image$width = image.width,
154
+ imageWidth = _image$width === void 0 ? 0 : _image$width,
155
+ _image$height = image.height,
156
+ imageHeight = _image$height === void 0 ? 0 : _image$height;
157
+ var extraClass = '';
158
+
159
+ if (isPreview) {
160
+ var scale = imageWidth / imageHeight;
161
+ var windowScale = actualBoxWidth / actualBoxHeight;
162
+
163
+ if (fit === 'preview-y') {
164
+ if (scale < windowScale) {
165
+ image.style.width = actualBoxWidth + "px";
166
+ image.style.height = actualBoxWidth / scale + "px";
167
+ extraClass = 'preview-overflow-y';
168
+ } else {
169
+ extraClass = 'preview-fit-contain-y';
170
+ }
171
+ } else if (fit === 'preview-x') {
172
+ if (scale > windowScale) {
173
+ image.style.width = actualBoxHeight * scale + "px";
174
+ image.style.height = actualBoxHeight + "px";
175
+ extraClass = 'preview-overflow-x';
176
+ } else {
177
+ extraClass = 'preview-fit-contain-x';
178
+ }
179
+ }
180
+ }
181
+
182
+ extraClass && image.classList.add(extraClass);
183
+ setWrapClass(extraClass ? extraClass + "-container" : '');
184
+ onLoad && onLoad(evt, image);
185
+ }
186
+
135
187
  function loadImage(isFromRetry) {
136
188
  // 如果在加载图片前发现上一个图片还没加载完,则抛弃上一个图片的加载
137
189
  // @en Abort last image before starting loading new image
@@ -157,41 +209,8 @@ export var BaseImage = /*#__PURE__*/forwardRef(function (props, ref) {
157
209
  image.onload = function (evt) {
158
210
  loadingImageRef.current = null;
159
211
  imageDomRef.current = image;
160
- hasLoadedRef.current = true;
161
- changeStatus('loaded');
162
- var _image$width = image.width,
163
- imageWidth = _image$width === void 0 ? 0 : _image$width,
164
- _image$height = image.height,
165
- imageHeight = _image$height === void 0 ? 0 : _image$height;
166
- var extraClass = '';
167
-
168
- if (isPreview) {
169
- var scale = imageWidth / imageHeight;
170
- var windowScale = actualBoxWidth / actualBoxHeight;
171
-
172
- if (fit === 'preview-y') {
173
- if (scale < windowScale) {
174
- image.style.width = actualBoxWidth + "px";
175
- image.style.height = actualBoxWidth / scale + "px";
176
- extraClass = 'preview-overflow-y';
177
- } else {
178
- extraClass = 'preview-fit-contain-y';
179
- }
180
- } else if (fit === 'preview-x') {
181
- if (scale > windowScale) {
182
- image.style.width = actualBoxHeight * scale + "px";
183
- image.style.height = actualBoxHeight + "px";
184
- extraClass = 'preview-overflow-x';
185
- } else {
186
- extraClass = 'preview-fit-contain-x';
187
- }
188
- }
189
- }
190
-
191
- extraClass && image.classList.add(extraClass);
192
- setWrapClass(extraClass ? extraClass + "-container" : '');
212
+ handleImageLoaded(evt, image);
193
213
  replaceChild(image);
194
- _onLoad && _onLoad(evt, image);
195
214
  };
196
215
 
197
216
  image.onerror = function (evt) {
@@ -217,9 +236,10 @@ export var BaseImage = /*#__PURE__*/forwardRef(function (props, ref) {
217
236
  }
218
237
 
219
238
  function handleStaticImageError(e) {
220
- var evt = e.nativeEvent;
239
+ var evt = e ? e.nativeEvent : null;
221
240
 
222
241
  if (retryCountRef.current >= retryTime) {
242
+ changeStatus('error');
223
243
  onError && onError(evt);
224
244
  } else {
225
245
  retryCountRef.current += 1;
@@ -284,7 +304,7 @@ export var BaseImage = /*#__PURE__*/forwardRef(function (props, ref) {
284
304
  }, staticLabel && showImage && !staticRetrying ? /*#__PURE__*/React.createElement("img", _extends({}, nativeProps, attrs, {
285
305
  ref: imageDomRef,
286
306
  onLoad: function onLoad(e) {
287
- return _onLoad && _onLoad(e.nativeEvent, imageDomRef.current);
307
+ return handleImageLoaded(e.nativeEvent, imageDomRef.current);
288
308
  },
289
309
  onError: handleStaticImageError
290
310
  })) : null), showLoading && validStatus === 'loading' ? /*#__PURE__*/React.createElement("div", {
@@ -814,7 +814,9 @@ var ImagePreview = /*#__PURE__*/forwardRef(function (props, ref) {
814
814
  return renderIndicator(currentIndex, total, lastIndex);
815
815
  }
816
816
 
817
- return openLoaded ? /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
817
+ return openLoaded ? /*#__PURE__*/React.createElement(Portal, {
818
+ getContainer: getContainer
819
+ }, /*#__PURE__*/React.createElement("div", {
818
820
  className: "image-preview-indicator"
819
821
  }, currentIndex + 1, "/", total)) : null;
820
822
  } // ios在重设style时图片会消失一下造成闪动,因此在底下垫一张图
@@ -852,7 +854,9 @@ var ImagePreview = /*#__PURE__*/forwardRef(function (props, ref) {
852
854
  function renderLoadingArea(index) {
853
855
  // loadingArea提出来,放到过渡图上层
854
856
  // @en The loadingArea is extracted and placed on the upper layer of the transition image
855
- return index === openIndex ? /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", {
857
+ return index === openIndex ? /*#__PURE__*/React.createElement(Portal, {
858
+ getContainer: getContainer
859
+ }, /*#__PURE__*/React.createElement("div", {
856
860
  className: "image-preview-loading-area"
857
861
  }, loadingArea || /*#__PURE__*/React.createElement(Loading, {
858
862
  type: "circle",
@@ -5,6 +5,7 @@ export interface OpenBaseProps {
5
5
  close: (e: any) => void;
6
6
  openIndex: number;
7
7
  images: any[];
8
+ getContainer?: () => HTMLElement;
8
9
  }
9
10
  export declare function open<P extends OpenBaseProps>(Component: React.FunctionComponent<P>): (config: Pick<P, Exclude<keyof P, "close">>, context?: GlobalContextParams | undefined) => {
10
11
  close: () => void;
@@ -7,9 +7,7 @@ export function open(Component) {
7
7
  unmountOnExit: true
8
8
  }, config || {}, {
9
9
  close: function close() {}
10
- });
11
-
12
- var dynamicProps = _extends({}, baseProps); // 不同的key用不同的容器挂载
10
+ }); // 不同的key用不同的容器挂载
13
11
  // @en Different keys are mounted in different containers
14
12
 
15
13
 
@@ -23,6 +21,12 @@ export function open(Component) {
23
21
  var _ReactDOMRender = new ReactDOMRender(Component, div, context),
24
22
  render = _ReactDOMRender.render;
25
23
 
24
+ var dynamicProps = _extends({}, baseProps, {
25
+ getContainer: function getContainer() {
26
+ return div;
27
+ }
28
+ });
29
+
26
30
  function update(newConfig) {
27
31
  dynamicProps = _extends({}, dynamicProps, newConfig || {});
28
32
  render(dynamicProps);
@@ -14,9 +14,7 @@ export function getOpenMethod(Component, containerId, normalize) {
14
14
  }, normalize(config), {
15
15
  visible: false,
16
16
  close: function close() {}
17
- });
18
-
19
- var dynamicProps = _extends({}, baseProps); // 不同的key用不同的容器挂载
17
+ }); // 不同的key用不同的容器挂载
20
18
 
21
19
 
22
20
  var id = "_" + (containerId || 'ARCO_MASKING') + "_DIV_" + (config.key || '') + "_";
@@ -29,6 +27,12 @@ export function getOpenMethod(Component, containerId, normalize) {
29
27
  var _ReactDOMRender = new ReactDOMRender(Component, div, context),
30
28
  render = _ReactDOMRender.render;
31
29
 
30
+ var dynamicProps = _extends({}, baseProps, {
31
+ getContainer: function getContainer() {
32
+ return div;
33
+ }
34
+ });
35
+
32
36
  function update(newConfig) {
33
37
  dynamicProps = _extends({}, dynamicProps, normalize(newConfig));
34
38
  render(dynamicProps);
@@ -63,10 +63,7 @@ export declare function methodsGenerator<P extends OpenBaseProps>(Comp: React.Fu
63
63
  close: () => void;
64
64
  update: (newConfig: Pick<P, Exclude<keyof P, "visible" | "close">> & {
65
65
  key?: string | undefined;
66
- }) => void; /**
67
- * 内容面板 touchstart 事件,返回true时表示阻止本组件内部处理事件
68
- * @en The touchstart callback of content panel. When it returns true, it means that the event is prevented from being processed inside the component
69
- */
66
+ }) => void;
70
67
  };
71
68
  };
72
69
  declare const _default: React.ForwardRefExoticComponent<PopupSwiperProps & React.RefAttributes<PopupSwiperRef>> & {
@@ -82,10 +79,7 @@ declare const _default: React.ForwardRefExoticComponent<PopupSwiperProps & React
82
79
  close: () => void;
83
80
  update: (newConfig: Pick<import("../context-provider").WithGlobalContext<PopupSwiperProps & React.RefAttributes<PopupSwiperRef>>, "direction" | "children" | "ref" | "key" | "context" | "translateZ" | "className" | "getScrollContainer" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "getContainer" | "mountOnEnter" | "unmountOnExit" | "onClose" | "initialBodyOverflow" | "maskClass" | "maskStyle" | "contentClass" | "contentStyle" | "maskTransitionType" | "contentTransitionType" | "maskTransitionTimeout" | "contentTransitionTimeout" | "maskClosable" | "animatingClosable" | "orientationDirection" | "preventBodyScroll" | "gestureOutOfControl" | "onOpen" | "onMaskClick" | "onPreventTouchMove" | "needBottomOffset" | "percentToClose" | "distanceToClose" | "speedToClose" | "allowSwipeDirections" | "exitDirection"> & {
84
81
  key?: string | undefined;
85
- }) => void; /**
86
- * 内容面板 touchstart 事件,返回true时表示阻止本组件内部处理事件
87
- * @en The touchstart callback of content panel. When it returns true, it means that the event is prevented from being processed inside the component
88
- */
82
+ }) => void;
89
83
  };
90
84
  };
91
85
  /**
package/esm/tabs/index.js CHANGED
@@ -229,7 +229,10 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
229
229
  // 利用受控手动更改index时,给cell line加上动画
230
230
  // @en Animate the cell line when changeing the index
231
231
  setCellTrans(true);
232
- changeFromRef.current = 'manual';
232
+
233
+ if (!changeFromRef.current) {
234
+ changeFromRef.current = 'manual';
235
+ }
233
236
  }, [activeTab]);
234
237
  useUpdateEffect(function () {
235
238
  onDistanceChange && onDistanceChange(distance, wrapWidth, activeIndex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arco-design/mobile-react",
3
- "version": "2.29.5",
3
+ "version": "2.29.6",
4
4
  "description": "",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -15,7 +15,7 @@
15
15
  "author": "taoyiyue@bytedance.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@arco-design/mobile-utils": "2.16.8",
18
+ "@arco-design/mobile-utils": "2.16.9",
19
19
  "@arco-design/transformable": "^1.0.0",
20
20
  "lodash.throttle": "^4.1.1",
21
21
  "resize-observer-polyfill": "^1.5.1"
@@ -49,5 +49,5 @@
49
49
  "publishConfig": {
50
50
  "access": "public"
51
51
  },
52
- "gitHead": "eca19563a4f83ce7acecb0a4e8e11e4ee258189e"
52
+ "gitHead": "0ac7a2b2a9f339e75d0b81d6af6dcf0f55ffad45"
53
53
  }
@@ -60,22 +60,22 @@ export interface ImageProps {
60
60
  * */
61
61
  bordered?: boolean;
62
62
  /**
63
- * 自定义展示加载中内容,staticLabel=false时有效
63
+ * 自定义展示加载中内容
64
64
  * @en Custom display loading content, valid when staticLabel=false
65
65
  * */
66
66
  loadingArea?: ReactNode;
67
67
  /**
68
- * 自定义展示加载失败内容,staticLabel=false时有效
68
+ * 自定义展示加载失败内容
69
69
  * @en Custom display failed to load content, valid when staticLabel=false
70
70
  * */
71
71
  errorArea?: ReactNode;
72
72
  /**
73
- * 是否展示图片加载中提示,staticLabel=false时有效
73
+ * 是否展示图片加载中提示
74
74
  * @en Whether to display the image loading prompt, valid when staticLabel=false
75
75
  * */
76
76
  showLoading?: boolean;
77
77
  /**
78
- * 是否展示图片加载失败提示,staticLabel=false时有效
78
+ * 是否展示图片加载失败提示
79
79
  * @en Whether to display the image loading failure prompt, valid when staticLabel=false
80
80
  * */
81
81
  showError?: boolean;
@@ -145,17 +145,17 @@ export interface ImageProps {
145
145
  * 图片加载完毕时触发的回调
146
146
  * @en Callback when the image is loaded
147
147
  * */
148
- onLoad?: (e: Event, image: HTMLImageElement) => void;
148
+ onLoad?: (e: Event | null, image: HTMLImageElement) => void;
149
149
  /**
150
150
  * 图片加载失败时触发的回调,如果有自动重试则在重试最终失败后触发
151
151
  * @en Callback when the image fails to load, triggered after the retry finally fails if there is an automatic retry
152
152
  */
153
- onError?: (e: string | Event) => void;
153
+ onError?: (e: string | Event | null) => void;
154
154
  /**
155
155
  * 图片加载失败时自动重试触发的回调
156
156
  * @en Callback triggered by automatic retry when image loading fails
157
157
  */
158
- onAutoRetry?: (e: string | Event) => void;
158
+ onAutoRetry?: (e: string | Event | null) => void;
159
159
  }
160
160
  export interface ImageRef {
161
161
  /**
@@ -34,30 +34,6 @@
34
34
  * @name_en Image
35
35
  */
36
36
  var BaseImage = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
37
- var system = (0, _helpers.useSystem)();
38
-
39
- var _useWindowSize = (0, _helpers.useWindowSize)(),
40
- windowWidth = _useWindowSize.windowWidth,
41
- windowHeight = _useWindowSize.windowHeight;
42
-
43
- var _useMountedState = (0, _helpers.useMountedState)('init'),
44
- imageStatus = _useMountedState[0],
45
- setImageStatus = _useMountedState[1];
46
-
47
- var _useMountedState2 = (0, _helpers.useMountedState)(''),
48
- wrapClass = _useMountedState2[0],
49
- setWrapClass = _useMountedState2[1];
50
-
51
- var _useMountedState3 = (0, _helpers.useMountedState)(false),
52
- staticRetrying = _useMountedState3[0],
53
- setStaticRetrying = _useMountedState3[1];
54
-
55
- var imageRef = (0, _react.useRef)(null);
56
- var imageDomRef = (0, _react.useRef)(null);
57
- var wrapRef = (0, _react.useRef)(null);
58
- var retryCountRef = (0, _react.useRef)(0);
59
- var loadingImageRef = (0, _react.useRef)(null);
60
- var hasLoadedRef = (0, _react.useRef)(false);
61
37
  var style = props.style,
62
38
  className = props.className,
63
39
  status = props.status,
@@ -94,9 +70,33 @@
94
70
  nativeProps = _props$nativeProps === void 0 ? {} : _props$nativeProps,
95
71
  onChange = props.onChange,
96
72
  onClick = props.onClick,
97
- _onLoad = props.onLoad,
73
+ onLoad = props.onLoad,
98
74
  onError = props.onError,
99
75
  onAutoRetry = props.onAutoRetry;
76
+ var system = (0, _helpers.useSystem)();
77
+
78
+ var _useWindowSize = (0, _helpers.useWindowSize)(),
79
+ windowWidth = _useWindowSize.windowWidth,
80
+ windowHeight = _useWindowSize.windowHeight;
81
+
82
+ var _useMountedState = (0, _helpers.useMountedState)(staticLabel && showLoading ? 'loading' : 'init'),
83
+ imageStatus = _useMountedState[0],
84
+ setImageStatus = _useMountedState[1];
85
+
86
+ var _useMountedState2 = (0, _helpers.useMountedState)(''),
87
+ wrapClass = _useMountedState2[0],
88
+ setWrapClass = _useMountedState2[1];
89
+
90
+ var _useMountedState3 = (0, _helpers.useMountedState)(false),
91
+ staticRetrying = _useMountedState3[0],
92
+ setStaticRetrying = _useMountedState3[1];
93
+
94
+ var imageRef = (0, _react.useRef)(null);
95
+ var imageDomRef = (0, _react.useRef)(null);
96
+ var wrapRef = (0, _react.useRef)(null);
97
+ var retryCountRef = (0, _react.useRef)(0);
98
+ var loadingImageRef = (0, _react.useRef)(null);
99
+ var hasLoadedRef = (0, _react.useRef)(false);
100
100
  var isPreview = Boolean(fit.indexOf('preview') >= 0);
101
101
  var actualBoxWidth = boxWidth || windowWidth;
102
102
  var actualBoxHeight = boxHeight || windowHeight;
@@ -132,6 +132,21 @@
132
132
  retryCountRef.current = 0;
133
133
  loadImage();
134
134
  }, [attrs, width, height, showImage, staticLabel]);
135
+ (0, _react.useEffect)(function () {
136
+ var _imageDomRef$current;
137
+
138
+ // 当使用img标签时,onLoad可能加载完成前已经执行完,此时手动触发一次
139
+ // @en When using the img tag, onLoad may have been executed before loading is complete, and it needs to be triggered manually
140
+ if (staticLabel && !hasLoadedRef.current && (_imageDomRef$current = imageDomRef.current) != null && _imageDomRef$current.complete) {
141
+ // 图片有宽高认为正常加载,否则认为加载错误
142
+ // @en If the image has width and height, it is considered to be loaded normally, otherwise it is considered to be a loading error
143
+ if (imageDomRef.current.naturalWidth || imageDomRef.current.naturalHeight) {
144
+ handleImageLoaded(null, imageDomRef.current);
145
+ } else {
146
+ handleStaticImageError(null);
147
+ }
148
+ }
149
+ }, [staticLabel]);
135
150
 
136
151
  function changeStatus(newStatus) {
137
152
  setImageStatus(newStatus);
@@ -152,6 +167,43 @@
152
167
  }
153
168
  }
154
169
 
170
+ function handleImageLoaded(evt, image) {
171
+ hasLoadedRef.current = true;
172
+ changeStatus('loaded');
173
+ var _image$width = image.width,
174
+ imageWidth = _image$width === void 0 ? 0 : _image$width,
175
+ _image$height = image.height,
176
+ imageHeight = _image$height === void 0 ? 0 : _image$height;
177
+ var extraClass = '';
178
+
179
+ if (isPreview) {
180
+ var scale = imageWidth / imageHeight;
181
+ var windowScale = actualBoxWidth / actualBoxHeight;
182
+
183
+ if (fit === 'preview-y') {
184
+ if (scale < windowScale) {
185
+ image.style.width = actualBoxWidth + "px";
186
+ image.style.height = actualBoxWidth / scale + "px";
187
+ extraClass = 'preview-overflow-y';
188
+ } else {
189
+ extraClass = 'preview-fit-contain-y';
190
+ }
191
+ } else if (fit === 'preview-x') {
192
+ if (scale > windowScale) {
193
+ image.style.width = actualBoxHeight * scale + "px";
194
+ image.style.height = actualBoxHeight + "px";
195
+ extraClass = 'preview-overflow-x';
196
+ } else {
197
+ extraClass = 'preview-fit-contain-x';
198
+ }
199
+ }
200
+ }
201
+
202
+ extraClass && image.classList.add(extraClass);
203
+ setWrapClass(extraClass ? extraClass + "-container" : '');
204
+ onLoad && onLoad(evt, image);
205
+ }
206
+
155
207
  function loadImage(isFromRetry) {
156
208
  // 如果在加载图片前发现上一个图片还没加载完,则抛弃上一个图片的加载
157
209
  // @en Abort last image before starting loading new image
@@ -177,41 +229,8 @@
177
229
  image.onload = function (evt) {
178
230
  loadingImageRef.current = null;
179
231
  imageDomRef.current = image;
180
- hasLoadedRef.current = true;
181
- changeStatus('loaded');
182
- var _image$width = image.width,
183
- imageWidth = _image$width === void 0 ? 0 : _image$width,
184
- _image$height = image.height,
185
- imageHeight = _image$height === void 0 ? 0 : _image$height;
186
- var extraClass = '';
187
-
188
- if (isPreview) {
189
- var scale = imageWidth / imageHeight;
190
- var windowScale = actualBoxWidth / actualBoxHeight;
191
-
192
- if (fit === 'preview-y') {
193
- if (scale < windowScale) {
194
- image.style.width = actualBoxWidth + "px";
195
- image.style.height = actualBoxWidth / scale + "px";
196
- extraClass = 'preview-overflow-y';
197
- } else {
198
- extraClass = 'preview-fit-contain-y';
199
- }
200
- } else if (fit === 'preview-x') {
201
- if (scale > windowScale) {
202
- image.style.width = actualBoxHeight * scale + "px";
203
- image.style.height = actualBoxHeight + "px";
204
- extraClass = 'preview-overflow-x';
205
- } else {
206
- extraClass = 'preview-fit-contain-x';
207
- }
208
- }
209
- }
210
-
211
- extraClass && image.classList.add(extraClass);
212
- setWrapClass(extraClass ? extraClass + "-container" : '');
232
+ handleImageLoaded(evt, image);
213
233
  replaceChild(image);
214
- _onLoad && _onLoad(evt, image);
215
234
  };
216
235
 
217
236
  image.onerror = function (evt) {
@@ -237,9 +256,10 @@
237
256
  }
238
257
 
239
258
  function handleStaticImageError(e) {
240
- var evt = e.nativeEvent;
259
+ var evt = e ? e.nativeEvent : null;
241
260
 
242
261
  if (retryCountRef.current >= retryTime) {
262
+ changeStatus('error');
243
263
  onError && onError(evt);
244
264
  } else {
245
265
  retryCountRef.current += 1;
@@ -304,7 +324,7 @@
304
324
  }, staticLabel && showImage && !staticRetrying ? /*#__PURE__*/_react.default.createElement("img", (0, _extends2.default)({}, nativeProps, attrs, {
305
325
  ref: imageDomRef,
306
326
  onLoad: function onLoad(e) {
307
- return _onLoad && _onLoad(e.nativeEvent, imageDomRef.current);
327
+ return handleImageLoaded(e.nativeEvent, imageDomRef.current);
308
328
  },
309
329
  onError: handleStaticImageError
310
330
  })) : null), showLoading && validStatus === 'loading' ? /*#__PURE__*/_react.default.createElement("div", {
@@ -843,7 +843,9 @@
843
843
  return renderIndicator(currentIndex, total, lastIndex);
844
844
  }
845
845
 
846
- return openLoaded ? /*#__PURE__*/_react.default.createElement(_portal.default, null, /*#__PURE__*/_react.default.createElement("div", {
846
+ return openLoaded ? /*#__PURE__*/_react.default.createElement(_portal.default, {
847
+ getContainer: getContainer
848
+ }, /*#__PURE__*/_react.default.createElement("div", {
847
849
  className: "image-preview-indicator"
848
850
  }, currentIndex + 1, "/", total)) : null;
849
851
  } // ios在重设style时图片会消失一下造成闪动,因此在底下垫一张图
@@ -881,7 +883,9 @@
881
883
  function renderLoadingArea(index) {
882
884
  // loadingArea提出来,放到过渡图上层
883
885
  // @en The loadingArea is extracted and placed on the upper layer of the transition image
884
- return index === openIndex ? /*#__PURE__*/_react.default.createElement(_portal.default, null, /*#__PURE__*/_react.default.createElement("div", {
886
+ return index === openIndex ? /*#__PURE__*/_react.default.createElement(_portal.default, {
887
+ getContainer: getContainer
888
+ }, /*#__PURE__*/_react.default.createElement("div", {
885
889
  className: "image-preview-loading-area"
886
890
  }, loadingArea || /*#__PURE__*/_react.default.createElement(_loading.default, {
887
891
  type: "circle",
@@ -5,6 +5,7 @@ export interface OpenBaseProps {
5
5
  close: (e: any) => void;
6
6
  openIndex: number;
7
7
  images: any[];
8
+ getContainer?: () => HTMLElement;
8
9
  }
9
10
  export declare function open<P extends OpenBaseProps>(Component: React.FunctionComponent<P>): (config: Pick<P, Exclude<keyof P, "close">>, context?: GlobalContextParams | undefined) => {
10
11
  close: () => void;