mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
remove activities from module constructors
Summary: Refactor modules that take activities (or activities that implement some interface) as constructor args to not do that. Expose `getCurrentActivity()` in `ReactContext` and use that wherever the activity is needed. public Reviewed By: astreet Differential Revision: D2680462 fb-gh-sync-id: f263b3fe5b422b7aab9fdadd051cef4e82797b0a
This commit is contained in:
committed by
facebook-github-bot-9
parent
7ab17e5ef3
commit
c06efc0831
@@ -146,7 +146,6 @@ public class ReactContext extends ContextWrapper {
|
||||
*/
|
||||
public void onPause() {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
mCurrentActivity = null;
|
||||
for (LifecycleEventListener listener : mLifecycleEventListeners) {
|
||||
listener.onHostPause();
|
||||
}
|
||||
@@ -163,6 +162,7 @@ public class ReactContext extends ContextWrapper {
|
||||
if (mCatalystInstance != null) {
|
||||
mCatalystInstance.destroy();
|
||||
}
|
||||
mCurrentActivity = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,4 +239,13 @@ public class ReactContext extends ContextWrapper {
|
||||
mCurrentActivity.startActivityForResult(intent, code, bundle);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the activity to which this context is currently attached, or {@code null} if not attached.
|
||||
* DO NOT HOLD LONG-LIVED REFERENCES TO THE OBJECT RETURNED BY THIS METHOD, AS THIS WILL CAUSE
|
||||
* MEMORY LEAKS.
|
||||
*/
|
||||
/* package */ @Nullable Activity getCurrentActivity() {
|
||||
return mCurrentActivity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user