react-native-fast-image 8.6.17 → 8.6.18
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.
|
@@ -9,7 +9,7 @@ import com.bumptech.glide.request.target.ImageViewTarget;
|
|
|
9
9
|
import com.bumptech.glide.request.target.Target;
|
|
10
10
|
import com.facebook.react.bridge.WritableMap;
|
|
11
11
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
12
|
-
import com.facebook.react.
|
|
12
|
+
import com.facebook.react.bridge.ReactContext;
|
|
13
13
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
14
14
|
|
|
15
15
|
public class FastImageRequestListener implements RequestListener<Drawable> {
|
|
@@ -36,7 +36,10 @@ public class FastImageRequestListener implements RequestListener<Drawable> {
|
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
38
|
FastImageViewWithUrl view = (FastImageViewWithUrl) ((ImageViewTarget) target).getView();
|
|
39
|
-
|
|
39
|
+
ReactContext context = FastImageViewManager.getReactContext(view.getContext());
|
|
40
|
+
if (context == null) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
40
43
|
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
|
|
41
44
|
int viewId = view.getId();
|
|
42
45
|
eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, new WritableNativeMap());
|
|
@@ -50,7 +53,10 @@ public class FastImageRequestListener implements RequestListener<Drawable> {
|
|
|
50
53
|
return false;
|
|
51
54
|
}
|
|
52
55
|
FastImageViewWithUrl view = (FastImageViewWithUrl) ((ImageViewTarget) target).getView();
|
|
53
|
-
|
|
56
|
+
ReactContext context = FastImageViewManager.getReactContext(view.getContext());
|
|
57
|
+
if (context == null) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
54
60
|
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
|
|
55
61
|
int viewId = view.getId();
|
|
56
62
|
eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_EVENT, mapFromResource(resource));
|
|
@@ -19,6 +19,7 @@ import com.facebook.react.bridge.WritableMap;
|
|
|
19
19
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
20
20
|
import com.facebook.react.common.MapBuilder;
|
|
21
21
|
import com.facebook.react.uimanager.SimpleViewManager;
|
|
22
|
+
import com.facebook.react.bridge.ReactContext;
|
|
22
23
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
23
24
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
24
25
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
@@ -120,7 +121,8 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
|
|
|
120
121
|
WritableMap event = new WritableNativeMap();
|
|
121
122
|
event.putInt("loaded", (int) bytesRead);
|
|
122
123
|
event.putInt("total", (int) expectedLength);
|
|
123
|
-
|
|
124
|
+
ReactContext context = getReactContext(view.getContext());
|
|
125
|
+
if (context == null) continue;
|
|
124
126
|
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
|
|
125
127
|
int viewId = view.getId();
|
|
126
128
|
eventEmitter.receiveEvent(viewId, REACT_ON_PROGRESS_EVENT, event);
|
|
@@ -143,6 +145,20 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
|
|
|
143
145
|
return !isActivityDestroyed(activity);
|
|
144
146
|
}
|
|
145
147
|
|
|
148
|
+
// A view's context is the ThemedReactContext it was created with, but below
|
|
149
|
+
// Android 5 (API 21) AppCompatImageView wraps it in a TintContextWrapper, so
|
|
150
|
+
// it can't be cast directly (#840). Unwrap until the ReactContext.
|
|
151
|
+
@Nullable
|
|
152
|
+
static ReactContext getReactContext(Context context) {
|
|
153
|
+
while (context instanceof ContextWrapper) {
|
|
154
|
+
if (context instanceof ReactContext) {
|
|
155
|
+
return (ReactContext) context;
|
|
156
|
+
}
|
|
157
|
+
context = ((ContextWrapper) context).getBaseContext();
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
146
162
|
private static Activity getActivityFromContext(final Context context) {
|
|
147
163
|
if (context instanceof Activity) {
|
|
148
164
|
return (Activity) context;
|
|
@@ -16,7 +16,7 @@ import com.bumptech.glide.request.Request;
|
|
|
16
16
|
import com.facebook.react.bridge.ReadableMap;
|
|
17
17
|
import com.facebook.react.bridge.WritableMap;
|
|
18
18
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
19
|
-
import com.facebook.react.
|
|
19
|
+
import com.facebook.react.bridge.ReactContext;
|
|
20
20
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
21
21
|
|
|
22
22
|
import java.util.ArrayList;
|
|
@@ -73,12 +73,14 @@ class FastImageViewWithUrl extends AppCompatImageView {
|
|
|
73
73
|
final FastImageSource imageSource = FastImageViewConverter.getImageSource(getContext(), mSource);
|
|
74
74
|
|
|
75
75
|
if (imageSource != null && imageSource.getUri().toString().length() == 0) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
ReactContext context = FastImageViewManager.getReactContext(getContext());
|
|
77
|
+
if (context != null) {
|
|
78
|
+
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
|
|
79
|
+
int viewId = getId();
|
|
80
|
+
WritableMap event = new WritableNativeMap();
|
|
81
|
+
event.putString("message", "Invalid source prop:" + mSource);
|
|
82
|
+
eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, event);
|
|
83
|
+
}
|
|
82
84
|
|
|
83
85
|
// Cancel existing requests.
|
|
84
86
|
clearView(requestManager);
|
|
@@ -111,10 +113,10 @@ class FastImageViewWithUrl extends AppCompatImageView {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
if (imageSource != null) {
|
|
116
|
+
ReactContext reactContext = FastImageViewManager.getReactContext(getContext());
|
|
117
|
+
if (imageSource != null && reactContext != null) {
|
|
116
118
|
// This is an orphan even without a load/loadend when only loading a placeholder
|
|
117
|
-
RCTEventEmitter eventEmitter =
|
|
119
|
+
RCTEventEmitter eventEmitter = reactContext.getJSModule(RCTEventEmitter.class);
|
|
118
120
|
int viewId = this.getId();
|
|
119
121
|
|
|
120
122
|
eventEmitter.receiveEvent(viewId,
|
|
@@ -133,7 +135,7 @@ class FastImageViewWithUrl extends AppCompatImageView {
|
|
|
133
135
|
// - data:image/png;base64
|
|
134
136
|
.load(imageSource == null ? null : imageSource.getSourceForLoad())
|
|
135
137
|
.apply(FastImageViewConverter
|
|
136
|
-
.getOptions(
|
|
138
|
+
.getOptions(getContext(), imageSource, mSource)
|
|
137
139
|
.placeholder(mDefaultSource) // show until loaded
|
|
138
140
|
.fallback(mDefaultSource)); // null will not be treated as error
|
|
139
141
|
|