mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(android): IllegalStateException with tabview&nested frames (#6495)
This commit is contained in:

committed by
SvetoslavTsenov

parent
b6a5df18fc
commit
7d21b5c9ab
@ -859,7 +859,38 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
|
||||
if (traceEnabled()) {
|
||||
traceWrite(`${fragment}.onDestroy()`, traceCategories.NativeLifecycle);
|
||||
}
|
||||
|
||||
superFunc.call(fragment);
|
||||
|
||||
const entry = this.entry;
|
||||
if (!entry) {
|
||||
traceError(`${fragment}.onDestroy: entry is null or undefined`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const page = entry.resolvedPage;
|
||||
if (!page) {
|
||||
traceError(`${fragment}.onDestroy: entry has no resolvedPage`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// fixes 'java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first'.
|
||||
// on app resume in nested frame scenarios with support library version greater than 26.0.0
|
||||
// HACK: this whole code block shouldn't be necessary as the native view is supposedly removed from its parent
|
||||
// right after onDestroyView(...) is called but for some reason the fragment view (page) still thinks it has a
|
||||
// parent while its supposed parent believes it properly removed its children; in order to "force" the child to
|
||||
// lose its parent we temporarily add it to the parent, and then remove it (addViewInLayout doesn't trigger layout pass)
|
||||
const nativeView = page.nativeViewProtected;
|
||||
if (nativeView != null) {
|
||||
const parentView = nativeView.getParent();
|
||||
if (parentView instanceof android.view.ViewGroup) {
|
||||
if (parentView.getChildCount() === 0) {
|
||||
parentView.addViewInLayout(nativeView, -1, new org.nativescript.widgets.CommonLayoutParams());
|
||||
}
|
||||
|
||||
parentView.removeView(nativeView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@profile
|
||||
|
Reference in New Issue
Block a user