FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(android): IllegalStateException with tabview&nested frames by manoldonev · Pull Request #6495 · NativeScript/NativeScript · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
31 changes: 31 additions & 0 deletions tns-core-modules/ui/frame/frame.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Back | FazBrowse Home | New Git URL