android: add ability to get the current Activity running RN

This helper method gets the current Activity attached to React Native (via the
ReactContext). This is useful for modules which need access to it, without being
actual React Native modules.
pull/4379/head
Saúl Ibarra Corretgé 5 years ago committed by Saúl Ibarra Corretgé
parent f71ec55170
commit 0bc369afb4
  1. 13
      android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java

@ -17,6 +17,7 @@
package org.jitsi.meet.sdk;
import android.app.Activity;
import android.app.Application;
import android.support.annotation.Nullable;
@ -120,6 +121,18 @@ class ReactInstanceManagerHolder {
? reactContext.getNativeModule(nativeModuleClass) : null;
}
/**
* Gets the current {@link Activity} linked to React Native.
*
* @return An activity attached to React Native.
*/
static Activity getCurrentActivity() {
ReactContext reactContext
= reactInstanceManager != null
? reactInstanceManager.getCurrentReactContext() : null;
return reactContext != null ? reactContext.getCurrentActivity() : null;
}
static ReactInstanceManager getReactInstanceManager() {
return reactInstanceManager;
}

Loading…
Cancel
Save