Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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
Expand All @@ -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);
Expand All @@ -44,6 +44,7 @@ public NetworkRecordingModuleMock(ReactApplicationContext reactContext) {
public NetworkRecordingModuleMock(ReactApplicationContext reactContext, boolean completeRequest) {
super(reactContext);
mCompleteRequest = completeRequest;
mContext = reactContext;
}

public interface RequestListener {
Expand Down Expand Up @@ -120,15 +121,15 @@ private void onDataReceived(int requestId, String data) {
args.pushInt(requestId);
args.pushString(data);

getEventEmitter().emit("didReceiveNetworkData", args);
mContext.emitDeviceEvent("didReceiveNetworkData", args);
}

private void onRequestComplete(int requestId, @Nullable String error) {
WritableArray args = Arguments.createArray();
args.pushInt(requestId);
args.pushString(error);

getEventEmitter().emit("didCompleteNetworkResponse", args);
mContext.emitDeviceEvent("didCompleteNetworkResponse", args);
}

private void onResponseReceived(int requestId, int code, WritableMap headers) {
Expand All @@ -137,11 +138,6 @@ private void onResponseReceived(int requestId, int code, WritableMap headers) {
args.pushInt(code);
args.pushMap(headers);

getEventEmitter().emit("didReceiveNetworkResponse", args);
}

private DeviceEventManagerModule.RCTDeviceEventEmitter getEventEmitter() {
return getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
mContext.emitDeviceEvent("didReceiveNetworkResponse", args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,7 @@ public void onNewIntent(Intent intent) {
private void toggleElementInspector() {
ReactContext currentContext = getCurrentReactContext();
if (currentContext != null && currentContext.hasActiveReactInstance()) {
currentContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("toggleElementInspector", null);
currentContext.emitDeviceEvent("toggleElementInspector");
} else {
ReactSoftExceptionLogger.logSoftException(
TAG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.modules.appregistry.AppRegistry;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
import com.facebook.react.surface.ReactStage;
import com.facebook.react.uimanager.DisplayMetricsHolder;
Expand Down Expand Up @@ -866,9 +865,7 @@ public ReactInstanceManager getReactInstanceManager() {

/* package */ void sendEvent(String eventName, @Nullable WritableMap params) {
if (hasActiveReactInstance()) {
getCurrentReactContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
getCurrentReactContext().emitDeviceEvent(eventName, params);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.uimanager.GuardedFrameCallback;
import com.facebook.react.uimanager.NativeViewHierarchyManager;
Expand Down Expand Up @@ -566,9 +565,7 @@ public void onValueUpdate(double value) {
ReactApplicationContext reactApplicationContext =
getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) {
reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onAnimatedValueUpdate", onAnimatedValueData);
reactApplicationContext.emitDeviceEvent("onAnimatedValueUpdate", onAnimatedValueData);
}
}
};
Expand Down Expand Up @@ -1090,9 +1087,8 @@ public void onValueUpdate(double value) {
ReactApplicationContext reactApplicationContext =
getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) {
reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onAnimatedValueUpdate", onAnimatedValueData);
reactApplicationContext.emitDeviceEvent(
"onAnimatedValueUpdate", onAnimatedValueData);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.facebook.react.bridge.UIManager;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.events.Event;
Expand Down Expand Up @@ -308,9 +307,8 @@ private void stopAnimationsForNode(AnimatedNode animatedNode) {
WritableMap params = Arguments.createMap();
params.putInt("animationId", animation.mId);
params.putBoolean("finished", false);
mReactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onNativeAnimatedModuleAnimationFinished", params);
mReactApplicationContext.emitDeviceEvent(
"onNativeAnimatedModuleAnimationFinished", params);
}
mActiveAnimations.removeAt(i);
i--;
Expand Down Expand Up @@ -339,9 +337,8 @@ public void stopAnimation(int animationId) {
WritableMap params = Arguments.createMap();
params.putInt("animationId", animation.mId);
params.putBoolean("finished", false);
mReactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onNativeAnimatedModuleAnimationFinished", params);
mReactApplicationContext.emitDeviceEvent(
"onNativeAnimatedModuleAnimationFinished", params);
}
mActiveAnimations.removeAt(i);
return;
Expand Down Expand Up @@ -474,9 +471,7 @@ public void getValue(int tag, Callback callback) {
WritableMap params = Arguments.createMap();
params.putInt("tag", tag);
params.putDouble("value", value);
mReactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("onNativeAnimatedModuleGetValue", params);
mReactApplicationContext.emitDeviceEvent("onNativeAnimatedModuleGetValue", params);
}

@UiThread
Expand Down Expand Up @@ -653,12 +648,8 @@ public void runUpdates(long frameTimeNanos) {
WritableMap params = Arguments.createMap();
params.putInt("animationId", animation.mId);
params.putBoolean("finished", true);
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter =
mReactApplicationContext.getJSModule(
DeviceEventManagerModule.RCTDeviceEventEmitter.class);
if (eventEmitter != null) {
eventEmitter.emit("onNativeAnimatedModuleAnimationFinished", params);
}
mReactApplicationContext.emitDeviceEvent(
"onNativeAnimatedModuleAnimationFinished", params);
}
mActiveAnimations.removeAt(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.queue.MessageQueueThread;
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
import com.facebook.react.common.LifecycleState;
Expand All @@ -32,6 +34,10 @@
* CatalystInstance}
*/
public class ReactContext extends ContextWrapper {
@DoNotStrip
public interface RCTDeviceEventEmitter extends JavaScriptModule {
void emit(@NonNull String eventName, @Nullable Object data);
}

private static final String TAG = "ReactContext";
private static final String EARLY_JS_ACCESS_EXCEPTION_MESSAGE =
Expand Down Expand Up @@ -183,6 +189,21 @@ public <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface
return mCatalystInstance.getNativeModule(nativeModuleInterface);
}

/**
* Calls RCTDeviceEventEmitter.emit to JavaScript, with given event name and an optional list of
* arguments.
*/
public void emitDeviceEvent(String eventName, @Nullable Object args) {
RCTDeviceEventEmitter eventEmitter = getJSModule(RCTDeviceEventEmitter.class);
if (eventEmitter != null) {
eventEmitter.emit(eventName, args);
}
}

public void emitDeviceEvent(String eventName) {
emitDeviceEvent(eventName, null);
}

public CatalystInstance getCatalystInstance() {
return Assertions.assertNotNull(mCatalystInstance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule;

/**
* Module that monitors and provides information about the state of Touch Exploration service on the
Expand Down Expand Up @@ -130,9 +129,7 @@ private void updateAndSendReduceMotionChangeEvent() {

ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) {
reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(REDUCE_MOTION_EVENT_NAME, mReduceMotionEnabled);
reactApplicationContext.emitDeviceEvent(REDUCE_MOTION_EVENT_NAME, mReduceMotionEnabled);
}
}
}
Expand All @@ -144,8 +141,7 @@ private void updateAndSendTouchExplorationChangeEvent(boolean enabled) {
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(TOUCH_EXPLORATION_EVENT_NAME, mTouchExplorationEnabled);
.emitDeviceEvent(TOUCH_EXPLORATION_EVENT_NAME, mTouchExplorationEnabled);
}
}
}
Expand All @@ -157,8 +153,7 @@ private void updateAndSendAccessibilityServiceChangeEvent(boolean enabled) {
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(ACCESSIBILITY_SERVICE_EVENT_NAME, mAccessibilityServiceEnabled);
.emitDeviceEvent(ACCESSIBILITY_SERVICE_EVENT_NAME, mAccessibilityServiceEnabled);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;

/** Module that exposes the user's preferred color scheme. */
@ReactModule(name = NativeAppearanceSpec.NAME)
Expand Down Expand Up @@ -108,9 +107,7 @@ public void emitAppearanceChanged(String colorScheme) {
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();

if (reactApplicationContext != null) {
reactApplicationContext
.getJSModule(RCTDeviceEventEmitter.class)
.emit(APPEARANCE_CHANGED_EVENT_NAME, appearancePreferences);
reactApplicationContext.emitDeviceEvent(APPEARANCE_CHANGED_EVENT_NAME, appearancePreferences);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -96,7 +95,7 @@ private void sendEvent(String eventName, @Nullable Object data) {
if (!reactApplicationContext.hasActiveReactInstance()) {
return;
}
reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit(eventName, data);
reactApplicationContext.emitDeviceEvent(eventName, data);
}

private void sendAppStateChangeEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public void emitHardwareBackPressed() {
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();

if (reactApplicationContext != null) {
reactApplicationContext
.getJSModule(RCTDeviceEventEmitter.class)
.emit("hardwareBackPress", null);
reactApplicationContext.emitDeviceEvent("hardwareBackPress", null);
}
}

Expand All @@ -60,7 +58,7 @@ public void emitNewIntentReceived(Uri uri) {
if (reactApplicationContext != null) {
WritableMap map = Arguments.createMap();
map.putString("url", uri.toString());
reactApplicationContext.getJSModule(RCTDeviceEventEmitter.class).emit("url", map);
reactApplicationContext.emitDeviceEvent("url", map);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.facebook.react.devsupport.interfaces.DevOptionHandler;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;

/**
* Module that exposes the URL to the source code map (used for exception stack trace parsing) to JS
Expand Down Expand Up @@ -89,9 +88,7 @@ public void onOptionSelected() {
getReactApplicationContextIfActiveOrWarn();

if (reactApplicationContext != null) {
reactApplicationContext
.getJSModule(RCTDeviceEventEmitter.class)
.emit("didPressMenuItem", data);
reactApplicationContext.emitDeviceEvent("didPressMenuItem", data);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -89,9 +88,7 @@ public void emitUpdateDimensionsEvent() {
mPreviousDisplayMetrics = displayMetrics.copy();
} else if (!displayMetrics.equals(mPreviousDisplayMetrics)) {
mPreviousDisplayMetrics = displayMetrics.copy();
mReactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("didUpdateDimensions", displayMetrics);
mReactApplicationContext.emitDeviceEvent("didUpdateDimensions", displayMetrics);
}
} else {
ReactSoftExceptionLogger.logSoftException(
Expand Down
Loading