Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,24 @@ public void onDropViewInstance(@NonNull FrameLayout view) {
controllerSink.clear();
}

FragmentActivity activity = (FragmentActivity) reactContext.getCurrentActivity();
if (activity == null) return;

WeakReference<IMapViewFragment> weakReference = fragmentMap.remove(viewId);
if (weakReference != null) {
IMapViewFragment fragment = weakReference.get();
if (fragment != null && fragment.isAdded()) {
activity
.getSupportFragmentManager()
.beginTransaction()
.remove((Fragment) fragment)
.commitNowAllowingStateLoss();
// Remove via the FragmentManager the fragment is actually attached to.
// reactContext.getCurrentActivity() can be a different Activity than the one hosting the
// fragment (e.g. after Activity recreation), in which case removing through its
// FragmentManager throws "Cannot remove Fragment attached to a different FragmentManager".
try {
((Fragment) fragment)
.getParentFragmentManager()
.beginTransaction()
.remove((Fragment) fragment)
.commitNowAllowingStateLoss();
} catch (IllegalStateException e) {
// FragmentManager already destroyed mid-teardown; the fragment is torn down with its
// host Activity anyway.
}
}
}
}
Expand Down