refactor(action-sheet): pass dismiss info to events

This commit is contained in:
Dan Bucholtz
2017-12-02 00:24:45 -06:00
parent c6df225014
commit ece30bb35a
2 changed files with 48 additions and 43 deletions

View File

@ -1,5 +1,12 @@
import { Component, CssClassMap, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core'; import { Component, CssClassMap, Element, Event, EventEmitter, Listen, Method, Prop } from '@stencil/core';
import { Animation, AnimationBuilder, AnimationController, Config, OverlayDismissEvent, OverlayDismissEventDetail } from '../../index'; import {
Animation,
AnimationBuilder,
AnimationController,
Config,
OverlayDismissEvent,
OverlayDismissEventDetail
} from '../../index';
import { domControllerAsync, playAnimationAsync } from '../../utils/helpers'; import { domControllerAsync, playAnimationAsync } from '../../utils/helpers';
import { createThemedClasses } from '../../utils/theme'; import { createThemedClasses } from '../../utils/theme';
@ -122,7 +129,7 @@ export class ActionSheet {
const animationBuilder = this.enterAnimation || this.config.get('actionSheetEnter', this.mode === 'ios' ? iosEnterAnimation : mdEnterAnimation); const animationBuilder = this.enterAnimation || this.config.get('actionSheetEnter', this.mode === 'ios' ? iosEnterAnimation : mdEnterAnimation);
// build the animation and kick it off // build the animation and kick it off
this.animationCtrl.create(animationBuilder, this.el).then(animation => { return this.animationCtrl.create(animationBuilder, this.el).then(animation => {
this.animation = animation; this.animation = animation;
if (!this.animate) { if (!this.animate) {
// if the duration is 0, it won't actually animate I don't think // if the duration is 0, it won't actually animate I don't think
@ -140,12 +147,15 @@ export class ActionSheet {
* Dismiss the action-sheet programatically * Dismiss the action-sheet programatically
*/ */
@Method() @Method()
dismiss() { dismiss(data?: any, role?: string) {
if (this.animation) { if (this.animation) {
this.animation.destroy(); this.animation.destroy();
this.animation = null; this.animation = null;
} }
this.ionActionSheetWillDismiss.emit(); this.ionActionSheetWillDismiss.emit({
data,
role
});
const animationBuilder = this.leaveAnimation || this.config.get('actionSheetLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation); const animationBuilder = this.leaveAnimation || this.config.get('actionSheetLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation);
@ -158,7 +168,10 @@ export class ActionSheet {
this.el.parentNode.removeChild(this.el); this.el.parentNode.removeChild(this.el);
}); });
}).then(() => { }).then(() => {
this.ionActionSheetDidDismiss.emit(); this.ionActionSheetDidDismiss.emit({
data,
role
});
}); });
} }

View File

@ -49,8 +49,10 @@
function presentBasic() { function presentBasic() {
var mode = Ionic.mode; var mode = Ionic.mode;
var actionSheetController = document.querySelector('ion-action-sheet-controller'); const actionSheetController = document.querySelector('ion-action-sheet-controller');
actionSheetController.create({ await actionSheetController.componentOnReady();
const actionSheetElement = await actionSheetController.create({
title: "Albums", title: "Albums",
buttons: [{ buttons: [{
text: 'Delete', text: 'Delete',
@ -87,14 +89,13 @@
}], }],
translucent: true translucent: true
}) })
.then(actionSheet => { await actionSheetElement.present();
actionSheet.present()
});
} }
function presentNoBackdropDismiss() { async function presentNoBackdropDismiss() {
var actionSheetController = document.querySelector('ion-action-sheet-controller'); const actionSheetController = document.querySelector('ion-action-sheet-controller');
actionSheetController.create({ await actionSheetController.componentOnReady();
const actionSheetElement = await actionSheetController.create({
buttons: [{ buttons: [{
text: 'Archive', text: 'Archive',
handler: () => { handler: () => {
@ -114,15 +115,14 @@
} }
}], }],
translucent: true translucent: true
})
.then(actionSheet => {
actionSheet.present()
}); });
return await actionSheetElement.present();
} }
function presentAlert() { async function presentAlert() {
var actionSheetController = document.querySelector('ion-action-sheet-controller'); const actionSheetController = document.querySelector('ion-action-sheet-controller');
actionSheetController.create({ await actionSheetController.componentOnReady();
const actionSheetElement = await actionSheetController.create({
buttons: [{ buttons: [{
text: 'Open Alert', text: 'Open Alert',
handler: () => { handler: () => {
@ -136,16 +136,14 @@
} }
}], }],
translucent: true translucent: true
})
.then(actionSheet => {
actionSheet.present()
}); });
return await actionSheetElement.present();
} }
function presentScroll() { async function presentScroll() {
var actionSheetController = document.querySelector('ion-action-sheet-controller'); const actionSheetController = document.querySelector('ion-action-sheet-controller');
await actionSheetController.componentOnReady();
actionSheetController.create({ const actionSheetElement = await actionSheetController.create({
buttons: [ buttons: [
{ {
text: 'Add Reaction', text: 'Add Reaction',
@ -217,16 +215,14 @@
} }
], ],
translucent: true translucent: true
})
.then(actionSheet => {
actionSheet.present()
}); });
return await actionSheetElement.present();
} }
function presentScrollNoCancel() { async function presentScrollNoCancel() {
var actionSheetController = document.querySelector('ion-action-sheet-controller'); const actionSheetController = document.querySelector('ion-action-sheet-controller');
await actionSheetController.componentOnReady();
actionSheetController.create({ const actionSheetElement = await actionSheetController.create({
buttons: [ buttons: [
{ {
text: 'Add Reaction', text: 'Add Reaction',
@ -292,16 +288,14 @@
} }
], ],
translucent: true translucent: true
})
.then(actionSheet => {
actionSheet.present()
}); });
return await actionSheetElement.present();
} }
function presentCancelOnly() { async function presentCancelOnly() {
var actionSheetController = document.querySelector('ion-action-sheet-controller'); const actionSheetController = document.querySelector('ion-action-sheet-controller');
await actionSheetController.componentOnReady();
actionSheetController.create({ const actionSheetElement = await actionSheetController.create({
buttons: [ buttons: [
{ {
text: 'Cancel', text: 'Cancel',
@ -312,10 +306,8 @@
} }
], ],
translucent: true translucent: true
})
.then(actionSheet => {
actionSheet.present()
}); });
return await actionSheetElement.present();
} }
</script> </script>