@artsy/palette-mobile 21.0.1 → 21.1.0
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/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/elements/Image/Image.js +14 -5
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import FastImage from "@d11/react-native-fast-image";
|
|
3
3
|
import { memo, useState } from "react";
|
|
4
|
-
import { View } from "react-native";
|
|
5
4
|
import { Blurhash } from "react-native-blurhash";
|
|
5
|
+
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withSpring, } from "react-native-reanimated";
|
|
6
6
|
import { getImageURL } from "./helpers/getImageURL";
|
|
7
|
+
import { DEFAULT_ANIMATION_DURATION } from "../../constants";
|
|
7
8
|
import { useColor } from "../../utils/hooks";
|
|
8
9
|
import { useScreenDimensions } from "../../utils/hooks/useScreenDimensions";
|
|
9
10
|
import { Flex } from "../Flex";
|
|
10
11
|
import { Skeleton, SkeletonBox } from "../Skeleton";
|
|
11
12
|
export const Image = memo(({ aspectRatio, width, height, performResize = true, src, style, resizeMode, geminiResizeMode, showLoadingState = false, blurhash, ...flexProps }) => {
|
|
12
|
-
const [isLoading, setIsLoading] = useState(
|
|
13
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
13
14
|
const dimensions = useImageDimensions({ aspectRatio, width, height });
|
|
15
|
+
const opacity = useSharedValue(1);
|
|
14
16
|
const color = useColor();
|
|
15
17
|
const onLoadEnd = () => {
|
|
16
|
-
|
|
18
|
+
opacity.value = withSpring(0, { duration: DEFAULT_ANIMATION_DURATION }, () => {
|
|
19
|
+
runOnJS(setIsLoading)(false);
|
|
20
|
+
});
|
|
17
21
|
};
|
|
22
|
+
const skeletonStyle = useAnimatedStyle(() => {
|
|
23
|
+
return {
|
|
24
|
+
opacity: opacity.value,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
18
27
|
if (showLoadingState) {
|
|
19
28
|
return (_jsx(ImageSkeleton, { dimensions: dimensions, blurhash: blurhash, style: { position: "absolute" } }));
|
|
20
29
|
}
|
|
21
|
-
return (_jsxs(Flex, { position: "relative", ...flexProps, style: { ...dimensions }, children: [
|
|
30
|
+
return (_jsxs(Flex, { position: "relative", ...flexProps, style: { ...dimensions }, children: [_jsx(FastImage, { style: [
|
|
22
31
|
dimensions,
|
|
23
32
|
style,
|
|
24
33
|
// If we have a blurhash, we don't want to show a background color
|
|
@@ -27,7 +36,7 @@ export const Image = memo(({ aspectRatio, width, height, performResize = true, s
|
|
|
27
36
|
], resizeMode: resizeMode, onLoadEnd: onLoadEnd, source: {
|
|
28
37
|
priority: FastImage.priority.normal,
|
|
29
38
|
uri: getImageURL({ src, dimensions, geminiResizeMode, performResize }),
|
|
30
|
-
} })] }));
|
|
39
|
+
} }), isLoading && (_jsx(Animated.View, { style: [dimensions, { position: "absolute" }, skeletonStyle], children: _jsx(ImageSkeleton, { dimensions: dimensions, blurhash: blurhash, style: { position: "absolute" } }) }))] }));
|
|
31
40
|
});
|
|
32
41
|
const useImageDimensions = (props) => {
|
|
33
42
|
const screenDimensions = useScreenDimensions();
|