react-native-fast-image 10.8.1 → 10.8.2
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.
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
package com.fastimage;
|
|
2
2
|
|
|
3
|
+
import android.os.Handler;
|
|
4
|
+
import android.os.Looper;
|
|
5
|
+
|
|
3
6
|
import com.facebook.react.bridge.Arguments;
|
|
4
7
|
import com.facebook.react.bridge.ReactContext;
|
|
5
8
|
import com.facebook.react.bridge.WritableMap;
|
|
@@ -15,6 +18,8 @@ final class FastImageEvents {
|
|
|
15
18
|
static final int ERROR = 1 << 3;
|
|
16
19
|
static final int LOAD_END = 1 << 4;
|
|
17
20
|
|
|
21
|
+
private static final Handler MAIN = new Handler(Looper.getMainLooper());
|
|
22
|
+
|
|
18
23
|
private FastImageEvents() {
|
|
19
24
|
}
|
|
20
25
|
|
|
@@ -57,8 +62,21 @@ final class FastImageEvents {
|
|
|
57
62
|
send(view, FastImageRequestListener.REACT_ON_LOAD_END_EVENT, event);
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
// Only the events JS has a handler for: most images have none.
|
|
65
|
+
// Only the events JS has a handler for: most images have none. Posted to
|
|
66
|
+
// the main thread rather than dispatched here: this is called from Glide's
|
|
67
|
+
// onResourceReady and onLoadFailed, and EventDispatcher calls its listeners
|
|
68
|
+
// inline. Reanimated's listener flushes pending mount items, which can
|
|
69
|
+
// drop this view, and the drop clears the request inside its own
|
|
70
|
+
// callback, which Glide doesn't allow (it throws). One Handler keeps the
|
|
71
|
+
// events in order.
|
|
61
72
|
static void send(FastImageViewWithUrl view, String name, WritableMap data) {
|
|
73
|
+
if (!view.handles(bit(name))) return;
|
|
74
|
+
MAIN.post(() -> dispatch(view, name, data));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Dispatches the event now: for callers on the main thread outside Glide's
|
|
78
|
+
// callbacks (e.g. progress, which is posted already).
|
|
79
|
+
static void dispatch(FastImageViewWithUrl view, String name, WritableMap data) {
|
|
62
80
|
if (!view.handles(bit(name))) return;
|
|
63
81
|
ReactContext context = FastImageViewManager.getReactContext(view.getContext());
|
|
64
82
|
if (context == null) return;
|
|
@@ -555,7 +555,7 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl>
|
|
|
555
555
|
// Downloads only report a known length (see FastImageSharedDownloads).
|
|
556
556
|
event.putDouble("progress", Math.min(1.0, Math.max(0.0, (double) loaded / total)));
|
|
557
557
|
try {
|
|
558
|
-
FastImageEvents.
|
|
558
|
+
FastImageEvents.dispatch(view, REACT_ON_PROGRESS_EVENT, event);
|
|
559
559
|
} catch (RuntimeException e) {
|
|
560
560
|
// E.g. the view's React instance is gone: progress isn't worth
|
|
561
561
|
// crashing the app for.
|