Pārlūkot izejas kodu

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 gadus atpakaļ
vecāks
revīzija
0bc369afb4

+ 13
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java Parādīt failu

17
 
17
 
18
 package org.jitsi.meet.sdk;
18
 package org.jitsi.meet.sdk;
19
 
19
 
20
+import android.app.Activity;
20
 import android.app.Application;
21
 import android.app.Application;
21
 import android.support.annotation.Nullable;
22
 import android.support.annotation.Nullable;
22
 
23
 
120
                 ? reactContext.getNativeModule(nativeModuleClass) : null;
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
     static ReactInstanceManager getReactInstanceManager() {
136
     static ReactInstanceManager getReactInstanceManager() {
124
         return reactInstanceManager;
137
         return reactInstanceManager;
125
     }
138
     }

Notiek ielāde…
Atcelt
Saglabāt