@veriff/react-native-sdk 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +34 -25
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradlew +234 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/java/com/veriff/sdk/reactnative/ReactNativeImageProvider.kt +126 -0
- package/android/src/main/java/com/veriff/sdk/reactnative/VeriffSdkModule.kt +449 -0
- package/android/src/main/java/com/veriff/sdk/reactnative/VeriffSdkPackage.kt +18 -0
- package/catalog-info.yaml +1 -1
- package/ios/Podfile +1 -1
- package/package.json +11 -50
- package/react-native-sdk.podspec +1 -1
- package/android/src/main/java/com/veriff/sdk/reactnative/ImageLoader.java +0 -119
- package/android/src/main/java/com/veriff/sdk/reactnative/ReactNativeImageProvider.java +0 -130
- package/android/src/main/java/com/veriff/sdk/reactnative/VeriffSdkModule.java +0 -494
- package/android/src/main/java/com/veriff/sdk/reactnative/VeriffSdkPackage.java +0 -23
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
package com.veriff.sdk.reactnative;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.Bitmap;
|
|
5
|
-
import android.graphics.drawable.BitmapDrawable;
|
|
6
|
-
import android.graphics.drawable.Drawable;
|
|
7
|
-
import android.os.Handler;
|
|
8
|
-
import android.os.Looper;
|
|
9
|
-
import android.util.Log;
|
|
10
|
-
import com.facebook.common.references.CloseableReference;
|
|
11
|
-
import com.facebook.datasource.DataSource;
|
|
12
|
-
import com.facebook.drawee.backends.pipeline.Fresco;
|
|
13
|
-
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
|
14
|
-
import com.facebook.imagepipeline.image.CloseableImage;
|
|
15
|
-
import com.facebook.imagepipeline.request.ImageRequest;
|
|
16
|
-
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
17
|
-
|
|
18
|
-
import java.io.IOException;
|
|
19
|
-
import java.util.concurrent.CountDownLatch;
|
|
20
|
-
import java.util.concurrent.atomic.AtomicReference;
|
|
21
|
-
|
|
22
|
-
public class ImageLoader {
|
|
23
|
-
private static final String TAG = "ImageLoader";
|
|
24
|
-
|
|
25
|
-
private final Handler main = new Handler(Looper.getMainLooper());
|
|
26
|
-
|
|
27
|
-
public Drawable load(Context context, String url) throws IOException {
|
|
28
|
-
if (isAsyncLogoUrl(url)) {
|
|
29
|
-
Log.d(TAG, "Async image" + url);
|
|
30
|
-
return loadAsyncImage(context, url);
|
|
31
|
-
} else {
|
|
32
|
-
Log.d(TAG, "Image from resource" + url);
|
|
33
|
-
int drawableId = getDrawableId(context, url);
|
|
34
|
-
return context.getDrawable(drawableId);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private Drawable loadAsyncImage(Context context, String url) throws IOException {
|
|
39
|
-
ImageRequest request = ImageRequestBuilder.fromRequest(ImageRequest.fromUri(url)).build();
|
|
40
|
-
|
|
41
|
-
if (!Fresco.hasBeenInitialized()) {
|
|
42
|
-
Fresco.initialize(context);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
DataSource<CloseableReference<CloseableImage>> source =
|
|
46
|
-
Fresco.getImagePipeline().fetchDecodedImage(request, null);
|
|
47
|
-
|
|
48
|
-
CountDownLatch imageLoadLatch = new CountDownLatch(1);
|
|
49
|
-
AtomicReference<Result> atomicResult = new AtomicReference<>(null);
|
|
50
|
-
source.subscribe(new BaseBitmapDataSubscriber() {
|
|
51
|
-
@Override
|
|
52
|
-
protected void onNewResultImpl(Bitmap bitmap) {
|
|
53
|
-
if (bitmap == null) {
|
|
54
|
-
Log.w(TAG, "Null bitmap: " + url);
|
|
55
|
-
atomicResult.set(new Result(new IOException("Loaded bitmap was null")));
|
|
56
|
-
} else {
|
|
57
|
-
Log.w(TAG, "Non-Null bitmap: " + url);
|
|
58
|
-
atomicResult.set(new Result(bitmap.copy(bitmap.getConfig(), false)));
|
|
59
|
-
}
|
|
60
|
-
imageLoadLatch.countDown();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Override
|
|
64
|
-
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
|
65
|
-
Throwable failure = dataSource.getFailureCause();
|
|
66
|
-
if (failure == null) {
|
|
67
|
-
atomicResult.set(new Result(new IOException("Provided failure cause was null")));
|
|
68
|
-
} else if (failure instanceof IOException) {
|
|
69
|
-
atomicResult.set(new Result((IOException) failure));
|
|
70
|
-
} else {
|
|
71
|
-
atomicResult.set(new Result(new IOException("Failed loading image", failure)));
|
|
72
|
-
}
|
|
73
|
-
imageLoadLatch.countDown();
|
|
74
|
-
}
|
|
75
|
-
}, main::post);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
imageLoadLatch.await();
|
|
80
|
-
Result result = atomicResult.get();
|
|
81
|
-
|
|
82
|
-
if (result.error != null) {
|
|
83
|
-
Log.w(TAG, "[ImageLoader] Loading image from [" + url + "] failed", result.error);
|
|
84
|
-
throw result.error;
|
|
85
|
-
} else {
|
|
86
|
-
Log.w(TAG, "[ImageLoader] Loading image [" + url + "] got a bitmap with size w=" + result.bitmap.getWidth() + " h=" + result.bitmap.getHeight());
|
|
87
|
-
return new BitmapDrawable(context.getResources(), result.bitmap);
|
|
88
|
-
}
|
|
89
|
-
} catch (InterruptedException e) {
|
|
90
|
-
Thread.currentThread().interrupt(); // preserve interrupt status
|
|
91
|
-
throw new IOException("Interrupted while loading image");
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private static int getDrawableId(Context context, String name) {
|
|
96
|
-
return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private boolean isAsyncLogoUrl(String url) {
|
|
100
|
-
return url.startsWith("https://") || url.startsWith("http://") || url.startsWith("file://");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private static class Result {
|
|
104
|
-
private final IOException error;
|
|
105
|
-
|
|
106
|
-
private final Bitmap bitmap;
|
|
107
|
-
|
|
108
|
-
private Result(IOException error) {
|
|
109
|
-
this.error = error;
|
|
110
|
-
this.bitmap = null;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private Result(Bitmap bitmap) {
|
|
114
|
-
this.error = null;
|
|
115
|
-
this.bitmap = bitmap;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
package com.veriff.sdk.reactnative;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.graphics.Bitmap;
|
|
5
|
-
import android.graphics.drawable.BitmapDrawable;
|
|
6
|
-
import android.graphics.drawable.Drawable;
|
|
7
|
-
import android.os.Handler;
|
|
8
|
-
import android.os.Looper;
|
|
9
|
-
import android.os.Parcel;
|
|
10
|
-
import android.os.Parcelable;
|
|
11
|
-
import android.util.Log;
|
|
12
|
-
|
|
13
|
-
import com.facebook.common.references.CloseableReference;
|
|
14
|
-
import com.facebook.datasource.DataSource;
|
|
15
|
-
import com.facebook.drawee.backends.pipeline.Fresco;
|
|
16
|
-
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
|
17
|
-
import com.facebook.imagepipeline.image.CloseableImage;
|
|
18
|
-
import com.facebook.imagepipeline.request.ImageRequest;
|
|
19
|
-
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
20
|
-
import com.veriff.Branding;
|
|
21
|
-
|
|
22
|
-
import java.io.IOException;
|
|
23
|
-
import java.util.concurrent.CountDownLatch;
|
|
24
|
-
import java.util.concurrent.atomic.AtomicReference;
|
|
25
|
-
|
|
26
|
-
public class ReactNativeImageProvider implements Branding.DrawableProvider, Parcelable {
|
|
27
|
-
private static final String TAG = "ReactNativeImageProvider";
|
|
28
|
-
|
|
29
|
-
private final String url;
|
|
30
|
-
|
|
31
|
-
private final Handler main = new Handler(Looper.getMainLooper());
|
|
32
|
-
|
|
33
|
-
public ReactNativeImageProvider(String url) {
|
|
34
|
-
this.url = url;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected ReactNativeImageProvider(Parcel in) {
|
|
38
|
-
this(in.readString());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@Override
|
|
42
|
-
public Drawable loadImage(Context context) throws IOException {
|
|
43
|
-
ImageRequest request = ImageRequestBuilder.fromRequest(ImageRequest.fromUri(this.url)).build();
|
|
44
|
-
DataSource<CloseableReference<CloseableImage>> source =
|
|
45
|
-
Fresco.getImagePipeline().fetchDecodedImage(request, null);
|
|
46
|
-
|
|
47
|
-
CountDownLatch imageLoadLatch = new CountDownLatch(1);
|
|
48
|
-
AtomicReference<Result> atomicResult = new AtomicReference<>(null);
|
|
49
|
-
|
|
50
|
-
source.subscribe(new BaseBitmapDataSubscriber() {
|
|
51
|
-
@Override
|
|
52
|
-
protected void onNewResultImpl(Bitmap bitmap) {
|
|
53
|
-
if (bitmap == null) {
|
|
54
|
-
atomicResult.set(new Result(new IOException("Loaded bitmap was null")));
|
|
55
|
-
} else {
|
|
56
|
-
atomicResult.set(new Result(bitmap.copy(bitmap.getConfig(), false)));
|
|
57
|
-
}
|
|
58
|
-
imageLoadLatch.countDown();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@Override
|
|
62
|
-
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
|
63
|
-
Throwable failure = dataSource.getFailureCause();
|
|
64
|
-
if (failure == null) {
|
|
65
|
-
atomicResult.set(new Result(new IOException("Provided failure cause was null")));
|
|
66
|
-
} else if (failure instanceof IOException) {
|
|
67
|
-
atomicResult.set(new Result((IOException) failure));
|
|
68
|
-
} else {
|
|
69
|
-
atomicResult.set(new Result(new IOException("Failed loading image", failure)));
|
|
70
|
-
}
|
|
71
|
-
imageLoadLatch.countDown();
|
|
72
|
-
}
|
|
73
|
-
}, main::post);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
imageLoadLatch.await();
|
|
78
|
-
Result result = atomicResult.get();
|
|
79
|
-
|
|
80
|
-
if (result.error != null) {
|
|
81
|
-
Log.w(TAG, "[ReactNativeImageProvider] Loading image from [" + this.url + "] failed", result.error);
|
|
82
|
-
throw result.error;
|
|
83
|
-
} else {
|
|
84
|
-
Log.w(TAG, "[ReactNativeImageProvider] Loading image [" + this.url + "] got a bitmap with size w=" + result.bitmap.getWidth() + " h=" + result.bitmap.getHeight());
|
|
85
|
-
return new BitmapDrawable(context.getResources(), result.bitmap);
|
|
86
|
-
}
|
|
87
|
-
} catch (InterruptedException e) {
|
|
88
|
-
Thread.currentThread().interrupt(); // preserve interrupt status
|
|
89
|
-
throw new IOException("Interrupted while loading image");
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private static class Result {
|
|
94
|
-
private final IOException error;
|
|
95
|
-
|
|
96
|
-
private final Bitmap bitmap;
|
|
97
|
-
|
|
98
|
-
private Result(IOException error) {
|
|
99
|
-
this.error = error;
|
|
100
|
-
this.bitmap = null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private Result(Bitmap bitmap) {
|
|
104
|
-
this.error = null;
|
|
105
|
-
this.bitmap = bitmap;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Override
|
|
110
|
-
public void writeToParcel(Parcel dest, int flags) {
|
|
111
|
-
dest.writeString(url);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@Override
|
|
115
|
-
public int describeContents() {
|
|
116
|
-
return 0;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public static final Creator<ReactNativeImageProvider> CREATOR = new Creator<ReactNativeImageProvider>() {
|
|
120
|
-
@Override
|
|
121
|
-
public ReactNativeImageProvider createFromParcel(Parcel in) {
|
|
122
|
-
return new ReactNativeImageProvider(in);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
@Override
|
|
126
|
-
public ReactNativeImageProvider[] newArray(int size) {
|
|
127
|
-
return new ReactNativeImageProvider[size];
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|