# rn-animated-snackbar

> A react native snackbar component for Android and IOS

Latest version **1.0.1** (published 2021-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install rn-animated-snackbar
pnpm add rn-animated-snackbar
yarn add rn-animated-snackbar
bun add rn-animated-snackbar
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-03-21 |
| First published | 2021-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | amnpoosri |
| Maintainers | amnpoosri |
| Keywords | snackbar, snack bar, material, design, android, ios, notifications, react-native |

## Links

- npm: https://www.npmjs.com/package/rn-animated-snackbar
- Repository: https://github.com/s-group-dev/rn_animated_snackbar
- Issues: https://github.com/s-group-dev/rn_animated_snackbar/issues
- npm.io page: https://npm.io/package/rn-animated-snackbar

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-03-21
- 1.0.0 — 2021-02-25

## README

# rn-animated-snackbar

A snackbar component for Android and iOS

|                              Android                               |                              IOS                               |
| :----------------------------------------------------------------: | :------------------------------------------------------------: |
| <img src="docs/assets/snackbar_android.gif" alt="IOS" width="250"> | <img src="docs/assets/snackbar_ios.gif" alt="IOS" width="250"> |

## Installation

1. Install:

- Using [npm](https://www.npmjs.com/#getting-started): `npm install rn-animated-snackbar --save`
- Using [Yarn](https://yarnpkg.com/): `yarn add rn-animated-snackbar`

2. Import it in your JS:

   ```js
   import Snackbar from 'react-native-snackbar';
   ```

## Usage

```tsx
import React from 'react';
import {Button, View, StyleSheet, SafeAreaView} from 'react-native';
import Snackbar from 'rn-animated-snackbar';

const App = () => {
  const [visible, setVisible] = React.useState(false);
  const onToggleSnackBar = () => setVisible(!visible);
  const onDismissSnackBar = () => setVisible(false);
  return (
    <SafeAreaView style={styles.safeAreaContainer}>
      <View style={styles.container}>
        <Button
          title={visible ? 'Hide' : 'Show'}
          onPress={onToggleSnackBar}
          style={styles.buttonStyle}
        />
        <Snackbar
          visible={visible}
          onDismiss={onDismissSnackBar}
          text={'Hello World'}
          action={{
            label: 'Hide',
            onPress: () => {
              setVisible(true);
            },
          }}
          duration={Snackbar.LENGTH_MEDIUM}
          containerStyle={styles.snackbarContainer}
        />
      </View>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  safeAreaContainer: {
    flex: 1,
  },
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  snackbarContainer: {
    backgroundColor: '#484848',
    position: 'absolute',
    left: 0,
    right: 0,
    bottom: 0,
  },
});

export default App;
```

## Options

| Key              | Data type                  | Default value?          | Description                                                                                           |
| ---------------- | -------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------- |
| `visible`        | `boolean`                  | Required.               | Show or hide snackbar                                                                                 |
| `text`           | `style`                    | Required.               | The message to show.                                                                                  |
| `textStyle`      | `style`                    | `undefined`             | Text message style                                                                                    |
| `duration`       | number                     | `Snackbar.LENGTH_SHORT` | How long to display the Snackbar.                                                                     |
| `action`         | `object` (described below) | `undefined` (no button) | Optional config for the action button (described below).                                              |
| `onDismiss`      | `function`                 | Required                | Callback called when Snackbar is dismissed. The visible prop needs to be updated when this is called. |
| `containerStyle` | `style`                    | `undefined`             | Snackbar container style                                                                              |

Where `duration` can be one of the following (timing may vary based on device):

- `Snackbar.LENGTH_SHORT` (3s)
- `Snackbar.LENGTH_MEDIUM` (5s)
- `Snackbar.LENGTH_LONG` (10s)
- `Snackbar.LENGTH_INFINITY` (INFINITE)

The optional `action` object can contain the following options:

| Key                  | Data type  | Default value?                             | Description                                   |
| -------------------- | ---------- | ------------------------------------------ | --------------------------------------------- |
| `label`              | `string`   | Required.                                  | Label of the action button.                   |
| `accessibilityLabel` | `string`   | `undefined`                                | The color of the button text.                 |
| `labelStyle`         | `style`    | `undefined`                                | Label text style.                             |
| `onPress`            | `function` | `undefined` (Snackbar is simply dismissed) | A callback for when the user taps the button. |

---
_Source: https://npm.io/package/rn-animated-snackbar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
