Skip to main content

Toast

The Toast component in our library is a lightweight and non-intrusive user interface element used to display brief messages or notifications to users. It typically appears as a small rectangular pop-up that appears at the top or bottom of the screen for a short period before disappearing automatically. Toasts are commonly used to provide users with quick feedback, alerts, or confirmation messages after completing an action, such as saving a file, submitting a form, or successfully completing a task.

Usage

Basic usage

import React, {useState} from 'react';
import {Button, Toast} from 'rn-inkpad';

const MyComponent = () => {
const [visible, setVisible] = useState(false);

return (
<View>
<Toast
visible={visible}
text="Toast information"
setVisible={setVisible}
/>
<Button text="Show toast" onPress={() => setVisible(true)} />
</View>
);
};

Props

NameTypeRequiredDefaultDescription
textstringYESToast text.
visiblebooleanYESShow or hide toast.
backgroundColorstringNOrgba(0,0,0,0.7)Toast background color.
bottomnumberNO30Separation between the bottom and the component when the position of the component is bottom.
durationnumberNO3000Time in milliseconds in which the toast will appear.
fontSizenumberNOToast text font size.
iconstringNOToast icon.
position'bottom' | 'top'NOtopDetermines where the toast will appear from.
textColorstringNO#FFFFFFToast text color.
textStylesStyleProp<TextStyle>NOCustom text styles.
topnumberNO50Separation between the top and the component when the position of the component is top.
setVisible(visible: boolean) => voidYESFunction that controls the visibility of the toast.

Usage props

import React, {useState} from 'react';
import {View} from 'react-native';

import {Buttom, Toast} from 'rn-inkpad';

const MyComponent = () => {
const [visibleTop, setVisibleTop] = useState(false);
const [visibleBottom, setVisibleBottom] = useState(false);

return (
<View>
<Toast
backgroundColor="#DB504A"
fontSize={16}
icon="information-circle-outline"
text="Toast top information"
visible={visibleTop}
setVisible={setVisibleTop}
/>
<Toast
backgroundColor="#21295C"
fontSize={16}
icon="cafe"
position="bottom"
text="Toast bottom information"
visible={visibleBottom}
setVisible={setVisibleBottom}
/>
<Button
full
rounded
text="Show toast top"
onPress={() => setVisibleTop(true)}
/>
<Button
full
rounded
style={{marginTop: 20}}
text="Show toast bottom"
onPress={() => setVisibleBottom(true)}
/>
</View>
);
};

Example with props