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

fix(android): crash on changing activity context after animated navigation Fixes #5674 by manoldonev · Pull Request #5700 · 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
30 changes: 25 additions & 5 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 @@ -22,6 +22,9 @@ import { profile } from "../../profiling";
// TODO: Remove this and get it from global to decouple builder for angular
import { createViewFromEntry } from "../builder";

import { device } from "../../platform";
import lazy from "../../utils/lazy";

export * from "./frame-common";

const INTENT_EXTRA = "com.tns.activity";
Expand All @@ -32,6 +35,8 @@ const CALLBACKS = "_callbacks";
const ownerSymbol = Symbol("_owner");
const activityRootViewsMap = new Map<number, WeakRef<View>>();

const sdkVersion = lazy(() => parseInt(device.sdkVersion));

let navDepth = -1;
let fragmentId = -1;
export let moduleLoaded: boolean;
Expand Down Expand Up @@ -186,13 +191,28 @@ export class Frame extends FrameBase {
super.onUnloaded();
}

private disposeCurrentFragment(){
if (this._currentEntry && this._currentEntry.fragment) {
const manager: android.app.FragmentManager = this._getFragmentManager();
const transaction = manager.beginTransaction();
private disposeCurrentFragment(): void {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We need the disposeCurrentFragment() call because of this: [quoting @MartoYankov] in Tabs-Frames-Pages scenario all of the frames' fragments are restored before the tabs' fragments are recreated and they try to load their pages before they have been selected. The chosen solution was to remove the frame fragment on unloading the frame. We want Android to recreate the tab fragment that will load its frame (that creates a new fragment for the page).

if (!this._currentEntry || !this._currentEntry.fragment) {
return;
}

const manager: android.app.FragmentManager = this._getFragmentManager();
const transaction = manager.beginTransaction();
const androidSdkVersion = sdkVersion();

if (androidSdkVersion !== 21 && androidSdkVersion !== 22) {
transaction.remove(this._currentEntry.fragment);
transaction.commitAllowingStateLoss();
} else {
// https://github.com/NativeScript/NativeScript/issues/5674
// HACK: Add and remove dummy fragment to workaround a Lollipop issue
// with inFragment passed as null when adding transition targets: https://android.googlesource.com/platform/frameworks/base.git/+/lollipop-release/core/java/android/app/BackStackRecord.java#1127
const dummyFragmentTag = "dummy";
const dummyFragment = this.createFragment(<BackstackEntry>{}, dummyFragmentTag);
transaction.replace(this.containerViewId, dummyFragment, dummyFragmentTag);
transaction.remove(dummyFragment);
}

transaction.commitAllowingStateLoss();
}

private createFragment(backstackEntry: BackstackEntry, fragmentTag: string): android.app.Fragment {
Expand Down

Back | FazBrowse Home | New Git URL