|
13 | 13 | import com.bumptech.glide.RequestManager; |
14 | 14 | import com.bumptech.glide.load.model.GlideUrl; |
15 | 15 | import com.bumptech.glide.request.Request; |
| 16 | +import com.dylanvann.fastimage.events.OnErrorEvent; |
| 17 | +import com.dylanvann.fastimage.events.OnLoadStartEvent; |
| 18 | +import com.dylanvann.fastimage.events.OnProgressEvent; |
16 | 19 | import com.facebook.react.bridge.ReadableMap; |
17 | 20 | import com.facebook.react.bridge.WritableMap; |
18 | 21 | import com.facebook.react.bridge.WritableNativeMap; |
19 | 22 | import com.facebook.react.uimanager.ThemedReactContext; |
| 23 | +import com.facebook.react.uimanager.UIManagerHelper; |
| 24 | +import com.facebook.react.uimanager.events.EventDispatcher; |
20 | 25 | import com.facebook.react.uimanager.events.RCTEventEmitter; |
21 | 26 |
|
22 | 27 | import java.util.ArrayList; |
@@ -81,11 +86,13 @@ public void onAfterUpdate( |
81 | 86 |
|
82 | 87 | if (imageSource != null && imageSource.getUri().toString().length() == 0) { |
83 | 88 | ThemedReactContext context = (ThemedReactContext) getContext(); |
84 | | - RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class); |
85 | 89 | int viewId = getId(); |
86 | | - WritableMap event = new WritableNativeMap(); |
87 | | - event.putString("message", "Invalid source prop:" + mSource); |
88 | | - eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, event); |
| 90 | + EventDispatcher eventDispatcher = |
| 91 | + UIManagerHelper.getEventDispatcherForReactTag(context, viewId); |
| 92 | + if (eventDispatcher == null) { |
| 93 | + return; |
| 94 | + } |
| 95 | + eventDispatcher.dispatchEvent(new OnErrorEvent(viewId)); |
89 | 96 |
|
90 | 97 | // Cancel existing requests. |
91 | 98 | clearView(requestManager); |
@@ -121,12 +128,13 @@ public void onAfterUpdate( |
121 | 128 | ThemedReactContext context = (ThemedReactContext) getContext(); |
122 | 129 | if (imageSource != null) { |
123 | 130 | // This is an orphan even without a load/loadend when only loading a placeholder |
124 | | - RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class); |
125 | | - int viewId = this.getId(); |
126 | | - |
127 | | - eventEmitter.receiveEvent(viewId, |
128 | | - FastImageViewManager.REACT_ON_LOAD_START_EVENT, |
129 | | - new WritableNativeMap()); |
| 131 | + int viewId = getId(); |
| 132 | + EventDispatcher eventDispatcher = |
| 133 | + UIManagerHelper.getEventDispatcherForReactTag(context, viewId); |
| 134 | + if (eventDispatcher == null) { |
| 135 | + return; |
| 136 | + } |
| 137 | + eventDispatcher.dispatchEvent(new OnLoadStartEvent(viewId, 0, 0)); |
130 | 138 | } |
131 | 139 |
|
132 | 140 | if (requestManager != null) { |
|
0 commit comments