Snackbar
Queued bottom (or top) messages with an optional action. Mount SnackbarProvider once and
call useSnackbar() anywhere below it. Messages are shown one after another.
API
const {show, hide, clear} = useSnackbar();
show('Saved'); // returns an id
show({text: 'Deleted', action: {text: 'Undo', onPress}, duration: 5000});
hide(); // hides the current one
hide(id); // removes a specific one (queued or shown)
clear(); // drops the queue
SnackbarProvider props
| Name | Type | Default | Description |
|---|---|---|---|
| position | 'top' | 'bottom' | bottom | Where snackbars appear. |
| offset | number | 24 | Distance from the screen edge. |
| duration | number | 3000 | Default auto-hide in milliseconds. |
| testID | string | Root testID (${testID}-action for the action). |
show() options
| Name | Type | Default | Description |
|---|---|---|---|
| text | string | Message. | |
| duration | number | provider duration | Auto-hide. 0 keeps it until dismissed. |
| action | {text: string; onPress: () => void} | Action button. Pressing it hides the snackbar. | |
| icon | IconProp | Leading icon. | |
| backgroundColor | string | #1F2937 | Background. |
| textColor | string | #FFFFFF | Text color. |
| actionColor | string | theme primary | Action text color. |