From 4d95ef17e3199fc780b73baea3531dba4ebaa237 Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Thu, 8 Nov 2018 16:50:14 +0200 Subject: [PATCH 1/2] fix: nested frames order with tabs & suspend/resume --- .../ui/tab-view/tab-view.android.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tns-core-modules/ui/tab-view/tab-view.android.ts b/tns-core-modules/ui/tab-view/tab-view.android.ts index 18165feb6f..18725498ee 100644 --- a/tns-core-modules/ui/tab-view/tab-view.android.ts +++ b/tns-core-modules/ui/tab-view/tab-view.android.ts @@ -12,6 +12,8 @@ import { textTransformProperty, TextTransform, getTransformedText } from "../tex import { fromFileOrResource } from "../../image-source"; import { RESOURCE_PREFIX, ad } from "../../utils/utils"; import { Frame } from "../frame"; +import { frameStack } from "../frame/frame-stack"; +import { getAncestor } from "../core/view-base"; export * from "./tab-view-common"; @@ -40,6 +42,18 @@ function getTabById(id: number): TabView { return ref && ref.get(); } +function isFrameNested(frame: Frame, parentFrameCandidate: Frame) { + let frameAncestor = frame; + while (frameAncestor) { + frameAncestor = getAncestor(frameAncestor, Frame); + if (frameAncestor === parentFrameCandidate) { + return true; + } + } + + return false; +} + function initializeNativeClasses() { if (PagerAdapter) { return; @@ -507,6 +521,14 @@ export class TabView extends TabViewBase { const selectedView = newItem && newItem.view; if (selectedView instanceof Frame) { selectedView._pushInFrameStack(); + + // make sure nested frames order is kept intact i.e. the nested one should always be on top; + // see https://github.com/NativeScript/nativescript-angular/issues/1596 for more information + for (const frame of frameStack) { + if (isFrameNested(frame, selectedView)) { + frame._pushInFrameStack(); + } + } } toLoad.forEach(index => { From 9b858682c7d5edfe00eac00e2f6c5fce96a0bcac Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Mon, 12 Nov 2018 19:04:08 +0200 Subject: [PATCH 2/2] rework impl and apply to iOS as well --- tns-core-modules/ui/frame/frame-common.ts | 29 +++++++++++++++++++ tns-core-modules/ui/frame/frame.d.ts | 4 +++ .../ui/tab-view/tab-view.android.ts | 24 +-------------- tns-core-modules/ui/tab-view/tab-view.ios.ts | 4 +-- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/tns-core-modules/ui/frame/frame-common.ts b/tns-core-modules/ui/frame/frame-common.ts index 818c232ee5..a86798ee46 100644 --- a/tns-core-modules/ui/frame/frame-common.ts +++ b/tns-core-modules/ui/frame/frame-common.ts @@ -251,6 +251,18 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { } } + private isNestedWithin(parentFrameCandidate: FrameBase): boolean { + let frameAncestor: FrameBase = this; + while (frameAncestor) { + frameAncestor = getAncestor(frameAncestor, FrameBase); + if (frameAncestor === parentFrameCandidate) { + return true; + } + } + + return false; + } + private raiseCurrentPageNavigatedEvents(isBack: boolean) { const page = this.currentPage; if (page) { @@ -410,6 +422,23 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { return null; } + public _pushInFrameStackRecursive() { + this._pushInFrameStack(); + + // make sure nested frames order is kept intact i.e. the nested one should always be on top; + // see https://github.com/NativeScript/nativescript-angular/issues/1596 for more information + const framesToPush = []; + for (const frame of frameStack) { + if (frame.isNestedWithin(this)) { + framesToPush.push(frame); + } + } + + for (const frame of framesToPush) { + frame._pushInFrameStack(); + } + } + public _pushInFrameStack() { _pushInFrameStack(this); } diff --git a/tns-core-modules/ui/frame/frame.d.ts b/tns-core-modules/ui/frame/frame.d.ts index 08f072ada5..5652967a64 100644 --- a/tns-core-modules/ui/frame/frame.d.ts +++ b/tns-core-modules/ui/frame/frame.d.ts @@ -158,6 +158,10 @@ export class Frame extends View { * @private */ _pushInFrameStack(); + /** + * @private + */ + _pushInFrameStackRecursive(); /** * @private */ diff --git a/tns-core-modules/ui/tab-view/tab-view.android.ts b/tns-core-modules/ui/tab-view/tab-view.android.ts index 18725498ee..3e2b0b816b 100644 --- a/tns-core-modules/ui/tab-view/tab-view.android.ts +++ b/tns-core-modules/ui/tab-view/tab-view.android.ts @@ -12,8 +12,6 @@ import { textTransformProperty, TextTransform, getTransformedText } from "../tex import { fromFileOrResource } from "../../image-source"; import { RESOURCE_PREFIX, ad } from "../../utils/utils"; import { Frame } from "../frame"; -import { frameStack } from "../frame/frame-stack"; -import { getAncestor } from "../core/view-base"; export * from "./tab-view-common"; @@ -42,18 +40,6 @@ function getTabById(id: number): TabView { return ref && ref.get(); } -function isFrameNested(frame: Frame, parentFrameCandidate: Frame) { - let frameAncestor = frame; - while (frameAncestor) { - frameAncestor = getAncestor(frameAncestor, Frame); - if (frameAncestor === parentFrameCandidate) { - return true; - } - } - - return false; -} - function initializeNativeClasses() { if (PagerAdapter) { return; @@ -520,15 +506,7 @@ export class TabView extends TabViewBase { const newItem = items[newIndex]; const selectedView = newItem && newItem.view; if (selectedView instanceof Frame) { - selectedView._pushInFrameStack(); - - // make sure nested frames order is kept intact i.e. the nested one should always be on top; - // see https://github.com/NativeScript/nativescript-angular/issues/1596 for more information - for (const frame of frameStack) { - if (isFrameNested(frame, selectedView)) { - frame._pushInFrameStack(); - } - } + selectedView._pushInFrameStackRecursive(); } toLoad.forEach(index => { diff --git a/tns-core-modules/ui/tab-view/tab-view.ios.ts b/tns-core-modules/ui/tab-view/tab-view.ios.ts index a7baebce13..5d2c9cee55 100644 --- a/tns-core-modules/ui/tab-view/tab-view.ios.ts +++ b/tns-core-modules/ui/tab-view/tab-view.ios.ts @@ -261,7 +261,7 @@ export class TabView extends TabViewBase { const selectedIndex = this.selectedIndex; const selectedView = this.items && this.items[selectedIndex] && this.items[selectedIndex].view; if (selectedView instanceof Frame) { - selectedView._pushInFrameStack(); + selectedView._pushInFrameStackRecursive(); } this._ios.delegate = this._delegate; @@ -300,7 +300,7 @@ export class TabView extends TabViewBase { if (newItem && this.isLoaded) { const selectedView = items[newIndex].view; if (selectedView instanceof Frame) { - selectedView._pushInFrameStack(); + selectedView._pushInFrameStackRecursive(); } newItem.loadView(newItem.view);