Skip to content

Commit

Permalink
Adding show/hide Native Implementation of Dev Loading Module (faceboo…
Browse files Browse the repository at this point in the history
…k#35746)

Summary:
Pull Request resolved: facebook#35746

Changelog:
[Android][Added] -  For supporting Dev Loading View across multiple platforms, adding native implementation for showMessage() & hide() of Dev Loading Module

Reviewed By: rshest

Differential Revision: D42286425

fbshipit-source-id: b2aa160583bc86965501f3ed3027152bb0b47af0
  • Loading branch information
arushikesarwani94 authored and OlimpiaZurek committed May 22, 2023
1 parent 8360b9c commit 9d50d36
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ public JSExceptionHandler getExceptionHandler() {
return mExceptionHandlerWrapper;
}

public JSExceptionHandler getJSExceptionHandler() {
return mJSExceptionHandler;
}

public boolean hasCurrentActivity() {
return mCurrentActivity != null && mCurrentActivity.get() != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
*/
public final class BridgeDevSupportManager extends DevSupportManagerBase {
private boolean mIsSamplingProfilerEnabled = false;
private ReactInstanceDevHelper mReactInstanceManagerHelper;
private @Nullable DevLoadingViewManager mDevLoadingViewManager;

public BridgeDevSupportManager(
Context applicationContext,
Expand All @@ -89,6 +91,9 @@ public BridgeDevSupportManager(
surfaceDelegateFactory,
devLoadingViewManager);

mReactInstanceManagerHelper = reactInstanceManagerHelper;
mDevLoadingViewManager = devLoadingViewManager;

if (getDevSettings().isStartSamplingProfilerOnInit()) {
// Only start the profiler. If its already running, there is an error
if (!mIsSamplingProfilerEnabled) {
Expand Down Expand Up @@ -128,6 +133,14 @@ public void onOptionSelected() {
}
}

public DevLoadingViewManager getDevLoadingViewManager() {
return mDevLoadingViewManager;
}

public ReactInstanceDevHelper getReactInstanceManagerHelper() {
return mReactInstanceManagerHelper;
}

@Override
protected String getUniqueTag() {
return "Bridge";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ rn_android_library(
"pfh:ReactNative_CommonInfrastructurePlaceholder",
],
language = "JAVA",
provided_deps = [
react_native_dep("third-party/android/androidx:annotation"),
],
visibility = [
"PUBLIC",
],
deps = [
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/devsupport:devsupport"),
react_native_target("java/com/facebook/react/devsupport:interfaces"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,36 @@

package com.facebook.react.modules.devloading;

import android.util.Log;
import androidx.annotation.Nullable;
import com.facebook.fbreact.specs.NativeDevLoadingViewSpec;
import com.facebook.react.bridge.JSExceptionHandler;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.devsupport.BridgeDevSupportManager;
import com.facebook.react.devsupport.DefaultDevLoadingViewImplementation;
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
import com.facebook.react.module.annotations.ReactModule;

/** {@link NativeModule} that allows JS to show dev loading view. */
@ReactModule(name = NativeDevLoadingViewSpec.NAME)
public class DevLoadingModule extends NativeDevLoadingViewSpec {

private final JSExceptionHandler mJSExceptionHandler;
private @Nullable DevLoadingViewManager mDevLoadingViewManager;

public DevLoadingModule(ReactApplicationContext reactContext) {
super(reactContext);
mJSExceptionHandler = reactContext.getJSExceptionHandler();
if (mJSExceptionHandler != null && mJSExceptionHandler instanceof BridgeDevSupportManager) {
mDevLoadingViewManager =
((BridgeDevSupportManager) mJSExceptionHandler).getDevLoadingViewManager();
mDevLoadingViewManager =
mDevLoadingViewManager != null
? mDevLoadingViewManager
: new DefaultDevLoadingViewImplementation(
((BridgeDevSupportManager) mJSExceptionHandler).getReactInstanceManagerHelper());
}
}

@Override
Expand All @@ -29,7 +46,7 @@ public void showMessage(final String message, final Double color, final Double b
new Runnable() {
@Override
public void run() {
Log.w(NAME, "Showing Message in DevLoadingModule java.");
mDevLoadingViewManager.showMessage(message);
}
});
}
Expand All @@ -41,7 +58,7 @@ public void hide() {
new Runnable() {
@Override
public void run() {
Log.w(NAME, "Hiding Message in DevLoadingModule java.");
mDevLoadingViewManager.hide();
}
});
}
Expand Down

0 comments on commit 9d50d36

Please sign in to comment.