Skip to content

Commit d2ea5fa

Browse files
committed
feat(background-image-native): add default image
1 parent f2246c1 commit d2ea5fa

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

packages/pluggableWidgets/background-image-native/src/BackgroundImage.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { BackgroundImageProps } from "../typings/BackgroundImageProps";
99

1010
export function BackgroundImage(props: BackgroundImageProps<BackgroundImageStyle>): JSX.Element | null {
1111
const styles = flattenStyles(defaultBackgroundImageStyle, props.style);
12-
const { image, name, resizeMode } = props;
12+
const { image, defaultImage, name, resizeMode } = props;
1313
let opacity = Number(props.opacity.toFixed());
1414

1515
if (opacity < 0) {
@@ -18,15 +18,17 @@ export function BackgroundImage(props: BackgroundImageProps<BackgroundImageStyle
1818
opacity = 1;
1919
}
2020

21-
if (image.status !== ValueStatus.Available || !image.value) {
21+
const renderImage = (image.status === ValueStatus.Available && image.value) || !defaultImage ? image : defaultImage;
22+
23+
if (renderImage.status !== ValueStatus.Available || !renderImage.value) {
2224
return null;
2325
}
2426

2527
const imageStyle = [
2628
StyleSheet.absoluteFill,
27-
typeof image.value === "number"
29+
typeof renderImage.value === "number"
2830
? { width: undefined, height: undefined }
29-
: typeof image.value === "string"
31+
: typeof renderImage.value === "string"
3032
? { width: "100%", height: "100%" }
3133
: undefined,
3234
styles.image,
@@ -35,7 +37,12 @@ export function BackgroundImage(props: BackgroundImageProps<BackgroundImageStyle
3537

3638
return (
3739
<View style={styles.container} testID={name}>
38-
<Image source={image.value} style={imageStyle} color={styles.image.svgColor} testID={`${name}$image`} />
40+
<Image
41+
source={renderImage.value}
42+
style={imageStyle}
43+
color={styles.image.svgColor}
44+
testID={`${name}$image`}
45+
/>
3946
{props.content}
4047
</View>
4148
);

packages/pluggableWidgets/background-image-native/src/BackgroundImage.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<caption>Image</caption>
1212
<description />
1313
</property>
14+
<property key="defaultImage" type="image" required="false">
15+
<caption>Default image</caption>
16+
<description/>
17+
</property>
1418
<property key="resizeMode" type="enumeration" defaultValue="cover">
1519
<caption>Resize mode</caption>
1620
<description>Cover: scale to cover space. Contain: scale to fit in space. Stretch: stretched to fit space. Center: centered and fit in space. For more information see the help page.</description>

packages/pluggableWidgets/background-image-native/typings/BackgroundImageProps.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface BackgroundImageProps<Style> {
1313
name: string;
1414
style: Style[];
1515
image: DynamicValue<NativeImage>;
16+
defaultImage?: DynamicValue<NativeImage>;
1617
resizeMode: ResizeModeEnum;
1718
opacity: Big;
1819
content?: ReactNode;
@@ -29,6 +30,7 @@ export interface BackgroundImagePreviewProps {
2930
readOnly: boolean;
3031
renderMode?: "design" | "xray" | "structure";
3132
image: { type: "static"; imageUrl: string; } | { type: "dynamic"; entity: string; } | null;
33+
defaultImage: { type: "static"; imageUrl: string; } | { type: "dynamic"; entity: string; } | null;
3234
resizeMode: ResizeModeEnum;
3335
opacity: number | null;
3436
content: { widgetCount: number; renderer: ComponentType<{ children: ReactNode; caption?: string }> };

0 commit comments

Comments
 (0)