@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.
@@ -13,3 +13,4 @@ export declare const DEFAULT_ICON_SIZE: number;
13
13
  */
14
14
  export declare let DEFAULT_ACTIVE_OPACITY: number;
15
15
  export declare const setGlobalActiveOpacity: (opacity: number) => void;
16
+ export declare const DEFAULT_ANIMATION_DURATION = 200;
package/dist/constants.js CHANGED
@@ -12,3 +12,4 @@ export let DEFAULT_ACTIVE_OPACITY = 0.8;
12
12
  export const setGlobalActiveOpacity = (opacity) => {
13
13
  DEFAULT_ACTIVE_OPACITY = opacity;
14
14
  };
15
+ export const DEFAULT_ANIMATION_DURATION = 200;
@@ -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(false);
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
- setIsLoading(false);
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: [isLoading && (_jsx(View, { style: [dimensions, { position: "absolute" }], children: _jsx(ImageSkeleton, { dimensions: dimensions, blurhash: blurhash, style: { position: "absolute" } }) })), _jsx(FastImage, { style: [
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artsy/palette-mobile",
3
- "version": "21.0.1",
3
+ "version": "21.1.0",
4
4
  "description": "Artsy's design system for React Native",
5
5
  "workspaces": [
6
6
  "Example"