├── .gitattributes ├── .gitignore ├── LICENSE.md ├── README.md ├── android ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── github │ └── godness84 │ └── RNSparkButton │ ├── RNSparkButton.java │ ├── RNSparkButtonPackage.java │ └── RNSparkButtonViewManager.java ├── art └── showcase.gif ├── example ├── .babelrc ├── .buckconfig ├── .flowconfig ├── .gitattributes ├── .gitignore ├── .watchmanconfig ├── __tests__ │ ├── index.android.js │ └── index.ios.js ├── android │ ├── app │ │ ├── BUCK │ │ ├── build.gradle │ │ ├── proguard-rules.pro │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.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 ├── assets │ └── thumbs-up.png ├── index.android.js ├── index.ios.js └── package.json ├── index.js ├── lib └── SparkButton.js └── package.json /.gitattributes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/.gitattributes -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # OSX 3 | # 4 | .DS_Store 5 | 6 | # node.js 7 | # 8 | node_modules/ 9 | npm-debug.log 10 | yarn-error.log 11 | 12 | 13 | # Android/IntelliJ 14 | # 15 | build/ 16 | .idea 17 | .gradle 18 | local.properties 19 | *.iml 20 | 21 | # BUCK 22 | buck-out/ 23 | \.buckd/ 24 | *.keystore 25 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Marc Shilling 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 | 2 | # react-native-sparkbutton 3 | 4 | A checked/button with Twitter's heart explosion like animation (for Android). 5 | Based on the Android library: https://github.com/varunest/SparkButton 6 | 7 | 8 | 9 | ## Getting started 10 | 11 | `$ npm install react-native-sparkbutton --save` 12 | 13 | ### Mostly automatic installation 14 | 15 | `$ react-native link react-native-sparkbutton` 16 | 17 | ### Manual installation 18 | 19 | 20 | #### Android 21 | 22 | 1. Open up `android/app/src/main/java/[...]/MainActivity.java` 23 | - Add `import com.github.godness84.RNSparkButton.RNSparkButtonPackage;` to the imports at the top of the file 24 | - Add `new RNSparkButtonPackage()` to the list returned by the `getPackages()` method 25 | 2. Append the following lines to `android/settings.gradle`: 26 | ``` 27 | include ':react-native-sparkbutton' 28 | project(':react-native-sparkbutton').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sparkbutton/android') 29 | ``` 30 | 3. Insert the following lines inside the dependencies block in `android/app/build.gradle`: 31 | ``` 32 | compile project(':react-native-sparkbutton') 33 | ``` 34 | 35 | 36 | ## Usage 37 | 38 | ```javascript 39 | import { Component } from 'react'; 40 | import SparkButton from 'react-native-sparkbutton'; 41 | 42 | class MyExample extends Component { 43 | state = { 44 | checked: false 45 | } 46 | 47 | render() { 48 | const { checked } = this.state; 49 | return ( 50 | this.setState({ checked })} /> 59 | ); 60 | } 61 | } 62 | ``` 63 | 64 | # Props 65 | 66 | Prop name | Description | Type | Default value 67 | ----------------------|---------------|-----------|-------------- 68 | `style` | Style for the container of the button | object | {} 69 | `checked` | Checked or not. In case it's checked after mounting it will play the animation | bool | false 70 | `activeImageSrc` | Source of the active image | {uri: '...'} or require('image.png') | none 71 | `inactiveImageSrc` | Source of the inactive image | {uri: '...'} or require('image.png') | none 72 | `activeImageTint` | Tint color to apply to active image | color | none 73 | `inactiveImageTint` | Tint color to apply to inactive image | color | none 74 | `primaryColor` | Primary color for the explosion | color | none 75 | `secondaryColor` | Secondary color for the explosion | color | none 76 | `animationSpeed` | Speed of the explosion | number | 1.0 77 | `touchableProps` | Props for the Touchable that wraps the button internally | object | none 78 | `onCheckedChange` | Called when the checked state changes | function | none 79 | `onPress` | Called when the button is pressed | function | none 80 | 81 | # Methods 82 | 83 | Method name | Params | Description 84 | ----------------------|---------------------------------|------------ 85 | `playAnimation` | none | Play the explosion animation 86 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | maven { url "https://jitpack.io" } 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:2.2.3' 10 | } 11 | } 12 | 13 | apply plugin: 'com.android.library' 14 | 15 | android { 16 | compileSdkVersion 23 17 | buildToolsVersion "23.0.1" 18 | 19 | defaultConfig { 20 | minSdkVersion 16 21 | targetSdkVersion 22 22 | versionCode 1 23 | versionName "1.0" 24 | } 25 | lintOptions { 26 | abortOnError false 27 | } 28 | } 29 | 30 | repositories { 31 | mavenCentral() 32 | maven { url "https://jitpack.io" } 33 | } 34 | 35 | dependencies { 36 | compile 'com.facebook.react:react-native:+' 37 | compile 'com.github.varunest:sparkbutton:1.0.5' 38 | } 39 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jul 20 19:37:19 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 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 Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/godness84/RNSparkButton/RNSparkButton.java: -------------------------------------------------------------------------------- 1 | package com.github.godness84.RNSparkButton; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ObjectAnimator; 7 | import android.content.Context; 8 | import android.graphics.Bitmap; 9 | import android.graphics.PorterDuff; 10 | import android.net.Uri; 11 | import android.support.annotation.Nullable; 12 | import android.util.Log; 13 | import android.view.LayoutInflater; 14 | import android.view.MotionEvent; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | import android.view.ViewParent; 18 | import android.view.animation.AccelerateDecelerateInterpolator; 19 | import android.view.animation.DecelerateInterpolator; 20 | import android.view.animation.OvershootInterpolator; 21 | import android.widget.FrameLayout; 22 | import android.widget.ImageView; 23 | 24 | import com.facebook.common.executors.UiThreadImmediateExecutorService; 25 | import com.facebook.common.references.CloseableReference; 26 | import com.facebook.datasource.DataSource; 27 | import com.facebook.drawee.backends.pipeline.Fresco; 28 | import com.facebook.imagepipeline.common.Priority; 29 | import com.facebook.imagepipeline.core.ImagePipeline; 30 | import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber; 31 | import com.facebook.imagepipeline.image.CloseableImage; 32 | import com.facebook.imagepipeline.request.ImageRequest; 33 | import com.facebook.imagepipeline.request.ImageRequestBuilder; 34 | import com.facebook.react.bridge.ReadableMap; 35 | import com.facebook.react.views.imagehelper.ImageSource; 36 | import com.varunest.sparkbutton.helpers.CircleView; 37 | import com.varunest.sparkbutton.helpers.DotsView; 38 | 39 | 40 | public class RNSparkButton extends FrameLayout { 41 | private static final String TAG = "SparkButton"; 42 | private static final DecelerateInterpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator(); 43 | private static final AccelerateDecelerateInterpolator ACCELERATE_DECELERATE_INTERPOLATOR = new AccelerateDecelerateInterpolator(); 44 | private static final OvershootInterpolator OVERSHOOT_INTERPOLATOR = new OvershootInterpolator(4); 45 | 46 | private static final float DOTVIEW_SIZE_FACTOR = 3; 47 | private static final float DOTS_SIZE_FACTOR = .08f; 48 | private static final float CIRCLEVIEW_SIZE_FACTOR = 1.4f; 49 | 50 | int imageSize; 51 | int dotsSize; 52 | int circleSize; 53 | int secondaryColor; 54 | int primaryColor; 55 | int activeImageTint; 56 | int inActiveImageTint; 57 | DotsView dotsView; 58 | CircleView circleView; 59 | ImageView imageView; 60 | 61 | float animationSpeed = 1; 62 | boolean isChecked = false; 63 | 64 | ImageSource activeImageSource; 65 | Bitmap activeImageBitmap; 66 | ImageSource inactiveImageSource; 67 | Bitmap inactiveImageBitmap; 68 | 69 | private AnimatorSet animatorSet; 70 | private boolean surrogateLayoutPassScheduled = false; 71 | private boolean isDirty = true; 72 | 73 | RNSparkButton(Context context) { 74 | super(context); 75 | init(); 76 | maybeUpdateView(); 77 | } 78 | 79 | @Override 80 | protected void onAttachedToWindow() { 81 | super.onAttachedToWindow(); 82 | ViewParent parent = getParent(); 83 | if (parent != null) { 84 | ((ViewGroup)parent).setClipChildren(false); 85 | parent = parent.getParent(); 86 | if (parent != null) { 87 | ((ViewGroup)parent).setClipChildren(false); 88 | } 89 | } 90 | } 91 | 92 | @Override 93 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 94 | final int wMode = View.MeasureSpec.getMode(widthMeasureSpec); 95 | final int wSize = View.MeasureSpec.getSize(widthMeasureSpec); 96 | final int hMode = View.MeasureSpec.getMode(heightMeasureSpec); 97 | final int hSize = View.MeasureSpec.getSize(heightMeasureSpec); 98 | 99 | //Log.d(TAG, "onMeasure: " + wMode + ", " + wSize + ", " + hMode + ", " + hSize); 100 | 101 | if (wMode == MeasureSpec.EXACTLY && hMode == MeasureSpec.EXACTLY) { 102 | imageSize = Math.min(wSize, hSize); 103 | isDirty = true; 104 | maybeUpdateView(); 105 | } 106 | 107 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 108 | } 109 | 110 | @Override 111 | public void requestLayout() { 112 | super.requestLayout(); 113 | if (!surrogateLayoutPassScheduled) { 114 | //Log.d(TAG, "requestLayout() called. Going to schedule a surrogate layout pass"); 115 | surrogateLayoutPassScheduled = true; 116 | this.post(new Runnable() { 117 | @Override 118 | public void run() { 119 | RNSparkButton.this.measure( 120 | View.MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), 121 | View.MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY) 122 | ); 123 | RNSparkButton.this.layout(getLeft(), getTop(), getRight(), getBottom()); 124 | surrogateLayoutPassScheduled = false; 125 | //Log.d(TAG, "surrogate layout pass executed"); 126 | } 127 | }); 128 | } 129 | } 130 | 131 | public void setPressed(boolean pressed) { 132 | if (pressed) { 133 | this.imageView.animate().scaleX(0.8f).scaleY(0.8f).setDuration(150).setInterpolator(DECELERATE_INTERPOLATOR).start(); 134 | } else if (this.animatorSet == null || !this.animatorSet.isRunning()) { 135 | this.imageView.animate().scaleX(1).scaleY(1).setInterpolator(DECELERATE_INTERPOLATOR).start(); 136 | } 137 | } 138 | 139 | public void setChecked(boolean checked) { 140 | this.isChecked = checked; 141 | this.isDirty = true; 142 | } 143 | 144 | public void setActiveImageSource(@Nullable ReadableMap source) { 145 | this.activeImageSource = null; 146 | 147 | if (source != null) { 148 | String uri = source.getString("uri"); 149 | this.activeImageSource = new ImageSource(getContext(), uri); 150 | } 151 | 152 | this.isDirty = true; 153 | } 154 | 155 | public void setInactiveImageSource(@Nullable ReadableMap source) { 156 | this.inactiveImageSource = null; 157 | 158 | if (source != null) { 159 | String uri = source.getString("uri"); 160 | this.inactiveImageSource = new ImageSource(getContext(), uri); 161 | } 162 | 163 | this.isDirty = true; 164 | } 165 | 166 | public void setActiveImageTint(int tint) { 167 | this.activeImageTint = tint; 168 | this.isDirty = true; 169 | } 170 | 171 | public void setInactiveImageTint(int tint) { 172 | this.inActiveImageTint = tint; 173 | this.isDirty = true; 174 | } 175 | 176 | public void setPrimaryColor(int color) { 177 | this.primaryColor = color; 178 | this.isDirty = true; 179 | } 180 | 181 | public void setSecondaryColor(int color) { 182 | this.secondaryColor = color; 183 | this.isDirty = true; 184 | } 185 | 186 | public void setAnimationSpeed(float animationSpeed) { 187 | this.animationSpeed = animationSpeed; 188 | // not necessary to flag it dirty 189 | } 190 | 191 | /** 192 | * Call this function to start spark animation 193 | */ 194 | public void playAnimation() { 195 | if (animatorSet != null) { 196 | animatorSet.cancel(); 197 | } 198 | 199 | imageView.animate().cancel(); 200 | imageView.setScaleX(0); 201 | imageView.setScaleY(0); 202 | circleView.setInnerCircleRadiusProgress(0); 203 | circleView.setOuterCircleRadiusProgress(0); 204 | dotsView.setCurrentProgress(0); 205 | 206 | animatorSet = new AnimatorSet(); 207 | 208 | ObjectAnimator outerCircleAnimator = ObjectAnimator.ofFloat(circleView, CircleView.OUTER_CIRCLE_RADIUS_PROGRESS, 0.1f, 1f); 209 | outerCircleAnimator.setDuration((long) (250 / animationSpeed)); 210 | outerCircleAnimator.setInterpolator(DECELERATE_INTERPOLATOR); 211 | 212 | ObjectAnimator innerCircleAnimator = ObjectAnimator.ofFloat(circleView, CircleView.INNER_CIRCLE_RADIUS_PROGRESS, 0.1f, 1f); 213 | innerCircleAnimator.setDuration((long) (200 / animationSpeed)); 214 | innerCircleAnimator.setStartDelay((long) (200 / animationSpeed)); 215 | innerCircleAnimator.setInterpolator(DECELERATE_INTERPOLATOR); 216 | 217 | ObjectAnimator starScaleYAnimator = ObjectAnimator.ofFloat(imageView, ImageView.SCALE_Y, 0.2f, 1f); 218 | starScaleYAnimator.setDuration((long) (350 / animationSpeed)); 219 | starScaleYAnimator.setStartDelay((long) (250 / animationSpeed)); 220 | starScaleYAnimator.setInterpolator(OVERSHOOT_INTERPOLATOR); 221 | 222 | ObjectAnimator starScaleXAnimator = ObjectAnimator.ofFloat(imageView, ImageView.SCALE_X, 0.2f, 1f); 223 | starScaleXAnimator.setDuration((long) (350 / animationSpeed)); 224 | starScaleXAnimator.setStartDelay((long) (250 / animationSpeed)); 225 | starScaleXAnimator.setInterpolator(OVERSHOOT_INTERPOLATOR); 226 | 227 | ObjectAnimator dotsAnimator = ObjectAnimator.ofFloat(dotsView, DotsView.DOTS_PROGRESS, 0, 1f); 228 | dotsAnimator.setDuration((long) (900 / animationSpeed)); 229 | dotsAnimator.setStartDelay((long) (50 / animationSpeed)); 230 | dotsAnimator.setInterpolator(ACCELERATE_DECELERATE_INTERPOLATOR); 231 | 232 | animatorSet.playTogether( 233 | outerCircleAnimator, 234 | innerCircleAnimator, 235 | starScaleYAnimator, 236 | starScaleXAnimator, 237 | dotsAnimator 238 | ); 239 | 240 | animatorSet.addListener(new AnimatorListenerAdapter() { 241 | @Override 242 | public void onAnimationCancel(Animator animation) { 243 | circleView.setInnerCircleRadiusProgress(0); 244 | circleView.setOuterCircleRadiusProgress(0); 245 | dotsView.setCurrentProgress(0); 246 | imageView.setScaleX(1); 247 | imageView.setScaleY(1); 248 | } 249 | 250 | @Override 251 | public void onAnimationEnd(Animator animation) { 252 | super.onAnimationEnd(animation); 253 | } 254 | 255 | @Override 256 | public void onAnimationStart(Animator animation) { 257 | super.onAnimationEnd(animation); 258 | } 259 | }); 260 | 261 | animatorSet.start(); 262 | } 263 | 264 | 265 | void init() { 266 | LayoutInflater.from(getContext()).inflate(com.varunest.sparkbutton.R.layout.layout_spark_button, this, true); 267 | 268 | circleView = (CircleView) findViewById(com.varunest.sparkbutton.R.id.vCircle); 269 | dotsView = (DotsView) findViewById(com.varunest.sparkbutton.R.id.vDotsView); 270 | imageView = (ImageView) findViewById(com.varunest.sparkbutton.R.id.ivImage); 271 | 272 | setClipChildren(false); 273 | } 274 | 275 | public void maybeUpdateView() { 276 | if (isDirty) { 277 | isDirty = false; 278 | circleSize = (int) (imageSize * CIRCLEVIEW_SIZE_FACTOR); 279 | dotsSize = (int) (imageSize * DOTVIEW_SIZE_FACTOR); 280 | 281 | circleView.setColors(secondaryColor, primaryColor); 282 | circleView.getLayoutParams().height = circleSize; 283 | circleView.getLayoutParams().width = circleSize; 284 | 285 | dotsView.getLayoutParams().width = dotsSize; 286 | dotsView.getLayoutParams().height = dotsSize; 287 | dotsView.setColors(secondaryColor, primaryColor); 288 | dotsView.setMaxDotSize((int) (imageSize * DOTS_SIZE_FACTOR)); 289 | 290 | imageView.getLayoutParams().height = imageSize; 291 | imageView.getLayoutParams().width = imageSize; 292 | 293 | if (isChecked) { 294 | if (activeImageBitmap != null) { 295 | imageView.setImageBitmap(activeImageBitmap); 296 | } else if (inactiveImageBitmap != null) { 297 | imageView.setImageBitmap(inactiveImageBitmap); 298 | } 299 | imageView.setColorFilter(activeImageTint, PorterDuff.Mode.SRC_ATOP); 300 | } else { 301 | if (inactiveImageBitmap != null) { 302 | imageView.setImageBitmap(inactiveImageBitmap); 303 | } else if (activeImageBitmap != null) { 304 | imageView.setImageBitmap(activeImageBitmap); 305 | } 306 | imageView.setColorFilter(inActiveImageTint, PorterDuff.Mode.SRC_ATOP); 307 | } 308 | 309 | if (activeImageSource != null) { 310 | final ImagePipeline imagePipeline = Fresco.getImagePipeline(); 311 | final Uri imageUri = activeImageSource.getUri(); 312 | activeImageSource = null; 313 | 314 | ImageRequest imageRequest = ImageRequestBuilder 315 | .newBuilderWithSource(imageUri) 316 | .setRequestPriority(Priority.HIGH) 317 | .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) 318 | .build(); 319 | 320 | DataSource> dataSource = 321 | imagePipeline.fetchDecodedImage(imageRequest, getContext()); 322 | 323 | dataSource.subscribe(new BaseBitmapDataSubscriber() { 324 | @Override 325 | public void onNewResultImpl(@Nullable Bitmap bitmap) { 326 | if (bitmap != null) { 327 | activeImageBitmap = bitmap.copy(bitmap.getConfig(), true); 328 | isDirty = true; 329 | maybeUpdateView(); 330 | } 331 | } 332 | 333 | @Override 334 | public void onFailureImpl(DataSource dataSource) { 335 | Log.e(TAG, "Failed to load image: " + imageUri, dataSource.getFailureCause()); 336 | } 337 | }, UiThreadImmediateExecutorService.getInstance()); 338 | } 339 | 340 | if (inactiveImageSource != null) { 341 | final ImagePipeline imagePipeline = Fresco.getImagePipeline(); 342 | final Uri imageUri = inactiveImageSource.getUri(); 343 | inactiveImageSource = null; 344 | 345 | ImageRequest imageRequest = ImageRequestBuilder 346 | .newBuilderWithSource(imageUri) 347 | .setRequestPriority(Priority.HIGH) 348 | .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) 349 | .build(); 350 | 351 | DataSource> dataSource = 352 | imagePipeline.fetchDecodedImage(imageRequest, getContext()); 353 | 354 | dataSource.subscribe(new BaseBitmapDataSubscriber() { 355 | @Override 356 | public void onNewResultImpl(@Nullable Bitmap bitmap) { 357 | if (bitmap != null) { 358 | inactiveImageBitmap = bitmap.copy(bitmap.getConfig(), true); 359 | isDirty = true; 360 | maybeUpdateView(); 361 | } 362 | } 363 | 364 | @Override 365 | public void onFailureImpl(DataSource dataSource) { 366 | Log.e(TAG, "Failed to load image: " + imageUri, dataSource.getFailureCause()); 367 | } 368 | }, UiThreadImmediateExecutorService.getInstance()); 369 | } 370 | } 371 | } 372 | } 373 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/godness84/RNSparkButton/RNSparkButtonPackage.java: -------------------------------------------------------------------------------- 1 | 2 | package com.github.godness84.RNSparkButton; 3 | 4 | import java.util.Arrays; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.bridge.NativeModule; 10 | import com.facebook.react.bridge.ReactApplicationContext; 11 | import com.facebook.react.uimanager.ViewManager; 12 | 13 | public class RNSparkButtonPackage implements ReactPackage { 14 | @Override 15 | public List createNativeModules(ReactApplicationContext reactContext) { 16 | return Collections.emptyList(); 17 | } 18 | 19 | @Override 20 | public List createViewManagers(ReactApplicationContext reactContext) { 21 | return Arrays.asList( 22 | new RNSparkButtonViewManager() 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /android/src/main/java/com/github/godness84/RNSparkButton/RNSparkButtonViewManager.java: -------------------------------------------------------------------------------- 1 | package com.github.godness84.RNSparkButton; 2 | 3 | import android.graphics.Color; 4 | import android.support.annotation.Nullable; 5 | 6 | import com.facebook.infer.annotation.Assertions; 7 | import com.facebook.react.bridge.ReadableArray; 8 | import com.facebook.react.bridge.ReadableMap; 9 | import com.facebook.react.common.MapBuilder; 10 | import com.facebook.react.uimanager.ThemedReactContext; 11 | import com.facebook.react.uimanager.ViewGroupManager; 12 | import com.facebook.react.uimanager.annotations.ReactProp; 13 | 14 | import java.util.Map; 15 | 16 | /** 17 | * View manager for {@link RNSparkButton}. 18 | */ 19 | public class RNSparkButtonViewManager extends 20 | ViewGroupManager { 21 | 22 | public static final String REACT_CLASS = "RNSparkButton"; 23 | public static final int COMMAND_PLAY_ANIMATION = 1; 24 | 25 | @Override 26 | public String getName() { 27 | return REACT_CLASS; 28 | } 29 | 30 | @Override 31 | protected RNSparkButton createViewInstance(ThemedReactContext reactContext) { 32 | return new RNSparkButton(reactContext); 33 | } 34 | 35 | @ReactProp(name = "pressed", defaultBoolean = false) 36 | public void setPressed(RNSparkButton view, boolean pressed) { 37 | view.setPressed(pressed); 38 | } 39 | 40 | @ReactProp(name = "checked", defaultBoolean = false) 41 | public void setChecked(RNSparkButton view, boolean checked) { 42 | view.setChecked(checked); 43 | } 44 | 45 | @ReactProp(name = "activeImageSrc") 46 | public void setActiveImageSource(RNSparkButton view, @Nullable ReadableMap source) { 47 | view.setActiveImageSource(source); 48 | } 49 | 50 | @ReactProp(name = "inactiveImageSrc") 51 | public void setInactiveImageSource(RNSparkButton view, @Nullable ReadableMap source) { 52 | view.setInactiveImageSource(source); 53 | } 54 | 55 | @ReactProp(name = "activeImageTint", defaultInt = Color.TRANSPARENT, customType = "Color") 56 | public void setActiveImageTint(RNSparkButton view, int tint) { 57 | view.setActiveImageTint(tint); 58 | } 59 | 60 | @ReactProp(name = "inactiveImageTint", defaultInt = Color.TRANSPARENT, customType = "Color") 61 | public void setInactiveImageTint(RNSparkButton view, int tint) { 62 | view.setInactiveImageTint(tint); 63 | } 64 | 65 | @ReactProp(name = "primaryColor", defaultInt = Color.BLACK, customType = "Color") 66 | public void setPrimaryColor(RNSparkButton view, int color) { 67 | view.setPrimaryColor(color); 68 | } 69 | 70 | @ReactProp(name = "secondaryColor", defaultInt = Color.BLACK, customType = "Color") 71 | public void setSecondayColor(RNSparkButton view, int color) { 72 | view.setSecondaryColor(color); 73 | } 74 | 75 | @ReactProp(name = "animationSpeed", defaultFloat = 1.0f) 76 | public void setAnimationSpeed(RNSparkButton view, float speed) { 77 | view.setAnimationSpeed(speed); 78 | } 79 | 80 | @javax.annotation.Nullable 81 | @Override 82 | public Map getCommandsMap() { 83 | return MapBuilder.of( 84 | "playAnimation", COMMAND_PLAY_ANIMATION 85 | ); 86 | } 87 | 88 | @Override 89 | public void receiveCommand( 90 | final RNSparkButton view, 91 | int commandType, 92 | @Nullable ReadableArray args) { 93 | Assertions.assertNotNull(view); 94 | Assertions.assertNotNull(args); 95 | switch (commandType) { 96 | case COMMAND_PLAY_ANIMATION: { 97 | view.playAnimation(); 98 | return; 99 | } 100 | 101 | default: 102 | throw new IllegalArgumentException(String.format( 103 | "Unsupported command %d received by %s.", 104 | commandType, 105 | getClass().getSimpleName())); 106 | } 107 | } 108 | 109 | @Override 110 | protected void onAfterUpdateTransaction(RNSparkButton view) { 111 | super.onAfterUpdateTransaction(view); 112 | view.maybeUpdateView(); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /art/showcase.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/art/showcase.gif -------------------------------------------------------------------------------- /example/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native"] 3 | } 4 | -------------------------------------------------------------------------------- /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 | .*/Libraries/react-native/ReactNative.js 16 | 17 | [include] 18 | 19 | [libs] 20 | node_modules/react-native/Libraries/react-native/react-native-interface.js 21 | node_modules/react-native/flow 22 | flow/ 23 | 24 | [options] 25 | emoji=true 26 | 27 | module.system=haste 28 | 29 | munge_underscores=true 30 | 31 | 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' 32 | 33 | suppress_type=$FlowIssue 34 | suppress_type=$FlowFixMe 35 | suppress_type=$FixMe 36 | 37 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 38 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 39 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 40 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 41 | 42 | unsafe.enable_getters_and_setters=true 43 | 44 | [version] 45 | ^0.49.1 46 | -------------------------------------------------------------------------------- /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://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 50 | 51 | fastlane/report.xml 52 | fastlane/Preview.html 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/__tests__/index.android.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.android.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /example/__tests__/index.ios.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.ios.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /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 | lib_deps = [] 12 | 13 | for jarfile in glob(['libs/*.jar']): 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 | 21 | for aarfile in glob(['libs/*.aar']): 22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')] 23 | lib_deps.append(':' + name) 24 | android_prebuilt_aar( 25 | name = name, 26 | aar = aarfile, 27 | ) 28 | 29 | android_library( 30 | name = "all-libs", 31 | exported_deps = lib_deps, 32 | ) 33 | 34 | android_library( 35 | name = "app-code", 36 | srcs = glob([ 37 | "src/main/java/**/*.java", 38 | ]), 39 | deps = [ 40 | ":all-libs", 41 | ":build_config", 42 | ":res", 43 | ], 44 | ) 45 | 46 | android_build_config( 47 | name = "build_config", 48 | package = "com.example", 49 | ) 50 | 51 | android_resource( 52 | name = "res", 53 | package = "com.example", 54 | res = "src/main/res", 55 | ) 56 | 57 | android_binary( 58 | name = "app", 59 | keystore = "//android/keystores:debug", 60 | manifest = "src/main/AndroidManifest.xml", 61 | package_type = "debug", 62 | deps = [ 63 | ":app-code", 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /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 | apply from: "../../node_modules/react-native/react.gradle" 76 | 77 | /** 78 | * Set this to true to create two separate APKs instead of one: 79 | * - An APK that only works on ARM devices 80 | * - An APK that only works on x86 devices 81 | * The advantage is the size of the APK is reduced by about 4MB. 82 | * Upload all the APKs to the Play Store and people will download 83 | * the correct one based on the CPU architecture of their device. 84 | */ 85 | def enableSeparateBuildPerCPUArchitecture = false 86 | 87 | /** 88 | * Run Proguard to shrink the Java bytecode in release builds. 89 | */ 90 | def enableProguardInReleaseBuilds = false 91 | 92 | android { 93 | compileSdkVersion 23 94 | buildToolsVersion "23.0.1" 95 | 96 | defaultConfig { 97 | applicationId "com.example" 98 | minSdkVersion 16 99 | targetSdkVersion 22 100 | versionCode 1 101 | versionName "1.0" 102 | ndk { 103 | abiFilters "armeabi-v7a", "x86" 104 | } 105 | } 106 | splits { 107 | abi { 108 | reset() 109 | enable enableSeparateBuildPerCPUArchitecture 110 | universalApk false // If true, also generate a universal APK 111 | include "armeabi-v7a", "x86" 112 | } 113 | } 114 | buildTypes { 115 | release { 116 | minifyEnabled enableProguardInReleaseBuilds 117 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 118 | } 119 | } 120 | // applicationVariants are e.g. debug, release 121 | applicationVariants.all { variant -> 122 | variant.outputs.each { output -> 123 | // For each separate APK per architecture, set a unique version code as described here: 124 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 125 | def versionCodes = ["armeabi-v7a":1, "x86":2] 126 | def abi = output.getFilter(OutputFile.ABI) 127 | if (abi != null) { // null for the universal-debug, universal-release variants 128 | output.versionCodeOverride = 129 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 130 | } 131 | } 132 | } 133 | } 134 | 135 | dependencies { 136 | compile project(":react-native-sparkbutton") 137 | compile fileTree(dir: "libs", include: ["*.jar"]) 138 | compile "com.android.support:appcompat-v7:23.0.1" 139 | compile "com.facebook.react:react-native:+" // From node_modules 140 | } 141 | 142 | // Run this once to be able to run the application with BUCK 143 | // puts all compile dependencies into folder libs for BUCK to use 144 | task copyDownloadableDepsToLibs(type: Copy) { 145 | from configurations.compile 146 | into 'libs' 147 | } 148 | -------------------------------------------------------------------------------- /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 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout. 54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. 55 | -dontwarn android.text.StaticLayout 56 | 57 | # okhttp 58 | 59 | -keepattributes Signature 60 | -keepattributes *Annotation* 61 | -keep class okhttp3.** { *; } 62 | -keep interface okhttp3.** { *; } 63 | -dontwarn okhttp3.** 64 | 65 | # okio 66 | 67 | -keep class sun.misc.Unsafe { *; } 68 | -dontwarn java.nio.file.* 69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 70 | -dontwarn okio.** 71 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /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 | import com.github.godness84.RNSparkButton.RNSparkButtonPackage; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | public class MainApplication extends Application implements ReactApplication { 16 | 17 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 18 | @Override 19 | public boolean getUseDeveloperSupport() { 20 | return BuildConfig.DEBUG; 21 | } 22 | 23 | @Override 24 | protected List getPackages() { 25 | return Arrays.asList( 26 | new MainReactPackage(), 27 | new RNSparkButtonPackage() 28 | ); 29 | } 30 | }; 31 | 32 | @Override 33 | public ReactNativeHost getReactNativeHost() { 34 | return mReactNativeHost; 35 | } 36 | 37 | @Override 38 | public void onCreate() { 39 | super.onCreate(); 40 | SoLoader.init(this, /* native exopackage */ false); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.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 | repositories { 5 | jcenter() 6 | maven { url "https://jitpack.io" } 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:2.2.3' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | mavenLocal() 19 | jcenter() 20 | maven { 21 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 22 | url "$rootDir/../node_modules/react-native/android" 23 | } 24 | maven { url "https://jitpack.io" } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 25 17:48:18 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 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 Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /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 | include ':react-native-sparkbutton' 3 | project(':react-native-sparkbutton').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sparkbutton/android') 4 | include ':app' 5 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Example", 3 | "displayName": "Example" 4 | } -------------------------------------------------------------------------------- /example/assets/thumbs-up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/godness84/react-native-sparkbutton/9b9dd678d48c7273d3733ff8ab48704d04348532/example/assets/thumbs-up.png -------------------------------------------------------------------------------- /example/index.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import React, { Component } from 'react'; 8 | import { View, Text, Button, StyleSheet, AppRegistry } from 'react-native'; 9 | import SparkButton from 'react-native-sparkbutton'; 10 | 11 | 12 | export default class Example extends React.Component { 13 | state = { 14 | size: 90, 15 | checked: false 16 | } 17 | 18 | render() { 19 | const { size, checked } = this.state; 20 | return ( 21 | 22 | 23 | this._spark = comp} 25 | style={{ width: size, height: size }} 26 | activeImageSrc={require('./assets/thumbs-up.png')} 27 | inactiveImageTint={'rgba(255,255,255,0.8)'} 28 | primaryColor={"yellow"} 29 | secondaryColor={"red"} 30 | animationSpeed={1} 31 | checked={checked} 32 | onCheckedChange={(checked) => this.setState({ checked })} /> 33 | 34 | 35 | 36 |