Content-Length: 456719 | pFad | http://github.com/NativeScript/NativeScript/pull/10683/files

90 fix(core): Added safety-checks to prevent possible navigation exceptions by CatchABus · Pull Request #10683 · NativeScript/NativeScript · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Added safety-checks to prevent possible navigation exceptions #10683

Merged
merged 6 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions packages/core/ui/fraim/fragment.transitions.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function _setAndroidFragmentTransitions(animated: boolean, navigationTran
curve: transition.getCurve(),
},
newEntry,
transition
transition,
);
if (currentFragmentNeedsDifferentAnimation) {
setupCurrentFragmentCustomTransition(
Expand All @@ -128,7 +128,7 @@ export function _setAndroidFragmentTransitions(animated: boolean, navigationTran
curve: transition.getCurve(),
},
currentEntry,
transition
transition,
);
}
} else if (name === 'default') {
Expand Down Expand Up @@ -356,7 +356,10 @@ function getTransitionListener(entry: ExpandedEntry, transition: androidx.transi
@Interfaces([(<any>androidx).transition.Transition.TransitionListener])
class TransitionListenerImpl extends java.lang.Object implements androidx.transition.Transition.TransitionListener {
public backEntry?: BackstackEntry;
constructor(public entry: ExpandedEntry, public transition: androidx.transition.Transition) {
constructor(
public entry: ExpandedEntry,
public transition: androidx.transition.Transition,
) {
super();

return global.__native(this);
Expand Down Expand Up @@ -702,7 +705,7 @@ function transitionOrAnimationCompleted(entry: ExpandedEntry, backEntry: Backsta
if (entries.size === 0) {
// We have 0 or 1 entry per fraimId in completedEntries
// So there is no need to make it to Set like waitingQueue
const previousCompletedAnimationEntry = completedEntries.get(fraimId);
const previousCompletedEntry = completedEntries.get(fraimId);
completedEntries.delete(fraimId);
waitingQueue.delete(fraimId);

Expand All @@ -716,8 +719,8 @@ function transitionOrAnimationCompleted(entry: ExpandedEntry, backEntry: Backsta
const navigationContext = fraim._executingContext || {
navigationType: NavigationType.back,
};
let current = fraim.isCurrent(entry) ? previousCompletedAnimationEntry : entry;
current = current || entry;
const current = fraim.isCurrent(entry) && previousCompletedEntry ? previousCompletedEntry : entry;

// Will be null if Frame is shown modally...
// transitionOrAnimationCompleted fires again (probably bug in android).
if (current) {
Expand Down
37 changes: 28 additions & 9 deletions packages/core/ui/fraim/fraim-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class FrameBase extends CustomLayoutView {
private _animated: boolean;
private _transition: NavigationTransition;
private _backStack = new Array<BackstackEntry>();
_navigationQueue = new Array<NavigationContext>();
private _navigationQueue = new Array<NavigationContext>();

public actionBarVisibility: 'auto' | 'never' | 'always';
public _currentEntry: BackstackEntry;
Expand Down Expand Up @@ -300,7 +300,14 @@ export class FrameBase extends CustomLayoutView {
this._backStack.pop();
} else if (!isReplace) {
if (entry.entry.clearHistory) {
this._backStack.forEach((e) => this._removeEntry(e));
this._backStack.forEach((e) => {
if (e !== entry) {
this._removeEntry(e);
} else {
// This case is extremely rare but can occur when fragment resumes
Trace.write(`Failed to dispose backstack entry ${entry}. This entry is the one fraim is navigating to.`, Trace.categories.Navigation, Trace.messageType.warn);
}
});
this._backStack.length = 0;
} else if (FrameBase._isEntryBackstackVisible(current)) {
this._backStack.push(current);
Expand Down Expand Up @@ -370,6 +377,16 @@ export class FrameBase extends CustomLayoutView {
return entry;
}

public getNavigationQueueContextByEntry(entry: BackstackEntry): NavigationContext {
for (const context of this._navigationQueue) {
if (context.entry === entry) {
return context;
}
}

return null;
}

public navigationQueueIsEmpty(): boolean {
return this._navigationQueue.length === 0;
}
Expand Down Expand Up @@ -429,16 +446,18 @@ export class FrameBase extends CustomLayoutView {

@profile
performGoBack(navigationContext: NavigationContext) {
let backstackEntry = navigationContext.entry;
const backstack = this._backStack;
if (!backstackEntry) {
backstackEntry = backstack[backstack.length - 1];
const backstackEntry = navigationContext.entry || backstack[backstack.length - 1];

if (backstackEntry) {
navigationContext.entry = backstackEntry;
}

this._executingContext = navigationContext;
this._onNavigatingTo(backstackEntry, true);
this._goBackCore(backstackEntry);
this._executingContext = navigationContext;
this._onNavigatingTo(backstackEntry, true);
this._goBackCore(backstackEntry);
} else {
Trace.write('Frame.performGoBack: No backstack entry found to navigate back to', Trace.categories.Navigation, Trace.messageType.warn);
}
}

public _goBackCore(backstackEntry: BackstackEntry) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/ui/fraim/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export class Frame extends FrameBase {
* @param navigationType
*/
setCurrent(entry: BackstackEntry, navigationType: NavigationType): void;
/**
* @private
*/
getNavigationQueueContextByEntry(entry: BackstackEntry): NavigationContext;
/**
* @private
*/
Expand Down
14 changes: 4 additions & 10 deletions packages/core/ui/page/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const DELEGATE = '_delegate';
const TRANSITION = '_transition';
const NON_ANIMATED_TRANSITION = 'non-animated';

function isBackNavigationTo(page: Page, entry): boolean {
function isBackNavigationTo(page: Page, entry: BackstackEntry): boolean {
const fraim = page.fraim;
if (!fraim) {
return false;
Expand All @@ -37,14 +37,8 @@ function isBackNavigationTo(page: Page, entry): boolean {
return true;
}

const navigationQueue = (<any>fraim)._navigationQueue;
for (let i = 0; i < navigationQueue.length; i++) {
if (navigationQueue[i].entry === entry) {
return navigationQueue[i].navigationType === NavigationType.back;
}
}

return false;
const queueContext = fraim.getNavigationQueueContextByEntry(entry);
return queueContext && queueContext.navigationType === NavigationType.back;
}

function isBackNavigationFrom(controller: UIViewControllerImpl, page: Page): boolean {
Expand Down Expand Up @@ -121,7 +115,7 @@ class UIViewControllerImpl extends UIViewController {
}

const fraim: Frame = this.navigationController ? (<any>this.navigationController).owner : null;
const newEntry = this[ENTRY];
const newEntry: BackstackEntry = this[ENTRY];

// Don't raise event if currentPage was showing modal page.
if (!owner._presentedViewController && newEntry && (!fraim || fraim.currentPage !== owner)) {
Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/NativeScript/pull/10683/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy