Browse Source

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.
master
Saúl Ibarra Corretgé 6 years ago
parent
commit
0bc369afb4

+ 13
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java View File

@@ -17,6 +17,7 @@
17 17
 
18 18
 package org.jitsi.meet.sdk;
19 19
 
20
+import android.app.Activity;
20 21
 import android.app.Application;
21 22
 import android.support.annotation.Nullable;
22 23
 
@@ -120,6 +121,18 @@ class ReactInstanceManagerHolder {
120 121
                 ? reactContext.getNativeModule(nativeModuleClass) : null;
121 122
     }
122 123
 
124
+    /**
125
+     * Gets the current {@link Activity} linked to React Native.
126
+     *
127
+     * @return An activity attached to React Native.
128
+     */
129
+    static Activity getCurrentActivity() {
130
+        ReactContext reactContext
131
+            = reactInstanceManager != null
132
+            ? reactInstanceManager.getCurrentReactContext() : null;
133
+        return reactContext != null ? reactContext.getCurrentActivity() : null;
134
+    }
135
+
123 136
     static ReactInstanceManager getReactInstanceManager() {
124 137
         return reactInstanceManager;
125 138
     }

Loading…
Cancel
Save