Skip to content

Commit 4c547bb

Browse files
authored
fix(android): nested dialog/fragment handling (NativeScript#9495)
1 parent 5309f2d commit 4c547bb

File tree

7 files changed

+78
-4
lines changed

7 files changed

+78
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
2+
3+
<ActionBar>
4+
<Label text="Nested Modal Tab"></Label>
5+
</ActionBar>
6+
7+
<TabView selectedTabTextColor="green">
8+
<TabViewItem title="First">
9+
<GridLayout>
10+
<Frame id="nestedFrame" defaultPage="nested-frames/nested-page" actionBarVisibility="always"></Frame>
11+
</GridLayout>
12+
</TabViewItem>
13+
<TabViewItem title="Second">
14+
<GridLayout>
15+
<Frame id="nestedFrame" defaultPage="nested-frames/nested-page" actionBarVisibility="always"></Frame>
16+
</GridLayout>
17+
</TabViewItem>
18+
<TabViewItem title="Third">
19+
<GridLayout>
20+
<Frame id="nestedFrame" defaultPage="nested-frames/nested-page" actionBarVisibility="always"></Frame>
21+
</GridLayout>
22+
</TabViewItem>
23+
</TabView>
24+
</Page>

apps/ui/src/modal-view/nested-modal.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ export function onShowingModally(args: ShownModallyData) {
99
onTap: function () {
1010
Dialogs.alert('it works!');
1111
},
12+
openNestedModal: function () {
13+
page.showModal('modal-view/nested-nested-modal', {
14+
context: 'Neste mODAL',
15+
closeCallback: () => {
16+
console.log('nested-modal.openNestedModal');
17+
},
18+
});
19+
},
1220
});
1321
}
1422

apps/ui/src/modal-view/nested-modal.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<StackLayout backgroundColor="PaleGreen" margin="10">
66
<Label text="{{ context }}"/>
77
<Button text="Show Alert" tap="{{ onTap }}"/>
8+
<Button text="Open Nested Modal" tap="{{ openNestedModal }}"/>
89
</StackLayout>
910
</Page>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Page, EventData, fromObject, Dialogs } from '@nativescript/core';
2+
3+
export function navigatingTo(args) {
4+
const page = <Page>args.object;
5+
6+
page.bindingContext = fromObject({
7+
context: args.context,
8+
onTap: function () {
9+
Dialogs.alert('it works!');
10+
},
11+
openNestedFrames: function () {
12+
page.showModal('modal-view/nested-modal-tab', {
13+
context: 'Nested Modal Tab',
14+
fullscreen: true,
15+
closeCallback: () => {
16+
console.log('nested-modal.openNestedModal');
17+
},
18+
});
19+
},
20+
});
21+
}
22+
23+
export function onLoaded(args: EventData) {
24+
console.log('nested-nested-modal.onLoaded');
25+
}
26+
27+
export function onUnloaded() {
28+
console.log('nested-nested-modal.onUnloaded');
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
2+
navigatingTo="navigatingTo"
3+
loaded="onLoaded" unloaded="onUnloaded" backgroundColor="Red">
4+
<StackLayout backgroundColor="PaleGreen" margin="10">
5+
<Label text="{{ context }}"/>
6+
<Button text="Show Alert" tap="{{ onTap }}"/>
7+
<Button text="Open Nested Frames" tap="{{ openNestedFrames }}" />
8+
</StackLayout>
9+
</Page>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Frame defaultPage="modal-view/nested-nested-frame"></Frame>

packages/core/ui/core/view/index.android.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ export class View extends ViewCommon {
345345
}
346346

347347
public _getFragmentManager(): androidx.fragment.app.FragmentManager {
348+
if ((<any>global)._dialogFragment) {
349+
return (<any>global)._dialogFragment.getChildFragmentManager();
350+
}
348351
let manager = this._manager;
349352
if (!manager) {
350353
let view: View = this;
@@ -690,20 +693,19 @@ export class View extends ViewCommon {
690693
};
691694

692695
saveModal(dialogOptions);
693-
694696
this._dialogFragment = df;
697+
(<any>global)._dialogFragment = df;
695698
this._raiseShowingModallyEvent();
696-
697699
this._dialogFragment.show(parent._getRootFragmentManager(), this._domId.toString());
698700
}
699701

700702
protected _hideNativeModalView(parent: View, whenClosedCallback: () => void) {
701-
const manager = this._dialogFragment.getFragmentManager();
703+
const manager = this._dialogFragment.getParentFragmentManager();
702704
if (manager) {
703705
this._dialogFragment.dismissAllowingStateLoss();
704706
}
705-
706707
this._dialogFragment = null;
708+
(<any>global)._dialogFragment = null;
707709
whenClosedCallback();
708710
}
709711

0 commit comments

Comments
 (0)