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

fix-next(android): tab/frame fragments thru child fm · NativeScript/NativeScript@45c7a80 · GitHub

Commit 45c7a80

Browse files
committed
fix-next(android): tab/frame fragments thru child fm
1 parent 58c9905 commit 45c7a80

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

‎tns-core-modules/ui/core/view/view.android.ts‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { Point, CustomLayoutView as CustomLayoutViewDefinition, dip } from ".";
33
import { GestureTypes, GestureEventData } from "../../gestures";
44
// Types.
55
import {
6-
Color, EventData, ViewCommon, layout, getAncestor, automationTextProperty,
7-
isEnabledProperty, isUserInteractionEnabledProperty, originXProperty, originYProperty,
6+
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
7+
traceEnabled, traceWrite, traceCategories, traceNotifyEvent,
88
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty,
9-
traceEnabled, traceWrite, traceCategories, traceNotifyEvent
9+
Color, EventData
1010
} from "./view-common";
1111

1212
import {
@@ -20,7 +20,7 @@ import {
2020

2121
import { Background, ad as androidBackground } from "../../styling/background";
2222
import { profile } from "../../../profiling";
23-
import { Frame, topmost } from "../../frame";
23+
import { topmost } from "../../frame";
2424
import { AndroidActivityBackPressedEventData, android as androidApp } from "../../../application";
2525

2626
export * from "./view-common";
@@ -269,24 +269,31 @@ export class View extends ViewCommon {
269269
let manager = this._manager;
270270
if (!manager) {
271271
let view: View = this;
272+
let frameOrTabFound = false;
272273
while (view) {
274+
// when interacting with nested fragments instead of using getSupportFragmentManager
275+
// we must always use getChildFragmentManager instead;
276+
// we have three sources of fragments -- Frame fragments, TabViewItem fragments, and
277+
// modal dialog fragments
278+
279+
// modal -> frame / tabview (frame / tabview use modal CHILD fm)
273280
const dialogFragment = view._dialogFragment;
274281
if (dialogFragment) {
275282
manager = dialogFragment.getChildFragmentManager();
276283
break;
277284
}
278-
279-
if (view instanceof Frame) {
280-
// when interacting with nested fragments instead of using getSupportFragmentManager
281-
// we must always use getChildFragmentManager
282-
const parentFrame: Frame = <Frame>getAncestor(view, Frame);
283-
if (parentFrame) {
284-
const backstackEntry = parentFrame._currentEntry || parentFrame._executingEntry;
285-
if (backstackEntry && backstackEntry.fragment && backstackEntry.fragment.isAdded()) {
286-
manager = backstackEntry.fragment.getChildFragmentManager();
287-
break;
288-
}
285+
286+
// - frame1 -> frame2 (frame2 uses frame1 CHILD fm)
287+
// - tabview -> frame1 (frame1 uses tabview item CHILD fm)
288+
// - frame1 -> tabview (tabview uses frame1 CHILD fm)
289+
// - frame1 -> tabview -> frame2 (tabview uses frame1 CHILD fm; frame2 uses tabview item CHILD fm)
290+
if (view.typeName === "Frame" || view.typeName === "TabView") {
291+
if (frameOrTabFound) {
292+
manager = (<any>view)._getChildFragmentManager();
293+
break;
289294
}
295+
296+
frameOrTabFound = true;
290297
}
291298

292299
// the case is needed because _dialogFragment is on View

‎tns-core-modules/ui/frame/frame.android.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ export class Frame extends FrameBase {
175175
}
176176
}
177177

178+
public _getChildFragmentManager() {
179+
const backstackEntry = this._executingEntry || this._currentEntry;
180+
if (backstackEntry && backstackEntry.fragment && backstackEntry.fragment.isAdded()) {
181+
return backstackEntry.fragment.getChildFragmentManager();
182+
}
183+
184+
return null;
185+
}
186+
178187
_onRootViewReset(): void {
179188
this.disposeCurrentFragment();
180189
super._onRootViewReset();

‎tns-core-modules/ui/tab-view/tab-view.android.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,17 @@ export class TabView extends TabViewBase {
361361
tabs.push(new WeakRef(this));
362362
}
363363

364+
public _getChildFragmentManager(): android.support.v4.app.FragmentManager {
365+
if (this._pagerAdapter) {
366+
const fragment: android.support.v4.app.Fragment = (<any>this._pagerAdapter).mCurrentPrimaryItem;
367+
if (fragment && fragment.isAdded()) {
368+
return fragment.getChildFragmentManager();
369+
}
370+
}
371+
372+
return null;
373+
}
374+
364375
public onItemsChanged(oldItems: TabViewItem[], newItems: TabViewItem[]): void {
365376
super.onItemsChanged(oldItems, newItems);
366377

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL