소스 검색

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.
j8
Saúl Ibarra Corretgé 6 년 전
부모
커밋
0bc369afb4
1개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 13
    0
      android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java

+ 13
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java 파일 보기

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
     }

Loading…
취소
저장