Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/toolbox/src/pages/a11y.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export class AccessibilityModel extends Observable {
}

openModal() {
page.showModal('pages/sample-modal');
page.showModal('pages/sample-modal', {
closeCallback(args) {
console.log('close modal callback', args);
},
} as ShowModalOptions);
}

openNormal() {
page.frame.navigate('pages/sample-modal');
}
}
4 changes: 3 additions & 1 deletion apps/toolbox/src/pages/a11y.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<GridLayout padding="20" class="a11y-demo-page">
<ScrollView>
<StackLayout>
<Button text="Open Modal Page" class="view-item" tap="{{openModal}}" />
<Button text="Open Normal Page" class="view-item" tap="{{openNormal}}" />

<Label text="Accessible Label" class="view-item a11y text-center" accessibilityLabel="Accessible Label" accessibilityHint="Just a label" accessibilityRole="{{accessibilityRole.StaticText}}" accessibilityValue="Accessible Label" />
<Button text="Accessible Button" class="view-item a11y" accessibilityLabel="Accessible Button" accessibilityHint="Tapping this really does nothing" />

Expand All @@ -30,7 +33,6 @@
<Label row="1" text="With another item in a row" class="view-item text-center" />
<Label rowSpan="2" col="1" text="Hi" />
</GridLayout>
<Button text="Open Modal" class="view-item" tap="{{openModal}}" />
<Slider value="10" minValue="0" maxValue="100" class="view-item a11y" accessibilityLabel="Slider" accessibilityHint="A smooth slider" accessibilityValue="10" />
</StackLayout>
</ScrollView>
Expand Down
31 changes: 27 additions & 4 deletions apps/toolbox/src/pages/sample-modal.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
import { Page, ShownModallyData, Observable } from '@nativescript/core';
import { Page, ShownModallyData, Observable, LoadEventData } from '@nativescript/core';

let page: Page;
let closeCallback: Function;
export function onShownModally(args: ShownModallyData) {
page = <Page>args.object;
page.bindingContext = new SampleModal();
console.log('page shown modally');

closeCallback = args.closeCallback;

if (args.context) {
args.context.shownModally = true;
}
}

export function onLoaded(args: LoadEventData) {
console.log('page loaded');

page = args.object as Page;
page.bindingContext = new SampleModal();

const disposePage = page.disposeNativeView.bind(page);
page.disposeNativeView = () => {
console.log('-'.repeat(100));
console.log(' [!!] Disposing modal page...');
console.log('-'.repeat(100));

disposePage();
};
}

export class SampleModal extends Observable {
close() {
// TODO: a11y
// if (global.isIOS) {
// (<UIViewController>page.ios).view.accessibilityPerformEscape();
// }
closeCallback();
if (typeof closeCallback === 'function') {
closeCallback('data from modal');
// reset callback...
closeCallback = undefined;
} else {
// fallback to regular nav back...
page.frame.goBack();
}
}
}
2 changes: 1 addition & 1 deletion apps/toolbox/src/pages/sample-modal.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" shownModally="onShownModally" class="page">
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded" shownModally="onShownModally" class="page">

<GridLayout padding="20">
<ScrollView>
Expand Down
2 changes: 2 additions & 0 deletions packages/core/ui/core/view/view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
if (typeof options.closeCallback === 'function') {
options.closeCallback.apply(undefined, originalArgs);
}

that._tearDownUI(true);
};

that._hideNativeModalView(parent, whenClosedCallback);
Expand Down