Snackbar
The Snackbar component provide brief feedback after an action through a message at the bottom of the screen. A Snackbar may contain an action, such as "Undo" or "Retry". Snackbars don't lock the app's main interface and are automatically dismissed after a while.
Usage
The following example displays a Snackbar message with a "Retry" button:
mobiscroll.snackbar({
message: "Connection timed out. Showing limited messages.",
button: {
text: 'Retry',
action: () => {
console.log('Retrying...');
}
}
});
Options
Explore the following API options that help you easily configure the Snackbar component.
animation
boolean | "pop" | "slide-down" | "slide-up"
Animation to use when the component is opened or closed.
Default value: undefined
button
{action?: () => void , icon?: string, text?: string}
Displays an action button on the snackbar. Properties:
text
: string - Text of the button.icon
: string - Icon of the button.action
: () => void - A function which executes when the button is clicked.
color
"success" | "primary" | "secondary" | "danger" | "warning" | "info"
Specifies the predefined background color of the message, each serving its own semantic purpose.
Default value: undefined
cssClass
string
Specifies a custom CSS class for the component.
Default value: undefined
display
"center" | "top" | "bottom"
Controls the positioning of the component.
Default value: undefined
duration
number | boolean
Specifies the display time of the message in milliseconds. If false
, the message will be persistent.
Default value: 3000
isOpen
boolean
Specifies if the component is opened or not. Use it together with the onClose event, by setting it
to false
when the component closes.
Default value: undefined
message
string
Message to present.
theme
string
Specifies the visual appearance of the component.
If it is 'auto'
or undefined
, the theme will automatically be chosen based on the platform.
If custom themes are also present, they will take precedence over the built in themes, e.g. if there's an iOS based custom theme,
it will be chosen on the iOS platform instead of the default iOS theme.
Supplied themes:
'ios'
- iOS theme'material'
- Material theme'windows'
- Windows theme
It's possible to modify theme colors or create custom themes.
Make sure that the theme you set is included in the downloaded package.
Default value: undefined
themeVariant
"auto" | "light" | "dark"
Controls which variant of the theme will be used (light or dark).
Possible values:
'light'
- Use the light variant of the theme.'dark'
- Use the dark variant of the theme.'auto'
orundefined
- Detect the preferred system theme on devices where this is supported.
To use the option with custom themes, make sure to create two custom themes, where the dark version has the same name as the light one,
suffixed with '-dark'
, e.g.: 'my-theme'
and 'my-theme-dark'
.
Default value: undefined
Events
The Snackbar component ships with different event hooks for deep customization. Events are triggered through the lifecycle of the component where you can tie in custom functionality and code.
onClose
(result: undefined) => void
Triggered when the component is closed.