Coder Social home page Coder Social logo

mrbrentkelly / react-native-snackbar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cooperka/react-native-snackbar

0.0 1.0 0.0 1.71 MB

:bento: Material Design "Snackbar" component for Android and iOS.

License: Other

Java 24.17% JavaScript 21.74% Objective-C 40.19% Ruby 8.67% Shell 0.50% Starlark 4.72%

react-native-snackbar's Introduction

React Native Snackbar

Build status npm downloads npm version Latest GitHub tag

Material Design "Snackbar" component for Android and iOS. Supports custom colors, fonts, and languages.

Snackbar screenshot

Snackbars are used for displaying a brief message to the user, along with an optional action. They animate up from the bottom of the screen and then disappear shortly afterward.

See Google's Material Design guidelines for more info on Snackbars and when to use them.

How it works

Snackbar.show({
  text: 'Hello world',
  duration: Snackbar.LENGTH_SHORT,
});

Or, to include an action button:

Snackbar.show({
  text: 'Hello world',
  duration: Snackbar.LENGTH_INDEFINITE,
  action: {
    text: 'UNDO',
    textColor: 'green',
    onPress: () => { /* Do something. */ },
  },
});

Installation

  1. Install:

    • Using npm: npm install react-native-snackbar --save
    • Using Yarn: yarn add react-native-snackbar
  2. Link:

    • RN >= 0.60 supports autolinking: first cd ios && pod install && cd ..
    • RN < 0.60: react-native link react-native-snackbar
    • Or if that fails, link manually using these steps
    • Note that because this is a native module, Expo does not support it -- to use with Expo you need to eject to ExpoKit
  3. Import it in your JS:

    import Snackbar from 'react-native-snackbar';

Usage

Snackbar.show(options)

Shows a Snackbar, dismissing any existing Snackbar first. Accepts an object with the following options:

Key Data type Default value? Description
text string Required. The message to show.
duration See below Snackbar.LENGTH_SHORT How long to display the Snackbar.
textColor string or style 'white' The color of the message text.
backgroundColor string or style undefined (dark gray) The background color for the whole Snackbar.
fontFamily string undefined [Android only] The basename of a .ttf font from assets/fonts/ (see setup guide and example app, remember to react-native link after).
rtl boolean false [Android only, API 17+] Whether the Snackbar should render right-to-left (requires android:supportsRtl="true", see setup guide and example app).
action object (described below) undefined (no button) Optional config for the action button (described below).

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

  • Snackbar.LENGTH_SHORT (just over a second)
  • Snackbar.LENGTH_LONG (about three seconds)
  • Snackbar.LENGTH_INDEFINITE (stays on screen until dismissed, replaced, or action button is tapped)

Note: the text will ellipsize after 2 lines of text on most platforms. See #110 if you need to display more lines.

The optional action object can contain the following options:

Key Data type Default value? Description
text string Required. The button text.
textColor string or style 'white' The color of the button text.
onPress function undefined (Snackbar is simply dismissed) A callback for when the user taps the button.

Deprecation note: The old keys title and color have been replaced by text and textColor for consistency. The old keys will continue to work for now but are deprecated and may be removed at any time.

Snackbar.dismiss()

Dismisses any existing Snackbars.

Troubleshooting

Snackbar not appearing [Android]

The Snackbar is designed to attach to whatever view is on top of your screen when show is called. If that view happens to be a temporary alert modal or some other view that goes away, you'll never see the Snackbar.

A workaround in some cases is to use setTimeout to show the Snackbar a few seconds later after the modal is gone. See issue #28 for further discussion. If you want to submit a PR to improve the view-finding logic, feel free.

Undefined import

If you see errors similar to Cannot read property 'LENGTH_LONG' of undefined or Undefined not an object (NativeModules.RNSnackbar), please refer to issue #43 for help.

Compiling [Android]

If you have issues compiling for Android after linking this library, please try updating your Gradle and Android configs to the latest versions. For example:

In your android/build.gradle:

  • com.android.tools.build:gradle:3.4.1 (or higher)

In your android/app/build.gradle:

  • compileSdkVersion 28 (or higher)
  • buildToolsVersion "28.0.3" (or higher)

Compiling [iOS]

Make sure your Deployment Target is iOS 9.0 or above.

react-native-snackbar's People

Contributors

abartolo avatar abrahambotros avatar ahanriat avatar alijamaliz avatar bhullnatik avatar boceto1 avatar brunolemos avatar chocky335 avatar cooperka avatar dantman avatar dependabot[bot] avatar gregoiredumas avatar gunnarak avatar iroachie avatar jacque006 avatar jazz747 avatar jeffgukang avatar mpatric avatar mrbrentkelly avatar pozdena avatar rafalolszewski94 avatar remstos avatar sandromachado avatar sonicdoe avatar sudendrakl avatar tcodes0 avatar testauthbasic avatar thomasw avatar wodka avatar xdimota7x avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.