Skip to content

Commit 1061b8e

Browse files
committed
feat: update backdrop configuration in Alert component to support custom children
1 parent b384dbd commit 1061b8e

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,9 @@ You can customize the default appearance and behavior of alerts using the `confi
412412
<AlertContainer
413413
config={{
414414
testID: 'alert_test_id',
415-
backdropBackgroundColor: 'rgba(255, 255, 255, 0.5)',
415+
backdrop: {
416+
backgroundColor: 'rgba(255, 255, 255, 0.5)',
417+
},
416418
alertStyle: {
417419
borderRadius: 20,
418420
padding: 20,
@@ -491,8 +493,12 @@ type AlertConfig = {
491493
// Test identifier for the alert
492494
testID?: string;
493495

494-
// Background color of the backdrop
495-
backdropBackgroundColor?: ColorValue;
496+
backdrop?: {
497+
// Background color of the backdrop
498+
backgroundColor?: ColorValue;
499+
// Custom content to render inside the backdrop
500+
children?: React.ReactNode;
501+
};
496502

497503
// Custom alert style
498504
alertStyle?: StyleProp<ViewStyle>;

src/components/Backdrop/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { type FC, useMemo } from "react";
1+
import { type FC, type PropsWithChildren, useMemo } from "react";
22
import { StyleSheet } from "react-native";
33
import Animated, { useAnimatedStyle } from "react-native-reanimated";
44

55
import { useAnimation } from "../../hooks/useAnimation";
66
import type { Props } from "./types";
77

8-
export const Backdrop: FC<Props> = ({
8+
export const Backdrop: FC<PropsWithChildren<Props>> = ({
99
animationDuration,
1010
isHiding,
1111
backgroundColor = "rgba(0, 0, 0, 0.5)",
12+
children,
1213
}) => {
1314
const { animation } = useAnimation({ animationDuration, isHiding });
1415

@@ -25,5 +26,5 @@ export const Backdrop: FC<Props> = ({
2526
[animatedStyle, backgroundColor],
2627
);
2728

28-
return <Animated.View style={style} />;
29+
return <Animated.View style={style}>{children}</Animated.View>;
2930
};

src/containers/AlertContainer/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ export const AlertContainer: FC<Props> = ({
8989
<Backdrop
9090
animationDuration={animationDuration}
9191
isHiding={isHiding}
92-
backgroundColor={config?.backdropBackgroundColor}
93-
/>
92+
backgroundColor={config?.backdrop?.backgroundColor}
93+
>
94+
{config?.backdrop?.children}
95+
</Backdrop>
9496
{renderConfetti()}
9597
<Alert
9698
{...currentAlert}

src/containers/AlertContainer/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export type Props = {
3232

3333
export type AlertConfig = {
3434
testID?: string;
35-
backdropBackgroundColor?: ColorValue;
35+
backdrop?: {
36+
backgroundColor?: ColorValue;
37+
children?: React.ReactNode;
38+
};
3639
success?: Partial<
3740
Pick<AlertProps, "icon" | "iconColor" | "iconSize" | "title">
3841
>;

0 commit comments

Comments
 (0)