diff --git a/packages/core/ui/frame/frame-common.spec.ts b/packages/core/ui/frame/frame-common.spec.ts index a2096eb19b..f7deba3d47 100644 --- a/packages/core/ui/frame/frame-common.spec.ts +++ b/packages/core/ui/frame/frame-common.spec.ts @@ -127,6 +127,33 @@ describe('FrameBase.goBack', () => { 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); + const nested = createFrame(true); + nested.parent = root; + nested._nativeWindow = window; + _pushInFrameStack(nested); + + expect(FrameBase.goBack(FrameBase.topmost(window))).toBe(true); + + expect(isNavigatingBack(nested)).toBe(true); + expect(isNavigatingBack(root)).toBe(false); + }); + + it('does not reach a nested frame with history when given its root frame', () => { + const window = createWindow('a'); + const root = createFrameInWindow(window); + const nested = createFrame(true); + nested.parent = root; + nested._nativeWindow = window; + _pushInFrameStack(nested); + + expect(FrameBase.goBack(root)).toBe(false); + + expect(isNavigatingBack(nested)).toBe(false); + }); }); /** diff --git a/packages/core/ui/frame/index.android.ts b/packages/core/ui/frame/index.android.ts index 9638b5272a..d98f76ab91 100644 --- a/packages/core/ui/frame/index.android.ts +++ b/packages/core/ui/frame/index.android.ts @@ -779,7 +779,7 @@ if (SDK_VERSION >= 33) { // In the case of Frame, use this callback only if it was overridden, since the original will cause navigation issues if (!viewArgs.cancel && (view.onBackPressed === Frame.prototype.onBackPressed || !view.onBackPressed())) { - callSuper = view instanceof Frame ? !Frame.goBack(view) : true; + callSuper = view instanceof Frame ? !Frame.goBack(Frame.topmost(nativeWindow)) : true; } } } @@ -1031,7 +1031,7 @@ export class ActivityCallbacksImplementation implements AndroidActivityCallbacks // In the case of Frame, use this callback only if it was overridden, since the original will cause navigation issues if (!viewArgs.cancel && (view.onBackPressed === Frame.prototype.onBackPressed || !view.onBackPressed())) { - callSuper = view instanceof Frame ? !Frame.goBack(view) : true; + callSuper = view instanceof Frame ? !Frame.goBack(Frame.topmost(nativeWindow)) : true; } if (callSuper) {