mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use emitDeviceEvent in core ReactAndroid code (#36280)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36280 [Changelog][Internal] As a follow-up to adding `ReactContext.emitDeviceEvent` (D43534174 (https://github.com/facebook/react-native/commit/a8f0a4dc626508ba3f1e629df5f9a24e43b6e150)) this makes it used in the OSS part of RN. Reviewed By: NickGerleman Differential Revision: D43494167 fbshipit-source-id: c3d56bde53fb1ce1297a48597b97470ff10f4dc0
This commit is contained in:
1 parent
ad686b0ce1
commit
b108cbbff8
17 files changed
+144
-187
No files matched your search
+5
-9
@@ -18,7 +18,6 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
|
||||
/**
|
||||
* Mock Networking module that records last request received by {@link #sendRequest} method and
|
||||
@@ -36,6 +35,7 @@ public class NetworkRecordingModuleMock extends ReactContextBaseJavaModule {
|
||||
public boolean mAbortedRequest;
|
||||
|
||||
private boolean mCompleteRequest;
|
||||
private ReactApplicationContext mContext;
|
||||
|
||||
public NetworkRecordingModuleMock(ReactApplicationContext reactContext) {
|
||||
this(reactContext, true);
|
||||
@@ -44,6 +44,7 @@ public class NetworkRecordingModuleMock extends ReactContextBaseJavaModule {
|
||||
public NetworkRecordingModuleMock(ReactApplicationContext reactContext, boolean completeRequest) {
|
||||
super(reactContext);
|
||||
mCompleteRequest = completeRequest;
|
||||
mContext = reactContext;
|
||||
}
|
||||
|
||||
public interface RequestListener {
|
||||
@@ -120,7 +121,7 @@ public class NetworkRecordingModuleMock extends ReactContextBaseJavaModule {
|
||||
args.pushInt(requestId);
|
||||
args.pushString(data);
|
||||
|
||||
getEventEmitter().emit("didReceiveNetworkData", args);
|
||||
mContext.emitDeviceEvent("didReceiveNetworkData", args);
|
||||
}
|
||||
|
||||
private void onRequestComplete(int requestId, @Nullable String error) {
|
||||
@@ -128,7 +129,7 @@ public class NetworkRecordingModuleMock extends ReactContextBaseJavaModule {
|
||||
args.pushInt(requestId);
|
||||
args.pushString(error);
|
||||
|
||||
getEventEmitter().emit("didCompleteNetworkResponse", args);
|
||||
mContext.emitDeviceEvent("didCompleteNetworkResponse", args);
|
||||
}
|
||||
|
||||
private void onResponseReceived(int requestId, int code, WritableMap headers) {
|
||||
@@ -137,11 +138,6 @@ public class NetworkRecordingModuleMock extends ReactContextBaseJavaModule {
|
||||
args.pushInt(code);
|
||||
args.pushMap(headers);
|
||||
|
||||
getEventEmitter().emit("didReceiveNetworkResponse", args);
|
||||
}
|
||||
|
||||
private DeviceEventManagerModule.RCTDeviceEventEmitter getEventEmitter() {
|
||||
return getReactApplicationContext()
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
|
||||
mContext.emitDeviceEvent("didReceiveNetworkResponse", args);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user