Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -25,6 +30,12 @@ android {
}
}

repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
compile 'com.facebook.react:react-native:+'
}
api 'com.facebook.react:react-native:+'
}
Binary file modified android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
72 changes: 42 additions & 30 deletions android/gradlew
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions android/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}


Expand All @@ -57,20 +68,28 @@ 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;
}

@Override
protected void onPostExecute(Bitmap bitmap) {
if (!isCancelled()) {
if (!isCancelled() && bitmap != null) {
onTaskCompleted(this, index, bitmap);
}
}
Expand All @@ -91,6 +110,11 @@ private void onTaskCompleted(DownloadImageTask downloadImageTask, Integer index,
}

public void setImages(ArrayList<String> 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++) {
Expand All @@ -108,7 +132,7 @@ public void setImages(ArrayList<String> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ImageSequence.defaultProps = {
};

ImageSequence.propTypes = {
...ViewPropTypes,
startFrameIndex: number,
images: array.isRequired,
framesPerSecond: number,
Expand Down
3 changes: 2 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down