Skip to content

Commit 6e21776

Browse files
committed
feat: integrate Customizations container into App and enhance Alert component to support icon customization via config
1 parent d4b6144 commit 6e21776

File tree

7 files changed

+119
-3
lines changed

7 files changed

+119
-3
lines changed

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AlertContainer } from 'react-native-alert-queue';
44

55
import { SafeAreaView, SafeAreaProvider } from 'react-native-safe-area-context';
66
import { Basics } from './containers/Basics';
7+
import { Customizations } from './containers/Customizations';
78

89
export default function App() {
910
return (
@@ -13,6 +14,7 @@ export default function App() {
1314
<Text style={styles.title}>React Native Alert Queue</Text>
1415
<ScrollView style={styles.scrollView}>
1516
<Basics />
17+
<Customizations />
1618
</ScrollView>
1719
</SafeAreaView>
1820
<AlertContainer />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Svg, { type SvgProps, Path } from 'react-native-svg';
2+
3+
export const DangerIcon = (props: SvgProps) => (
4+
<Svg viewBox="0 0 24 24" {...props}>
5+
<Path
6+
d="M4.723 21.167h-.04a2.833 2.833 0 0 1-2.476-3.89L9.53 4.45a2.833 2.833 0 0 1 4.946.009l7.273 12.728c.162.381.23.691.248 1.007a2.8 2.8 0 0 1-.725 2.042 2.8 2.8 0 0 1-1.956.93l-14.52.001z"
7+
opacity={0.4}
8+
/>
9+
<Path
10+
fillRule="evenodd"
11+
d="M11.124 10.02c0-.481.393-.874.875-.874s.875.393.875.875v2.828a.876.876 0 0 1-1.75 0zm0 6.25c0-.485.393-.88.875-.88s.875.39.875.869a.88.88 0 0 1-.875.886.877.877 0 0 1-.875-.875"
12+
clipRule="evenodd"
13+
/>
14+
</Svg>
15+
);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* eslint-disable react-native/no-inline-styles */
2+
/* eslint-disable react/no-unstable-nested-components */
3+
4+
import { alert } from 'react-native-alert-queue';
5+
import { Button } from '../components/Button';
6+
import { Section } from '../components/Section';
7+
import {
8+
StyleSheet,
9+
Text,
10+
View,
11+
type StyleProp,
12+
type ViewStyle,
13+
} from 'react-native';
14+
import { DangerIcon } from '../components/icons/Danger';
15+
16+
export const Customizations = () => {
17+
return (
18+
<Section title="Customizations">
19+
<Button
20+
onPress={() =>
21+
alert.show({
22+
title: 'Hello',
23+
message: 'Message',
24+
icon: DangerIcon,
25+
beforeTitleSlot: () => (
26+
<Slot
27+
text="Before title slot"
28+
style={{
29+
marginBottom: 10,
30+
}}
31+
/>
32+
),
33+
beforeMessageSlot: () => (
34+
<Slot
35+
text="Before message slot"
36+
style={{
37+
marginBottom: 20,
38+
}}
39+
/>
40+
),
41+
beforeButtonsSlot: () => (
42+
<Slot
43+
text="Before buttons slot"
44+
style={{
45+
marginBottom: 20,
46+
}}
47+
/>
48+
),
49+
afterButtonsSlot: () => <Slot text="After buttons slot" />,
50+
})
51+
}
52+
text="Slots"
53+
/>
54+
</Section>
55+
);
56+
};
57+
58+
const Slot = ({
59+
text,
60+
style,
61+
}: {
62+
text: string;
63+
style?: StyleProp<ViewStyle>;
64+
}) => {
65+
return (
66+
<View style={StyleSheet.compose(styles.slot, style)}>
67+
<Text style={styles.slotText}>{text}</Text>
68+
</View>
69+
);
70+
};
71+
72+
const styles = StyleSheet.create({
73+
slot: {
74+
backgroundColor: 'black',
75+
padding: 10,
76+
},
77+
slotText: {
78+
color: 'white',
79+
fontSize: 16,
80+
fontWeight: 'bold',
81+
},
82+
});

src/components/Alert/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const Alert: FC<AlertViewProps> = (props) => {
2828
beforeTitleSlot,
2929
renderDismissButton,
3030
icon,
31-
iconColor = 'black',
31+
iconColor,
3232
iconSize,
3333
isDismissible,
3434
isHiding,
@@ -39,6 +39,7 @@ export const Alert: FC<AlertViewProps> = (props) => {
3939
renderTitle,
4040
message,
4141
renderMessage,
42+
config,
4243
} = props;
4344

4445
const { animation } = useAnimation({
@@ -129,12 +130,21 @@ export const Alert: FC<AlertViewProps> = (props) => {
129130
const renderIconCb = useCallback(() => {
130131
const Svg = icon;
131132

133+
const iconConfig = config?.icon;
134+
135+
const defaultIconSize = iconSize || iconConfig?.size || 72;
136+
const defaultIconColor = iconColor || iconConfig?.color || 'black';
137+
132138
return Svg ? (
133139
<View style={styles.iconContainer}>
134-
<Svg fill={iconColor} width={iconSize} height={iconSize} />
140+
<Svg
141+
fill={defaultIconColor}
142+
width={defaultIconSize}
143+
height={defaultIconSize}
144+
/>
135145
</View>
136146
) : null;
137-
}, [icon, iconColor, iconSize]);
147+
}, [icon, iconColor, iconSize, config]);
138148

139149
const renderDismissButtonCb = useCallback(() => {
140150
const defaultDismissButton = (

src/components/Alert/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ReactElement, FC } from 'react';
22
import type { ColorValue, StyleProp, TextStyle } from 'react-native';
3+
import type { AlertConfig } from '../../containers/AlertContainer/types';
34

45
type IconProps = {
56
fill?: ColorValue;
@@ -62,4 +63,5 @@ export type AlertViewProps<R = unknown> = Props<R> & {
6263
animationDuration: number;
6364
isHiding: boolean;
6465
resolve: (value?: R) => void;
66+
config?: AlertConfig;
6567
};

src/containers/AlertContainer/controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export const useController = ({ animationDuration, config }: Props) => {
156156
];
157157

158158
if (passedButtons?.length !== 2) {
159+
// eslint-disable-next-line no-console
159160
console.warn(
160161
`[React Native Alert Queue] Confirm props must have 2 buttons, got ${passedButtons?.length}`,
161162
alert

src/containers/AlertContainer/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ export type AlertConfig = {
4444
text: string;
4545
testID?: string;
4646
};
47+
icon?: {
48+
size?: number;
49+
color?: ColorValue;
50+
};
4751
};

0 commit comments

Comments
 (0)