Material Design "Snackbar" Component for Android and IOS

React Native Snackbar

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.
numberOfLines number 2 The max number of text lines to allow before ellipsizing.
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)

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.

Software development

If you want to help contribute to this library, here are local setup steps:

  1. Clone this git repo
  2. Install main dependencies: yarn install
  3. Set up the example app too: cd example && yarn install
  4. Within the example directory, react-native run-android to run it

The example app will update automatically when changing JS code. To see your changes in the example app after updating native library code:

  1. yarn install && react-native run-android in the example directory
  2. Type “rr” in the app to trigger a reload

Download Details:

Author: cooperka

Source Code: https://github.com/cooperka/react-native-snackbar

#react-native #react #mobile-apps

What is GEEK

Buddha Community

Material Design "Snackbar" Component for Android and IOS

Material Design "Snackbar" Component for Android and IOS

React Native Snackbar

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.
numberOfLines number 2 The max number of text lines to allow before ellipsizing.
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)

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.

Software development

If you want to help contribute to this library, here are local setup steps:

  1. Clone this git repo
  2. Install main dependencies: yarn install
  3. Set up the example app too: cd example && yarn install
  4. Within the example directory, react-native run-android to run it

The example app will update automatically when changing JS code. To see your changes in the example app after updating native library code:

  1. yarn install && react-native run-android in the example directory
  2. Type “rr” in the app to trigger a reload

Download Details:

Author: cooperka

Source Code: https://github.com/cooperka/react-native-snackbar

#react-native #react #mobile-apps

How to Add SnackBar | Android Studio

How to add snackbar in your android app.

#android studio #snackbar

Oda  Shields

Oda Shields

1625704980

Snackbar & Custom Snackbar in Kotlin

In this video, I will show you how to create and show snackbar in your apps.

Thanks for watching, subscribe, like and leave your comment…

Github ----- https://github.com/IsaiasCuvula
Linkedin ----- https://www.linkedin.com/in/isaias-bernardo-988a8a1a9/
Website ----- https://www.bersyte.com/
Twitter ----- https://twitter.com/ICuvula
Instagram ----- https://www.instagram.com/isaias_cuvula/
My App ---- https://play.google.com/store/apps/details?id=com.bersyte.berlist

#kotlin #AndroidDev #AndroidTutorial

#kotlin #custom snackbar #snackbar

Sasha  Hall

Sasha Hall

1635213600

Everything about Snackbar in Android Studio

Hey everyone
In this video I explained what is snackbar in android
Types of snackbar
How to use them
And everything about snackbar you will going to learn in this video

 
#android 

A Snackbar Component for React Native (android and IOS)

react-native-snackbar-component

A snackbar component for Android and iOS, customizable and simple.

Installation

npm install --save react-native-snackbar-component

Basic Usage

import SnackBar from 'react-native-snackbar-component'

Code

<SnackBar visible={true} textMessage="Hello There!" actionHandler={()=>{console.log("snackbar button clicked!")}} actionText="let's go"/>

Options

PropTypeEffectDefault Value
visiblebooleanShow or hide the snackbarnone
textMessagestring / functionThe main message text, can also supply a function returning JSX to render custom message UInone
actionHandlerfunctionFunction to be called when button is pressed, if absent no action button is shownnone
actionTextmessageThe text of action button, will be uppercased automaticallynone
backgroundColorcolorThe background color of snackbar#484848
accentColorcolorThe color of action button textorange
messageColorcolorThe color of main message text#FFFFFF
distanceCallbackfunctionFunction to be caled whenever snackbar moves in and out or changes layout, the function will be supplied a number indicating distance taken up by snackbar on bottom or top, based on position.(distance) => {}
positionstringThe position of the snackbar: top, bottombottom
top / bottom / left / rightnumberUse these to position the snackbar0
autoHidingTimenumberHow many milliseconds the snackbar will be hidden0 (Do not hide automatically)
containerStyleobjectOverride or add style to the root container View{}
messageStyleobjectOverride or add style to the message Text{}
actionStyleobjectOverride or add style to the action button Text{}

Note

  • When visible prop is changed, the snackbar will be animated in/out of screen
  • The snackbar will not auto-dismiss by itself, for auto-dismiss use setTimeout() and change value passed to prop to false,
    OR you can set autoHidingTime to any particular value to hide the snackbar itself, although you will need to reset visible to false manually after the autoHidingTime period is over, since visible is controlled from outside.
  • This works great together with react-native-fab. See demo for example and instructions how to.

Demo

Snackbar demo With fab

See Google Material Design for more info on Snackbars.

Download Details:
Author: SiDevesh
Source Code: https://github.com/SiDevesh/React-Native-SnackBar-Component
License: MIT License

#react  #reactnative  #javascript