UNPKG

react-native-snackbar

Version:

Material Design "Snackbar" component for Android and iOS.

81 lines (77 loc) 2.55 kB
"use strict"; import { processColor } from 'react-native'; import NativeSnackbar from "./NativeSnackbar.js"; /** * An optional, actionable button on the Snackbar. */ /** * Snackbar configuration options. */ function processColorOrThrow(color) { if (color == null) { return -1; } const processed = processColor(color); if (typeof processed === 'number') { return processed; } throw new Error(`Failed to parse color '${String(color)}'`); } const constants = NativeSnackbar.getConstants(); export const Snackbar = { /** * Snackbar duration of about one second (varies per device). */ LENGTH_SHORT: constants.LENGTH_SHORT, /** * Snackbar duration of about three seconds (varies per device). */ LENGTH_LONG: constants.LENGTH_LONG, /** * Snackbar duration that lasts forever (until dismissed, replaced, or action button is tapped). */ LENGTH_INDEFINITE: constants.LENGTH_INDEFINITE, /** * Indicates that the Snackbar was dismissed via a swipe. */ DISMISS_EVENT_SWIPE: constants.DISMISS_EVENT_SWIPE, /** * Indicates that the Snackbar was dismissed via an action click. */ DISMISS_EVENT_ACTION: constants.DISMISS_EVENT_ACTION, /** * Indicates that the Snackbar was dismissed via a timeout. */ DISMISS_EVENT_TIMEOUT: constants.DISMISS_EVENT_TIMEOUT, /** * Indicates that the Snackbar was dismissed via a call to {@link #dismiss()}. */ DISMISS_EVENT_MANUAL: constants.DISMISS_EVENT_MANUAL, /** * Indicates that the Snackbar was dismissed from a new Snackbar being shown. */ DISMISS_EVENT_CONSECUTIVE: constants.DISMISS_EVENT_CONSECUTIVE, /** * Indicates that Snackbar appears. */ SHOW_EVENT: constants.SHOW_EVENT, /** * Shows a native Snackbar component. */ show(options) { NativeSnackbar.show(options.text, options.duration ?? Snackbar.LENGTH_SHORT, options.numberOfLines ?? 2, options.textAlignCenter ?? false, options.marginBottom ?? 0, processColorOrThrow(options.textColor ?? 'white'), processColorOrThrow(options.backgroundColor), options.fontFamily ?? '', options.rtl ?? false, options.action != null, options.action?.text ?? '', processColorOrThrow(options.action?.textColor ?? 'white'), options.action?.onPress ?? (() => {})); }, /** * Dismisses any and all active Snackbars. */ dismiss() { NativeSnackbar.dismiss(); }, /** * Observe Snackbar visibility changes. */ onSnackbarVisibility(handler) { return NativeSnackbar.onSnackbarVisibility(handler); } }; //# sourceMappingURL=index.js.map