diff --git a/android/build.gradle b/android/build.gradle index 151607d..77c1891 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,22 +1,27 @@ buildscript { repositories { + google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.3.1' + classpath 'com.android.tools.build:gradle:3.5.2' } } +def getExtOrDefault(name, fallback) { + return rootProject.ext.has(name) ? rootProject.ext.get(name) : fallback +} + apply plugin: 'com.android.library' android { - compileSdkVersion 23 - buildToolsVersion "23.0.1" + compileSdkVersion getExtOrDefault('compileSdkVersion', 28) + buildToolsVersion getExtOrDefault('buildToolsVersion', "28.0.3") defaultConfig { minSdkVersion 16 - targetSdkVersion 22 + targetSdkVersion getExtOrDefault('targetSdkVersion', 28) versionCode 1 versionName "1.0" } @@ -25,6 +30,12 @@ android { } } +repositories { + google() + jcenter() + mavenCentral() +} + dependencies { - compile 'com.facebook.react:react-native:+' -} \ No newline at end of file + api 'com.facebook.react:react-native:+' +} diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar index 13372ae..01b8bf6 100644 Binary files a/android/gradle/wrapper/gradle-wrapper.jar and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 122a0dc..fb491f5 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Sat Apr 18 20:53:10 BST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip diff --git a/android/gradlew b/android/gradlew old mode 100644 new mode 100755 index 9d82f78..cccdd3d --- a/android/gradlew +++ b/android/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,20 +6,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -150,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/android/gradlew.bat b/android/gradlew.bat index aec9973..e95643d 100644 --- a/android/gradlew.bat +++ b/android/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/android/src/main/java/dk/madslee/imageSequence/RCTImageSequenceView.java b/android/src/main/java/dk/madslee/imageSequence/RCTImageSequenceView.java index a072809..a2e46a8 100644 --- a/android/src/main/java/dk/madslee/imageSequence/RCTImageSequenceView.java +++ b/android/src/main/java/dk/madslee/imageSequence/RCTImageSequenceView.java @@ -5,12 +5,15 @@ import android.graphics.BitmapFactory; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.util.Log; import android.os.AsyncTask; import android.widget.ImageView; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -43,11 +46,19 @@ public DownloadImageTask(Integer index, String uri, Context context) { @Override protected Bitmap doInBackground(String... params) { - if (this.uri.startsWith("http")) { - return this.loadBitmapByExternalURL(this.uri); - } + try { + if (this.uri.startsWith("http")) { + return this.loadBitmapByExternalURL(this.uri); + } else if (this.uri.startsWith("file://")) { + File file = new File(new URI(this.uri)); + return BitmapFactory.decodeFile(file.getAbsolutePath()); + } + + return this.loadBitmapByLocalResource(this.uri); + } catch (Exception e) { - return this.loadBitmapByLocalResource(this.uri); + } + return null; } @@ -57,12 +68,20 @@ private Bitmap loadBitmapByLocalResource(String uri) { private Bitmap loadBitmapByExternalURL(String uri) { Bitmap bitmap = null; + InputStream in = null; try { - InputStream in = new URL(uri).openStream(); + in = new URL(uri).openStream(); bitmap = BitmapFactory.decodeStream(in); - } catch (IOException e) { + } catch (Exception e) { e.printStackTrace(); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (Exception e) { + } } return bitmap; @@ -70,7 +89,7 @@ private Bitmap loadBitmapByExternalURL(String uri) { @Override protected void onPostExecute(Bitmap bitmap) { - if (!isCancelled()) { + if (!isCancelled() && bitmap != null) { onTaskCompleted(this, index, bitmap); } } @@ -91,6 +110,11 @@ private void onTaskCompleted(DownloadImageTask downloadImageTask, Integer index, } public void setImages(ArrayList uris) { + Drawable drawable = getDrawable(); + if(drawable instanceof AnimationDrawable){ + ((AnimationDrawable)drawable).stop(); + } + if (isLoading()) { // cancel ongoing tasks (if still loading previous images) for (int index = 0; index < activeTasks.size(); index++) { @@ -108,7 +132,7 @@ public void setImages(ArrayList uris) { try { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (RejectedExecutionException e){ - Log.e("react-native-image-sequence", "DownloadImageTask failed" + e.getMessage()); + Log.e("image-sequence", "DownloadImageTask failed" + e.getMessage()); break; } } diff --git a/android/src/main/java/dk/madslee/imageSequence/RCTResourceDrawableIdHelper.java b/android/src/main/java/dk/madslee/imageSequence/RCTResourceDrawableIdHelper.java index dee659a..7830805 100644 --- a/android/src/main/java/dk/madslee/imageSequence/RCTResourceDrawableIdHelper.java +++ b/android/src/main/java/dk/madslee/imageSequence/RCTResourceDrawableIdHelper.java @@ -3,11 +3,13 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.net.Uri; -import com.facebook.common.util.UriUtil; +import androidx.core.content.ContextCompat; -import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; + +import com.facebook.common.util.UriUtil; public class RCTResourceDrawableIdHelper { @@ -36,7 +38,7 @@ public int getResourceDrawableId(Context context, @Nullable String name) { public @Nullable Drawable getResourceDrawable(Context context, @Nullable String name) { int resId = getResourceDrawableId(context, name); - return resId > 0 ? context.getResources().getDrawable(resId) : null; + return resId > 0 ? ContextCompat.getDrawable(context, resId) : null; } public Uri getResourceDrawableUri(Context context, @Nullable String name) { diff --git a/index.js b/index.js index 4b7632c..d3577c7 100644 --- a/index.js +++ b/index.js @@ -31,6 +31,7 @@ ImageSequence.defaultProps = { }; ImageSequence.propTypes = { + ...ViewPropTypes, startFrameIndex: number, images: array.isRequired, framesPerSecond: number, diff --git a/typings/index.d.ts b/typings/index.d.ts index c413d58..f3515e8 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,6 +1,7 @@ import { Component } from 'react'; +import { ViewProps } from 'react-native'; -interface ImageSequenceProps { +interface ImageSequenceProps extends ViewProps { /** An array of source images. Each element of the array should be the result of a call to require(imagePath). */ images: any[]; /** Which index of the images array should the sequence start at. Default: 0 */