@jobber/components-native 0.91.0 → 0.91.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.91.0",
3
+ "version": "0.91.1",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -94,5 +94,5 @@
94
94
  "react-native-safe-area-context": "^5.4.0",
95
95
  "react-native-svg": ">=12.0.0"
96
96
  },
97
- "gitHead": "29381f7508578c0518fd4cecd07d021df83e08fc"
97
+ "gitHead": "5f68cfee448c36f14f589edd6359c9cb30c8ab79"
98
98
  }
@@ -1,4 +1,4 @@
1
- import React, { useState } from "react";
1
+ import React, { useEffect, useRef, useState } from "react";
2
2
  import { ImageBackground, View } from "react-native";
3
3
  import { useStyles } from "./MediaView.style";
4
4
  import { StatusCode } from "../../types";
@@ -14,20 +14,37 @@ export function MediaView({ accessibilityLabel, showOverlay, showError, file, st
14
14
  const { useCreateThumbnail } = useAtlantisFormatFileContext();
15
15
  const { thumbnail, error } = useCreateThumbnail(file);
16
16
  const [isLoading, setIsLoading] = useState(false);
17
+ /**
18
+ * Tracks whether onLoadEnd has fired to prevent race conditions.
19
+ * ImageBackground can fire onLoadEnd before onLoadStart when loading cached images,
20
+ * which would cause isLoading to get stuck at true, showing an infinite spinner.
21
+ */
22
+ const hasLoadedRef = useRef(false);
17
23
  const a11yLabel = computeA11yLabel({
18
24
  accessibilityLabel,
19
25
  showOverlay,
20
26
  showError,
21
27
  t,
22
28
  });
23
- const hasError = showError || error;
24
- const uri = thumbnail || file.thumbnailUrl || file.source;
25
- const styles = useStyles();
29
+ const hasError = showError || error, uri = thumbnail || file.thumbnailUrl || file.source, styles = useStyles();
30
+ const handleLoadStart = () => {
31
+ if (!hasLoadedRef.current) {
32
+ setIsLoading(true);
33
+ }
34
+ };
35
+ const handleLoadEnd = () => {
36
+ hasLoadedRef.current = true;
37
+ setIsLoading(false);
38
+ };
39
+ useEffect(() => {
40
+ hasLoadedRef.current = false;
41
+ setIsLoading(false);
42
+ }, [uri]);
26
43
  return (React.createElement(View, { accessible: true, accessibilityLabel: a11yLabel },
27
44
  React.createElement(ImageBackground, { style: [
28
45
  styles.imageBackground,
29
46
  styleInGrid ? styles.imageBackgroundGrid : styles.imageBackgroundFlat,
30
- ], resizeMode: styleInGrid ? "cover" : "contain", source: { uri }, testID: "test-image", onLoadStart: () => setIsLoading(true), onLoadEnd: () => setIsLoading(false) },
47
+ ], resizeMode: styleInGrid ? "cover" : "contain", source: { uri }, testID: "test-image", onLoadStart: handleLoadStart, onLoadEnd: handleLoadEnd },
31
48
  React.createElement(Overlay, { isLoading: isLoading, showOverlay: showOverlay, hasError: hasError, file: file, onUploadComplete: onUploadComplete, styles: styles }))));
32
49
  }
33
50
  function Overlay({ isLoading, showOverlay, hasError, file, onUploadComplete, styles, }) {