@artsy/palette-mobile 11.2.12 → 11.2.13
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# v11.2.13 (Tue Aug 01 2023)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- feat(Image): enable more styling on the Image element and more [#120](https://github.com/artsy/palette-mobile/pull/120) ([@araujobarret](https://github.com/araujobarret))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Carlos Alberto de Araujo Barreto ([@araujobarret](https://github.com/araujobarret))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
1
13
|
# v11.2.12 (Fri Jul 28 2023)
|
|
2
14
|
|
|
3
15
|
#### 🐛 Bug Fix
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { FastImageProps } from "react-native-fast-image";
|
|
3
|
+
type CustomFastImageProps = Omit<FastImageProps, "onLoadStart" | "onLoadEnd" | "source">;
|
|
4
|
+
export interface ImageProps extends CustomFastImageProps {
|
|
4
5
|
/** Supplied aspect ratio of image. If none provided, defaults to 1 */
|
|
5
6
|
aspectRatio?: number;
|
|
6
7
|
/** Supplied width of image. If none provided, defaults to screen width */
|
|
@@ -13,3 +14,4 @@ export interface ImageProps extends FlexProps {
|
|
|
13
14
|
src: string;
|
|
14
15
|
}
|
|
15
16
|
export declare const Image: React.FC<ImageProps>;
|
|
17
|
+
export {};
|
|
@@ -11,12 +11,14 @@ const react_native_1 = require("react-native");
|
|
|
11
11
|
const react_native_fast_image_1 = __importDefault(require("react-native-fast-image"));
|
|
12
12
|
const react_native_reanimated_1 = require("react-native-reanimated");
|
|
13
13
|
const createGeminiUrl_1 = require("../../utils/createGeminiUrl");
|
|
14
|
+
const hooks_1 = require("../../utils/hooks");
|
|
14
15
|
const useScreenDimensions_1 = require("../../utils/hooks/useScreenDimensions");
|
|
15
16
|
const Flex_1 = require("../Flex");
|
|
16
17
|
const Skeleton_1 = require("../Skeleton");
|
|
17
|
-
const Image = ({ aspectRatio, width, height, performResize = true, src, ...flexProps }) => {
|
|
18
|
+
const Image = ({ aspectRatio, width, height, performResize = true, src, style, resizeMode, ...flexProps }) => {
|
|
18
19
|
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
19
20
|
const dimensions = useImageDimensions({ aspectRatio, width, height });
|
|
21
|
+
const color = (0, hooks_1.useColor)();
|
|
20
22
|
let uri = src;
|
|
21
23
|
if (performResize) {
|
|
22
24
|
uri = (0, createGeminiUrl_1.createGeminiUrl)({
|
|
@@ -25,7 +27,7 @@ const Image = ({ aspectRatio, width, height, performResize = true, src, ...flexP
|
|
|
25
27
|
height: react_native_1.PixelRatio.getPixelSizeForLayoutSize(dimensions.height),
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
|
-
return ((0, jsx_runtime_1.jsxs)(Flex_1.Flex, { position: "relative", ...flexProps, children: [!!loading && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { position: "absolute", zIndex: 1, children: (0, jsx_runtime_1.jsx)(Skeleton_1.Skeleton, { children: (0, jsx_runtime_1.jsx)(Skeleton_1.SkeletonBox, { ...dimensions }) }) })), (0, jsx_runtime_1.jsx)(moti_1.MotiView, { animate: { opacity: loading ? 0 : 1 }, transition: { type: "timing", duration: 400, easing: react_native_reanimated_1.Easing.sin }, children: (0, jsx_runtime_1.jsx)(react_native_fast_image_1.default, { style: dimensions, onLoadStart: () => setLoading(true), onLoadEnd: () => setLoading(false), source: {
|
|
30
|
+
return ((0, jsx_runtime_1.jsxs)(Flex_1.Flex, { position: "relative", ...flexProps, children: [!!loading && ((0, jsx_runtime_1.jsx)(Flex_1.Flex, { position: "absolute", zIndex: 1, children: (0, jsx_runtime_1.jsx)(Skeleton_1.Skeleton, { children: (0, jsx_runtime_1.jsx)(Skeleton_1.SkeletonBox, { ...dimensions }) }) })), (0, jsx_runtime_1.jsx)(moti_1.MotiView, { animate: { opacity: loading ? 0 : 1 }, transition: { type: "timing", duration: 400, easing: react_native_reanimated_1.Easing.sin }, children: (0, jsx_runtime_1.jsx)(react_native_fast_image_1.default, { style: [dimensions, style, { backgroundColor: color("black30") }], resizeMode: resizeMode, onLoadStart: () => setLoading(true), onLoadEnd: () => setLoading(false), source: {
|
|
29
31
|
priority: react_native_fast_image_1.default.priority.normal,
|
|
30
32
|
uri,
|
|
31
33
|
} }) })] }));
|
|
@@ -40,7 +42,7 @@ const useImageDimensions = (props) => {
|
|
|
40
42
|
}
|
|
41
43
|
else {
|
|
42
44
|
if (!props.aspectRatio) {
|
|
43
|
-
console.error("[
|
|
45
|
+
console.error("[Image] Error: `aspectRatio` is required if `height` is not provided.");
|
|
44
46
|
}
|
|
45
47
|
const aspectRatio = props.aspectRatio ?? 1;
|
|
46
48
|
imageHeight = imageWidth / aspectRatio;
|
|
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
const react_native_1 = require("@storybook/react-native");
|
|
5
5
|
const Image_1 = require("./Image");
|
|
6
|
+
const Flex_1 = require("../Flex");
|
|
6
7
|
(0, react_native_1.storiesOf)("Image", module)
|
|
7
8
|
.add("With default fallback screen width", () => ((0, jsx_runtime_1.jsx)(Image_1.Image, { aspectRatio: 0.62, src: "https://d32dm0rphc51dk.cloudfront.net/A983VUIZusVBKy420xP3ow/normalized.jpg" })))
|
|
8
9
|
.add("With width and height", () => ((0, jsx_runtime_1.jsx)(Image_1.Image, { width: 250, height: 400, src: "https://d32dm0rphc51dk.cloudfront.net/A983VUIZusVBKy420xP3ow/normalized.jpg" })))
|
|
9
10
|
.add("With aspect ratio", () => ((0, jsx_runtime_1.jsx)(Image_1.Image, { width: 250, aspectRatio: 0.62, src: "https://d32dm0rphc51dk.cloudfront.net/A983VUIZusVBKy420xP3ow/normalized.jpg" })))
|
|
10
|
-
.add("Without automatic resizing", () => ((0, jsx_runtime_1.jsx)(Image_1.Image, { aspectRatio: 0.62, performResize: false, src: "https://d32dm0rphc51dk.cloudfront.net/A983VUIZusVBKy420xP3ow/normalized.jpg" })))
|
|
11
|
+
.add("Without automatic resizing", () => ((0, jsx_runtime_1.jsx)(Image_1.Image, { aspectRatio: 0.62, performResize: false, src: "https://d32dm0rphc51dk.cloudfront.net/A983VUIZusVBKy420xP3ow/normalized.jpg" })))
|
|
12
|
+
.add("With percentage width and height", () => {
|
|
13
|
+
return ((0, jsx_runtime_1.jsxs)(Flex_1.Flex, { flexDirection: "row", flex: 1, children: [(0, jsx_runtime_1.jsx)(Flex_1.Flex, { flex: 1, style: { aspectRatio: 0.69 }, children: (0, jsx_runtime_1.jsx)(Image_1.Image, { src: "https://d32dm0rphc51dk.cloudfront.net/A983VUIZusVBKy420xP3ow/normalized.jpg", height: 260, width: 180, style: { width: "100%", height: "100%" } }) }), (0, jsx_runtime_1.jsx)(Flex_1.Flex, { flex: 1, style: { aspectRatio: 1 }, children: (0, jsx_runtime_1.jsx)(Image_1.Image, { src: "https://i.imgur.com/b9IZinu.gif", width: 200, height: 200, style: { width: "100%", height: "100%" } }) }), (0, jsx_runtime_1.jsx)(Flex_1.Flex, { flex: 1, style: { aspectRatio: 1.2 }, children: (0, jsx_runtime_1.jsx)(Image_1.Image, { width: 200, height: 240, src: "https://i.imgur.com/non-existing-image.gif", style: { width: "100%", height: "100%" } }) })] }));
|
|
14
|
+
});
|