You can customize existing toast types or create entirely new ones by providing a config object to the Toast component at your app's entry point.
There are two ways to create a custom layout:
- Modify existing types: Use the built-in
BaseToast, SuccessToast, ErrorToast, or InfoToast components and pass them custom styles via props. - Build from scratch: Create a new component function that receives
text1, text2, and props. Any custom data passed to the props key in the Toast.show() method will be available in this object.
To use a custom type, ensure the key in your toastConfig object matches the type string passed to Toast.show().
// 1. Define the config
const toastConfig = {
// Overwriting an existing type
success: (props) => (
<BaseToast
{...props}
style={{ borderLeftColor: 'pink' }}
/>
),
// Creating a completely new type
tomatoToast: ({ text1, props }) => (
<View style={{ height: 60, width: '100%', backgroundColor: 'tomato' }}>
<Text>{text1}</Text>
<Text>{props.uuid}</Text>
</View>
)
};
// 2. Pass config to the Toast component
export function App() {
return (
<>
{/* ... other components ... */}
<Toast config={toastConfig} />
</>
);
}
// 3. Trigger the custom type
Toast.show({
type: 'tomatoToast',
props: { uuid: 'bba1a7d0-6ab2-4a0a-a76e-ebbe05ae6d70' }
});