├── .gitignore ├── .npmignore ├── Example ├── .buckconfig ├── .flowconfig ├── .gitattributes ├── .gitignore ├── .watchmanconfig ├── App.js ├── __tests__ │ └── App.js ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── build_defs.bzl │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── keystores │ │ ├── BUCK │ │ └── debug.keystore.properties │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── package.json ├── snackbar.gif └── yarn.lock ├── LICENSE ├── README.md ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── lugg │ └── ReactSnackbar │ ├── ReactSnackbarModule.java │ └── ReactSnackbarPackage.java ├── index.android.js ├── index.ios.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .npmignore 2 | Example 3 | -------------------------------------------------------------------------------- /Example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /Example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | 16 | ; Ignore polyfills 17 | .*/Libraries/polyfills/.* 18 | 19 | ; Ignore metro 20 | .*/node_modules/metro/.* 21 | 22 | [include] 23 | 24 | [libs] 25 | node_modules/react-native/Libraries/react-native/react-native-interface.js 26 | node_modules/react-native/flow/ 27 | node_modules/react-native/flow-github/ 28 | 29 | [options] 30 | emoji=true 31 | 32 | esproposal.optional_chaining=enable 33 | esproposal.nullish_coalescing=enable 34 | 35 | module.system=haste 36 | module.system.haste.use_name_reducers=true 37 | # get basename 38 | module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1' 39 | # strip .js or .js.flow suffix 40 | module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1' 41 | # strip .ios suffix 42 | module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1' 43 | module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1' 44 | module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1' 45 | module.system.haste.paths.blacklist=.*/__tests__/.* 46 | module.system.haste.paths.blacklist=.*/__mocks__/.* 47 | module.system.haste.paths.blacklist=/node_modules/react-native/Libraries/Animated/src/polyfills/.* 48 | module.system.haste.paths.whitelist=/node_modules/react-native/Libraries/.* 49 | 50 | munge_underscores=true 51 | 52 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 53 | 54 | module.file_ext=.js 55 | module.file_ext=.jsx 56 | module.file_ext=.json 57 | module.file_ext=.native.js 58 | 59 | suppress_type=$FlowIssue 60 | suppress_type=$FlowFixMe 61 | suppress_type=$FlowFixMeProps 62 | suppress_type=$FlowFixMeState 63 | 64 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 65 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 66 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 67 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 68 | 69 | [version] 70 | ^0.86.0 71 | -------------------------------------------------------------------------------- /Example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /Example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://docs.fastlane.tools/best-practices/source-control/ 50 | 51 | */fastlane/report.xml 52 | */fastlane/Preview.html 53 | */fastlane/screenshots 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | -------------------------------------------------------------------------------- /Example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /Example/App.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import {Platform, StyleSheet, Text, TouchableOpacity, View} from 'react-native'; 3 | import Snackbar from 'react-native-android-snackbar'; 4 | 5 | export default class App extends Component<{}> { 6 | _onPressCustomSnackbar() { 7 | Snackbar.show('This has a custom action:', { 8 | actionColor: '#FFCA00', 9 | actionLabel: 'CLICK', 10 | actionCallback: (() => Snackbar.show('Nice click!')) 11 | }); 12 | }; 13 | 14 | render() { 15 | return ( 16 | 17 | Snackbar.show('Hello World!')}> 18 | 19 | Click to show short snackbar 20 | 21 | 22 | Snackbar.show('This snackbar stays on screen for longer', { duration: Snackbar.LONG })}> 23 | 24 | Click to show longer snackbar 25 | 26 | 27 | Snackbar.show('Click to dismiss', { duration: Snackbar.UNTIL_CLICK })}> 28 | 29 | Click to show permanent snackbar 30 | 31 | 32 | 33 | 34 | Click to show snackbar with custom action 35 | 36 | 37 | 38 | ); 39 | } 40 | } 41 | 42 | const Styles = StyleSheet.create({ 43 | Container: { 44 | flex: 1, 45 | justifyContent: 'center', 46 | alignItems: 'center', 47 | backgroundColor: '#F5FCFF', 48 | }, 49 | Label: { 50 | fontSize: 18, 51 | marginBottom: 16, 52 | }, 53 | }); 54 | -------------------------------------------------------------------------------- /Example/__tests__/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | * @lint-ignore-every XPLATJSCOPYRIGHT1 4 | */ 5 | 6 | import 'react-native'; 7 | import React from 'react'; 8 | import App from '../App'; 9 | 10 | // Note: test renderer must be required after react-native. 11 | import renderer from 'react-test-renderer'; 12 | 13 | it('renders correctly', () => { 14 | renderer.create(); 15 | }); 16 | -------------------------------------------------------------------------------- /Example/android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.example", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.example", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /Example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | import com.android.build.OutputFile 4 | 5 | /** 6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 7 | * and bundleReleaseJsAndAssets). 8 | * These basically call `react-native bundle` with the correct arguments during the Android build 9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 10 | * bundle directly from the development server. Below you can see all the possible configurations 11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 12 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 13 | * 14 | * project.ext.react = [ 15 | * // the name of the generated asset file containing your JS bundle 16 | * bundleAssetName: "index.android.bundle", 17 | * 18 | * // the entry file for bundle generation 19 | * entryFile: "index.android.js", 20 | * 21 | * // whether to bundle JS and assets in debug mode 22 | * bundleInDebug: false, 23 | * 24 | * // whether to bundle JS and assets in release mode 25 | * bundleInRelease: true, 26 | * 27 | * // whether to bundle JS and assets in another build variant (if configured). 28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 29 | * // The configuration property can be in the following formats 30 | * // 'bundleIn${productFlavor}${buildType}' 31 | * // 'bundleIn${buildType}' 32 | * // bundleInFreeDebug: true, 33 | * // bundleInPaidRelease: true, 34 | * // bundleInBeta: true, 35 | * 36 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 37 | * // for example: to disable dev mode in the staging build type (if configured) 38 | * devDisabledInStaging: true, 39 | * // The configuration property can be in the following formats 40 | * // 'devDisabledIn${productFlavor}${buildType}' 41 | * // 'devDisabledIn${buildType}' 42 | * 43 | * // the root of your project, i.e. where "package.json" lives 44 | * root: "../../", 45 | * 46 | * // where to put the JS bundle asset in debug mode 47 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 48 | * 49 | * // where to put the JS bundle asset in release mode 50 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 51 | * 52 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 53 | * // require('./image.png')), in debug mode 54 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 55 | * 56 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 57 | * // require('./image.png')), in release mode 58 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 59 | * 60 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 61 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 62 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 63 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 64 | * // for example, you might want to remove it from here. 65 | * inputExcludes: ["android/**", "ios/**"], 66 | * 67 | * // override which node gets called and with what additional arguments 68 | * nodeExecutableAndArgs: ["node"], 69 | * 70 | * // supply additional arguments to the packager 71 | * extraPackagerArgs: [] 72 | * ] 73 | */ 74 | 75 | project.ext.react = [ 76 | entryFile: "index.js" 77 | ] 78 | 79 | apply from: "../../node_modules/react-native/react.gradle" 80 | 81 | /** 82 | * Set this to true to create two separate APKs instead of one: 83 | * - An APK that only works on ARM devices 84 | * - An APK that only works on x86 devices 85 | * The advantage is the size of the APK is reduced by about 4MB. 86 | * Upload all the APKs to the Play Store and people will download 87 | * the correct one based on the CPU architecture of their device. 88 | */ 89 | def enableSeparateBuildPerCPUArchitecture = false 90 | 91 | /** 92 | * Run Proguard to shrink the Java bytecode in release builds. 93 | */ 94 | def enableProguardInReleaseBuilds = false 95 | 96 | android { 97 | compileSdkVersion rootProject.ext.compileSdkVersion 98 | buildToolsVersion rootProject.ext.buildToolsVersion 99 | 100 | defaultConfig { 101 | applicationId "com.example" 102 | minSdkVersion rootProject.ext.minSdkVersion 103 | targetSdkVersion rootProject.ext.targetSdkVersion 104 | versionCode 1 105 | versionName "1.0" 106 | } 107 | splits { 108 | abi { 109 | reset() 110 | enable enableSeparateBuildPerCPUArchitecture 111 | universalApk false // If true, also generate a universal APK 112 | include "armeabi-v7a", "x86", "arm64-v8a" 113 | } 114 | } 115 | buildTypes { 116 | release { 117 | minifyEnabled enableProguardInReleaseBuilds 118 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 119 | } 120 | } 121 | // applicationVariants are e.g. debug, release 122 | applicationVariants.all { variant -> 123 | variant.outputs.each { output -> 124 | // For each separate APK per architecture, set a unique version code as described here: 125 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 126 | def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3] 127 | def abi = output.getFilter(OutputFile.ABI) 128 | if (abi != null) { // null for the universal-debug, universal-release variants 129 | output.versionCodeOverride = 130 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 131 | } 132 | } 133 | } 134 | } 135 | 136 | dependencies { 137 | implementation fileTree(dir: "libs", include: ["*.jar"]) 138 | implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" 139 | implementation "com.facebook.react:react-native:+" // From node_modules 140 | implementation project(':react-native-android-snackbar') 141 | 142 | } 143 | 144 | // Run this once to be able to run the application with BUCK 145 | // puts all compile dependencies into folder libs for BUCK to use 146 | task copyDownloadableDepsToLibs(type: Copy) { 147 | from configurations.compile 148 | into 'libs' 149 | } 150 | -------------------------------------------------------------------------------- /Example/android/app/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /Example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "Example"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Example/android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.shell.MainReactPackage; 9 | import com.facebook.soloader.SoLoader; 10 | 11 | import com.lugg.ReactSnackbar.ReactSnackbarPackage; 12 | 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 19 | @Override 20 | public boolean getUseDeveloperSupport() { 21 | return BuildConfig.DEBUG; 22 | } 23 | 24 | @Override 25 | protected List getPackages() { 26 | return Arrays.asList( 27 | new MainReactPackage(), 28 | new ReactSnackbarPackage() 29 | ); 30 | } 31 | 32 | @Override 33 | protected String getJSMainModuleName() { 34 | return "index"; 35 | } 36 | }; 37 | 38 | @Override 39 | public ReactNativeHost getReactNativeHost() { 40 | return mReactNativeHost; 41 | } 42 | 43 | @Override 44 | public void onCreate() { 45 | super.onCreate(); 46 | SoLoader.init(this, /* native exopackage */ false); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Example 3 | 4 | -------------------------------------------------------------------------------- /Example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext { 5 | buildToolsVersion = "28.0.2" 6 | minSdkVersion = 16 7 | compileSdkVersion = 28 8 | targetSdkVersion = 27 9 | supportLibVersion = "28.0.0" 10 | } 11 | repositories { 12 | google() 13 | jcenter() 14 | } 15 | dependencies { 16 | classpath 'com.android.tools.build:gradle:3.2.1' 17 | 18 | // NOTE: Do not place your application dependencies here; they belong 19 | // in the individual module build.gradle files 20 | } 21 | } 22 | 23 | allprojects { 24 | repositories { 25 | mavenLocal() 26 | google() 27 | jcenter() 28 | maven { 29 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 30 | url "$rootDir/../node_modules/react-native/android" 31 | } 32 | } 33 | } 34 | 35 | 36 | task wrapper(type: Wrapper) { 37 | gradleVersion = '4.7' 38 | distributionUrl = distributionUrl.replace("bin", "all") 39 | } 40 | -------------------------------------------------------------------------------- /Example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip 6 | -------------------------------------------------------------------------------- /Example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /Example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /Example/android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = "debug", 3 | properties = "debug.keystore.properties", 4 | store = "debug.keystore", 5 | visibility = [ 6 | "PUBLIC", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /Example/android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /Example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Example' 2 | 3 | include ':react-native-android-snackbar' 4 | project(':react-native-android-snackbar').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-snackbar/android') 5 | 6 | include ':app' 7 | -------------------------------------------------------------------------------- /Example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "displayName": "Example" 4 | } -------------------------------------------------------------------------------- /Example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ["module:metro-react-native-babel-preset"] 3 | } 4 | -------------------------------------------------------------------------------- /Example/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | * @lint-ignore-every XPLATJSCOPYRIGHT1 4 | */ 5 | 6 | import {AppRegistry} from 'react-native'; 7 | import App from './App'; 8 | import {name as appName} from './app.json'; 9 | 10 | AppRegistry.registerComponent(appName, () => App); 11 | -------------------------------------------------------------------------------- /Example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SnackbarExample", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start", 7 | "test": "jest" 8 | }, 9 | "dependencies": { 10 | "react": "16.6.3", 11 | "react-native": "0.58.3", 12 | "react-native-android-snackbar": "file:../" 13 | }, 14 | "devDependencies": { 15 | "babel-core": "^7.0.0-bridge.0", 16 | "babel-jest": "24.1.0", 17 | "jest": "24.1.0", 18 | "metro-react-native-babel-preset": "0.51.1", 19 | "react-test-renderer": "16.6.3" 20 | }, 21 | "jest": { 22 | "preset": "react-native" 23 | } 24 | } -------------------------------------------------------------------------------- /Example/snackbar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lugg/react-native-android-snackbar/3ef5c0778904f021e805b0c8785c6667cb7987c7/Example/snackbar.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Lugg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Snackbar for React Native in Android 2 | 3 | Expose the [Snackbar android widget](http://developer.android.com/reference/android/support/design/widget/Snackbar.html) for react-native apps. 4 | 5 | ![Snackbar demo](/Example/snackbar.gif?raw=true) 6 | 7 | Snackbar provides a lightweight feedback to users about an operation, such as saving a form or deleting a message. They are similar to Toasts, but are a bit more prominent and customizable. 8 | 9 | Fore more info please refer to the [Google design spec on Snackbars](https://www.google.com/design/spec/components/snackbars-toasts.html#). 10 | 11 | 12 | ## Usage 13 | 14 | Require it: 15 | 16 | ```js 17 | import Snackbar from 'react-native-android-snackbar'; 18 | ``` 19 | 20 | Then call: 21 | 22 | ``` 23 | Snackbar.show('Hello World!', options); 24 | ``` 25 | 26 | Available options: 27 | 28 | - `duration`: one of: `Snackbar.SHORT`, `Snackbar.LONG`, `Snackbar.INDEFINITE` or `Snackbar.UNTIL_CLICK` 29 | - `actionLabel`: text to show at the right of the snackbar 30 | - `actionColor`: color of the action text in the snackbar. Like `red` or `#FFCA00` 31 | - `actionCallback`: function to be evoked after the user clicks the snackbar. Keep in mind the snackbar will automatically close just before this function call 32 | 33 | [Check full example](Example/index.android.js). 34 | 35 | To dismiss the currently active Snackbar early (for example, when changing scenes in your app), you can call: 36 | 37 | ```js 38 | Snackbar.dismiss(); 39 | ``` 40 | 41 | ## Setup 42 | 43 | 1. Include this module in `android/settings.gradle`: 44 | 45 | ``` 46 | include ':react-native-android-snackbar' 47 | project(':react-native-android-snackbar').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-snackbar/android') 48 | include ':app' 49 | ``` 50 | 51 | 2. Add a dependency to your app build in `android/app/build.gradle`: 52 | 53 | ``` 54 | dependencies { 55 | ... 56 | implementation project(':react-native-android-snackbar') 57 | } 58 | ``` 59 | 60 | 3. Change your main application to add a new package, in `android/app/src/main/.../MainApplication.java`: 61 | 62 | ```java 63 | import com.lugg.ReactSnackbar.ReactSnackbarPackage; // Add new import 64 | 65 | public class MainApplication extends Application implements ReactApplication { 66 | ... 67 | 68 | @Override 69 | protected List getPackages() { 70 | return Arrays.asList( 71 | new MainReactPackage(), 72 | new ReactSnackbarPackage() // Add the package here 73 | ); 74 | } 75 | } 76 | ``` 77 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | def safeExtGet(prop, fallback) { 2 | rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback 3 | } 4 | 5 | buildscript { 6 | repositories { 7 | jcenter() 8 | } 9 | 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:1.3.0' 12 | } 13 | } 14 | 15 | apply plugin: 'com.android.library' 16 | 17 | android { 18 | compileSdkVersion safeExtGet('compileSdkVersion', 27) 19 | buildToolsVersion safeExtGet('buildToolsVersion', '27.0.3') 20 | 21 | defaultConfig { 22 | minSdkVersion safeExtGet('minSdkVersion', 16) 23 | targetSdkVersion safeExtGet('targetSdkVersion', 27) 24 | versionCode 1 25 | versionName "1.0" 26 | } 27 | lintOptions { 28 | abortOnError false 29 | } 30 | } 31 | 32 | repositories { 33 | mavenCentral() 34 | } 35 | 36 | dependencies { 37 | implementation 'com.facebook.react:react-native:+' 38 | implementation "com.android.support:design:${safeExtGet('supportLibVersion', '27.1.1')}" 39 | } 40 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /android/src/main/java/com/lugg/ReactSnackbar/ReactSnackbarModule.java: -------------------------------------------------------------------------------- 1 | package com.lugg.ReactSnackbar; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | import android.os.Handler; 6 | import android.support.annotation.Nullable; 7 | import android.support.design.widget.Snackbar; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | 11 | import com.facebook.react.modules.core.DeviceEventManagerModule; 12 | import com.facebook.react.bridge.ReactApplicationContext; 13 | import com.facebook.react.bridge.ReactContext; 14 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 15 | import com.facebook.react.bridge.ReactMethod; 16 | import com.facebook.react.bridge.ReadableMap; 17 | import com.facebook.react.bridge.Callback; 18 | import com.facebook.react.bridge.WritableMap; 19 | 20 | import java.util.Map; 21 | import java.util.HashMap; 22 | 23 | public class ReactSnackbarModule extends ReactContextBaseJavaModule { 24 | private Snackbar mSnackbar = null; 25 | 26 | private static final String LENGTH_SHORT = "SHORT"; 27 | private static final String LENGTH_LONG = "LONG"; 28 | private static final String LENGTH_INDEFINITE = "INDEFINITE"; 29 | 30 | // Events which will be posted to the JS module 31 | private static final String EVENT_HIDE = "snackbarHide"; 32 | private static final String EVENT_HIDDEN = "snackbarHidden"; 33 | private static final String EVENT_SHOW = "snackbarShow"; 34 | private static final String EVENT_SHOWN = "snackbarShown"; 35 | 36 | /** 37 | * @hack 38 | * 39 | * Durations of animations and show constants. 40 | * 41 | * Taken from Android source code. This sucks because if they change, we'll 42 | * have to update these. Unfortunately there doesn't seem to be anyway to get 43 | * these values programmatically. 44 | * 45 | * https://github.com/android/platform_frameworks_support/blob/62eb3105e51335cf9074a5506d8d2b220aeb95dc/design/src/android/support/design/widget/Snackbar.java 46 | */ 47 | private static final int ANIMATION_DURATION = 250; 48 | private static final int ANIMATION_FADE_DURATION = 180; 49 | private static final int DURATION_SHORT_MS = 1500; 50 | private static final int DURATION_LONG_MS = 2750; 51 | 52 | private static final int COLOR_BACKGROUND = -13487566; // #323232 53 | private static final int COLOR_TEXT = Color.WHITE; 54 | 55 | private ReactContext mContext; 56 | 57 | public ReactSnackbarModule(ReactApplicationContext reactContext) { 58 | super(reactContext); 59 | 60 | mContext = reactContext; 61 | } 62 | 63 | /** 64 | * Delivers an event to the JS module. 65 | * 66 | * @param eventType the event type, such the constant EVENT_SHOW 67 | * @param params map of event parameters that the JS will receive 68 | */ 69 | private void sendEvent(String eventType, @Nullable WritableMap params) { 70 | mContext 71 | .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 72 | .emit(eventType, params); 73 | } 74 | 75 | /** 76 | * Sends EVENT_HIDE to the JS module after the specified delay 77 | * 78 | * @param delayMs delay before sending EVENT_HIDE, in ms 79 | */ 80 | private void setupDelayedHideEvent(int delayMs) { 81 | final Handler handler = new Handler(); 82 | handler.postDelayed(new Runnable() { 83 | @Override 84 | public void run() { 85 | 86 | // If Snackbar is not already dismissed, fire EVENT_HIDE 87 | if (mSnackbar != null && mSnackbar.isShown()) { 88 | ReactSnackbarModule.this.sendEvent(EVENT_HIDE, null); 89 | } 90 | } 91 | }, delayMs); 92 | } 93 | 94 | @Override 95 | public String getName() { 96 | return "SnackbarAndroid"; 97 | } 98 | 99 | @Override 100 | public Map getConstants() { 101 | final Map constants = new HashMap<>(); 102 | constants.put(LENGTH_SHORT, Snackbar.LENGTH_SHORT); 103 | constants.put(LENGTH_LONG, Snackbar.LENGTH_LONG); 104 | constants.put(LENGTH_INDEFINITE, Snackbar.LENGTH_INDEFINITE); 105 | constants.put("EVENT_HIDE", EVENT_HIDE); 106 | constants.put("EVENT_HIDDEN", EVENT_HIDDEN); 107 | constants.put("EVENT_SHOW", EVENT_SHOW); 108 | constants.put("EVENT_SHOWN", EVENT_SHOWN); 109 | constants.put("ANIMATION_DURATION", ANIMATION_DURATION); 110 | constants.put("ANIMATION_FADE_DURATION", ANIMATION_FADE_DURATION); 111 | return constants; 112 | } 113 | 114 | @ReactMethod 115 | public void show(String message, final int length, boolean hideOnClick, int actionColor, String actionLabel, final Callback actionCallback) { 116 | final Activity activity = getCurrentActivity(); 117 | 118 | if (activity == null) return; 119 | 120 | View view = activity.findViewById(android.R.id.content); 121 | mSnackbar = Snackbar.make(view, message, length); 122 | 123 | mSnackbar.setCallback(new Snackbar.Callback() { 124 | /** 125 | * When the Snackbar is hidden, fire EVENT_HIDDEN to the JS module 126 | * @todo send event in params 127 | * 128 | * @param snackbar the snackbar which was hidden 129 | * @param event one of the Snackbar's event type constants 130 | */ 131 | public void onDismissed(Snackbar snackbar, int event) { 132 | ReactSnackbarModule.this.sendEvent(EVENT_HIDDEN, null); 133 | } 134 | 135 | /** 136 | * When the Snackbar is shown, fire EVENT_SHOWN to the JS module 137 | */ 138 | public void onShown(Snackbar snackbar) { 139 | ReactSnackbarModule.this.sendEvent(EVENT_SHOWN, null); 140 | 141 | /* Setup a delay for firing EVENT_HIDE after the specified show duration 142 | * expires, provided the length is not LENGTH_INDEFINITE (-2) */ 143 | if (length > Snackbar.LENGTH_INDEFINITE) { 144 | switch (length) { 145 | case Snackbar.LENGTH_SHORT: 146 | setupDelayedHideEvent(DURATION_SHORT_MS); 147 | break; 148 | case Snackbar.LENGTH_LONG: 149 | setupDelayedHideEvent(DURATION_LONG_MS); 150 | break; 151 | default: 152 | setupDelayedHideEvent(length); 153 | } 154 | } 155 | } 156 | }); 157 | 158 | // enforce snackbar background/text color so it doesn't inherit from styles.xml 159 | View snackbarView = mSnackbar.getView(); 160 | snackbarView.setBackgroundColor(COLOR_BACKGROUND); 161 | TextView textView = (TextView) snackbarView.findViewById(R.id.snackbar_text); 162 | textView.setTextColor(COLOR_TEXT); 163 | 164 | // Add a state change listener for firing EVENT_SHOW 165 | snackbarView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { 166 | @Override 167 | public void onViewAttachedToWindow(View v) { 168 | ReactSnackbarModule.this.sendEvent(EVENT_SHOW, null); 169 | } 170 | 171 | @Override 172 | public void onViewDetachedFromWindow(View v) { } 173 | }); 174 | 175 | // set a custom action color 176 | mSnackbar.setActionTextColor(actionColor); 177 | 178 | if (hideOnClick) { 179 | mSnackbar.setAction("Dismiss", new View.OnClickListener() { 180 | @Override 181 | public void onClick(View v) { 182 | ReactSnackbarModule.this.dismiss(); 183 | } 184 | }); 185 | } 186 | else if (actionLabel != null && actionCallback != null) { 187 | mSnackbar.setAction(actionLabel, new View.OnClickListener() { 188 | @Override 189 | public void onClick(View v) { 190 | ReactSnackbarModule.this.dismiss(); 191 | actionCallback.invoke(); 192 | } 193 | }); 194 | } 195 | 196 | mSnackbar.show(); 197 | } 198 | 199 | @ReactMethod 200 | public void dismiss() { 201 | if (mSnackbar == null) { 202 | return; 203 | } 204 | 205 | sendEvent(EVENT_HIDE, null); 206 | mSnackbar.dismiss(); 207 | mSnackbar = null; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /android/src/main/java/com/lugg/ReactSnackbar/ReactSnackbarPackage.java: -------------------------------------------------------------------------------- 1 | package com.lugg.ReactSnackbar; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.JavaScriptModule; 5 | import com.facebook.react.bridge.NativeModule; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.react.uimanager.ViewManager; 8 | 9 | import java.util.Arrays; 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | public class ReactSnackbarPackage implements ReactPackage { 14 | public List createNativeModules(ReactApplicationContext reactContext) { 15 | return Arrays.asList( 16 | new ReactSnackbarModule(reactContext) 17 | ); 18 | } 19 | 20 | public List> createJSModules() { 21 | return Collections.emptyList(); 22 | } 23 | 24 | public List createViewManagers(ReactApplicationContext reactContext) { 25 | return Collections.emptyList(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /index.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule SnackbarAndroid 3 | */ 4 | 5 | 'use strict'; 6 | 7 | /** 8 | * This exposes the native SnackbarAndroid module in JS. 9 | */ 10 | 11 | import { DeviceEventEmitter, NativeModules, processColor } from 'react-native'; 12 | 13 | var NativeSnackbar = NativeModules.SnackbarAndroid; 14 | 15 | // List of registered event listeners 16 | var eventListeners = {} 17 | 18 | // Map of event names for consumers to names delivered by native module 19 | var eventListenerMap = { 20 | hide: NativeSnackbar.EVENT_HIDE, 21 | hidden: NativeSnackbar.EVENT_HIDDEN, 22 | show: NativeSnackbar.EVENT_SHOW, 23 | shown: NativeSnackbar.EVENT_SHOWN 24 | } 25 | 26 | var SnackbarAndroid = { 27 | SHORT: NativeSnackbar.SHORT, 28 | LONG: NativeSnackbar.LONG, 29 | INDEFINITE: NativeSnackbar.INDEFINITE, 30 | ANIMATION_DURATION: NativeSnackbar.ANIMATION_DURATION, 31 | ANIMATION_FADE_DURATION: NativeSnackbar.ANIMATION_FADE_DURATION, 32 | UNTIL_CLICK: 42, 33 | 34 | show: function ( 35 | message: string, 36 | options: { 37 | duration: number, 38 | actionColor: string, 39 | actionLabel: string, 40 | actionCallback: Function, 41 | } 42 | ): void { 43 | var hideOnClick = false; 44 | 45 | if (options == null) { 46 | options = {}; 47 | } 48 | 49 | var label, callback; 50 | if (options.actionLabel && options.actionCallback) { 51 | if (options.duration == null) { 52 | options.duration = this.INDEFINITE; 53 | } 54 | 55 | label = options.actionLabel; 56 | callback = options.actionCallback; 57 | } 58 | 59 | if (options.duration == null) { 60 | options.duration = this.SHORT; 61 | } 62 | else if (options.duration == this.UNTIL_CLICK) { 63 | options.duration = this.INDEFINITE; 64 | hideOnClick = true; 65 | } 66 | 67 | if (options.actionColor == null) { 68 | options.actionColor = '#EEFF41'; 69 | } 70 | var color = processColor(options.actionColor); 71 | 72 | this.snackbar = NativeSnackbar.show( 73 | message, 74 | options.duration, 75 | hideOnClick, 76 | color, 77 | label, 78 | callback); 79 | }, 80 | 81 | dismiss: function(): void { 82 | NativeSnackbar.dismiss(); 83 | }, 84 | 85 | /** 86 | * Add an event listener for the specified event type 87 | * 88 | * @param {String} eventType one of 'hide', 'show', 'hidden' or 'shown' 89 | * @param {Function} callback callback to execute when event is received 90 | */ 91 | addEventListener(eventType: string, callback: Function): void { 92 | if (eventType in eventListenerMap) { 93 | eventListeners[callback] = DeviceEventEmitter.addListener( 94 | eventListenerMap[eventType], 95 | callback 96 | ); 97 | } 98 | }, 99 | 100 | /** 101 | * Removes a previously registered event listener for the specified type. 102 | * 103 | * @param {String} eventType type of event that callback was registered to 104 | * @param {Function} callback listener to remove. Must be the same object 105 | * reference as the function that was originally 106 | * passed to addEventListener() 107 | */ 108 | removeEventListener(eventType: string, callback: Function): void { 109 | if (eventType in eventListenerMap) { 110 | if (callback in eventListeners) { 111 | DeviceEventEmitter.removeSubscription(eventListeners[callback]); 112 | delete eventListeners[callback]; 113 | } 114 | } 115 | } 116 | }; 117 | 118 | module.exports = SnackbarAndroid; 119 | -------------------------------------------------------------------------------- /index.ios.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = {}; 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-android-snackbar", 3 | "version": "0.2.0", 4 | "description": "React Native widget to render a snackbar in Android apps", 5 | "keywords": ["react-native", "android", "snackbar"], 6 | "homepage": "https://github.com/luggit/react-native-android-snackbar", 7 | "author": "Pedro Belo", 8 | "files": [ 9 | "android/", 10 | "index.android.js", 11 | "index.ios.js" 12 | ], 13 | "license": "MIT" 14 | } 15 | --------------------------------------------------------------------------------