Skip to content
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
24 changes: 1 addition & 23 deletions packages/core/ui/frame/frame-common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('FrameBase.goBack', () => {
expect(isNavigatingBack(child)).toBe(false);
});

it('reports no navigation and leaves the stack alone when the given frame is not topmost', () => {
it('reports no navigation when the given frame is not topmost', () => {
const first = createFrame(false);
const second = createFrame(true);
_pushInFrameStack(first);
Expand All @@ -106,28 +106,6 @@ describe('FrameBase.goBack', () => {
expect(isNavigatingBack(second)).toBe(false);
});

it('pops the topmost frame when it cannot navigate back', () => {
const first = createFrame(true);
const second = createFrame(false);
_pushInFrameStack(first);
_pushInFrameStack(second);

expect(FrameBase.goBack()).toBe(false);

expect(frameStack).toEqual([first]);
expect(second._isInFrameStack).toBe(false);
});

it('keeps the last frame in the stack when it cannot navigate back', () => {
const only = createFrame(false);
_pushInFrameStack(only);

expect(FrameBase.goBack()).toBe(false);
expect(FrameBase.goBack(only)).toBe(false);

expect(frameStack).toEqual([only]);
});

it("navigates a nested frame with history when given the window's topmost frame", () => {
const window = createWindow('a');
const root = createFrameInWindow(window);
Expand Down
35 changes: 16 additions & 19 deletions packages/core/ui/frame/frame-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,29 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {

static goBack(frame?: FrameBase): boolean {
const top = frame ?? FrameBase.topmost();
if (top && top.canGoBack()) {
top.goBack();
if (!top) {
return false;
}

if (top.canGoBack()) {
top.goBack();
return true;
} else if (top) {
let parentFrameCanGoBack = false;
let parentFrame = getAncestor(top, 'Frame');

while (parentFrame && !parentFrameCanGoBack) {
if (parentFrame && parentFrame.canGoBack()) {
parentFrameCanGoBack = true;
} else {
parentFrame = getAncestor(parentFrame, 'Frame');
}
}
}

if (parentFrame && parentFrameCanGoBack) {
parentFrame.goBack();
let parentFrameCanGoBack = false;
let parentFrame = getAncestor(top, 'Frame');

return true;
while (parentFrame && !parentFrameCanGoBack) {
if (parentFrame && parentFrame.canGoBack()) {
parentFrameCanGoBack = true;
} else {
parentFrame = getAncestor(parentFrame, 'Frame');
}
}

// Popping is only valid for the frame at the top of the stack - an explicitly passed frame may sit lower.
if (frameStack.length > 1 && frameStack[frameStack.length - 1] === top) {
top._popFromFrameStack();
if (parentFrame && parentFrameCanGoBack) {
parentFrame.goBack();
return true;
}

return false;
Expand Down
8 changes: 0 additions & 8 deletions packages/core/ui/frame/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,6 @@ export class Frame extends FrameBase {
super.disposeNativeView();
}

public _popFromFrameStack() {
Comment thread
farfromrefug marked this conversation as resolved.
Resolved
if (!this._isInFrameStack) {
return;
}

super._popFromFrameStack();
}

public _getNavBarVisible(page: Page): boolean {
switch (this.actionBarVisibility) {
case 'never':
Expand Down
Loading