fix(android): nested dialog/fragment handling (#9495)

This commit is contained in:
Nathan Walker
2021-08-03 21:57:19 -07:00
committed by GitHub
parent 5309f2d0a7
commit 4c547bb00c
7 changed files with 78 additions and 4 deletions

View File

@@ -0,0 +1,24 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
<ActionBar>
<Label text="Nested Modal Tab"></Label>
</ActionBar>
<TabView selectedTabTextColor="green">
<TabViewItem title="First">
<GridLayout>
<Frame id="nestedFrame" defaultPage="nested-frames/nested-page" actionBarVisibility="always"></Frame>
</GridLayout>
</TabViewItem>
<TabViewItem title="Second">
<GridLayout>
<Frame id="nestedFrame" defaultPage="nested-frames/nested-page" actionBarVisibility="always"></Frame>
</GridLayout>
</TabViewItem>
<TabViewItem title="Third">
<GridLayout>
<Frame id="nestedFrame" defaultPage="nested-frames/nested-page" actionBarVisibility="always"></Frame>
</GridLayout>
</TabViewItem>
</TabView>
</Page>

View File

@@ -9,6 +9,14 @@ export function onShowingModally(args: ShownModallyData) {
onTap: function () { onTap: function () {
Dialogs.alert('it works!'); Dialogs.alert('it works!');
}, },
openNestedModal: function () {
page.showModal('modal-view/nested-nested-modal', {
context: 'Neste mODAL',
closeCallback: () => {
console.log('nested-modal.openNestedModal');
},
});
},
}); });
} }

View File

@@ -5,5 +5,6 @@
<StackLayout backgroundColor="PaleGreen" margin="10"> <StackLayout backgroundColor="PaleGreen" margin="10">
<Label text="{{ context }}"/> <Label text="{{ context }}"/>
<Button text="Show Alert" tap="{{ onTap }}"/> <Button text="Show Alert" tap="{{ onTap }}"/>
<Button text="Open Nested Modal" tap="{{ openNestedModal }}"/>
</StackLayout> </StackLayout>
</Page> </Page>

View File

@@ -0,0 +1,29 @@
import { Page, EventData, fromObject, Dialogs } from '@nativescript/core';
export function navigatingTo(args) {
const page = <Page>args.object;
page.bindingContext = fromObject({
context: args.context,
onTap: function () {
Dialogs.alert('it works!');
},
openNestedFrames: function () {
page.showModal('modal-view/nested-modal-tab', {
context: 'Nested Modal Tab',
fullscreen: true,
closeCallback: () => {
console.log('nested-modal.openNestedModal');
},
});
},
});
}
export function onLoaded(args: EventData) {
console.log('nested-nested-modal.onLoaded');
}
export function onUnloaded() {
console.log('nested-nested-modal.onUnloaded');
}

View File

@@ -0,0 +1,9 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd"
navigatingTo="navigatingTo"
loaded="onLoaded" unloaded="onUnloaded" backgroundColor="Red">
<StackLayout backgroundColor="PaleGreen" margin="10">
<Label text="{{ context }}"/>
<Button text="Show Alert" tap="{{ onTap }}"/>
<Button text="Open Nested Frames" tap="{{ openNestedFrames }}" />
</StackLayout>
</Page>

View File

@@ -0,0 +1 @@
<Frame defaultPage="modal-view/nested-nested-frame"></Frame>

View File

@@ -345,6 +345,9 @@ export class View extends ViewCommon {
} }
public _getFragmentManager(): androidx.fragment.app.FragmentManager { public _getFragmentManager(): androidx.fragment.app.FragmentManager {
if ((<any>global)._dialogFragment) {
return (<any>global)._dialogFragment.getChildFragmentManager();
}
let manager = this._manager; let manager = this._manager;
if (!manager) { if (!manager) {
let view: View = this; let view: View = this;
@@ -690,20 +693,19 @@ export class View extends ViewCommon {
}; };
saveModal(dialogOptions); saveModal(dialogOptions);
this._dialogFragment = df; this._dialogFragment = df;
(<any>global)._dialogFragment = df;
this._raiseShowingModallyEvent(); this._raiseShowingModallyEvent();
this._dialogFragment.show(parent._getRootFragmentManager(), this._domId.toString()); this._dialogFragment.show(parent._getRootFragmentManager(), this._domId.toString());
} }
protected _hideNativeModalView(parent: View, whenClosedCallback: () => void) { protected _hideNativeModalView(parent: View, whenClosedCallback: () => void) {
const manager = this._dialogFragment.getFragmentManager(); const manager = this._dialogFragment.getParentFragmentManager();
if (manager) { if (manager) {
this._dialogFragment.dismissAllowingStateLoss(); this._dialogFragment.dismissAllowingStateLoss();
} }
this._dialogFragment = null; this._dialogFragment = null;
(<any>global)._dialogFragment = null;
whenClosedCallback(); whenClosedCallback();
} }