mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +08:00
modal updates
This commit is contained in:
189
CHANGELOG.md
189
CHANGELOG.md
@ -1,3 +1,192 @@
|
|||||||
|
<a name="2.0.0-alpha.46"></a>
|
||||||
|
# 2.0.0-alpha.46 (2016-1-4)
|
||||||
|
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
##### Overlay Refactor
|
||||||
|
|
||||||
|
* `<ion-overlay></ion-overlay>` is no longer required within any template
|
||||||
|
* `Popup` has been renamed to `Alert`
|
||||||
|
* Common API for all overlays: `Alert`, `ActionSheet`, `Modal`, etc.
|
||||||
|
* `Alert` is more generic and you can mix and match any number of buttons/inputs
|
||||||
|
* `Alert` and `ActionSheet` can take an array of buttons with `handlers`
|
||||||
|
* Returning `false` from button handlers prevent the overlay from closing
|
||||||
|
* All overlays use `NavController` `present()`, similar to `push()`
|
||||||
|
* A `Modal` uses an injected `ViewController` to dismiss itself
|
||||||
|
and optionally pass data to modal's `onDismss()`
|
||||||
|
|
||||||
|
##### Alert Refactor
|
||||||
|
|
||||||
|
Was:
|
||||||
|
|
||||||
|
```
|
||||||
|
import {Popup} from 'ionic/ionic';
|
||||||
|
|
||||||
|
@Page(...)
|
||||||
|
class MyPage {
|
||||||
|
constructor(popup: Popup) {
|
||||||
|
this.popup = popup;
|
||||||
|
}
|
||||||
|
doAlert() {
|
||||||
|
this.popup.alert({
|
||||||
|
title: "New Friend!",
|
||||||
|
template: "Obi wan Kenobi just accepted your friend request!"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now:
|
||||||
|
|
||||||
|
```
|
||||||
|
import {Alert, NavController} from 'ionic/ionic';
|
||||||
|
|
||||||
|
@Page(...)
|
||||||
|
class MyPage {
|
||||||
|
constructor(nav: NavController) {
|
||||||
|
this.nav = nav;
|
||||||
|
}
|
||||||
|
doAlert() {
|
||||||
|
let alert = Alert.create({
|
||||||
|
title: "New Friend!",
|
||||||
|
body: "Obi wan Kenobi just accepted your friend request!",
|
||||||
|
buttons: ['Ok']
|
||||||
|
});
|
||||||
|
|
||||||
|
this.nav.present(alert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Confirm Refactor
|
||||||
|
|
||||||
|
Was:
|
||||||
|
|
||||||
|
```
|
||||||
|
import {Popup} from 'ionic/ionic';
|
||||||
|
|
||||||
|
@Page(...)
|
||||||
|
class MyPage {
|
||||||
|
constructor(popup: Popup) {
|
||||||
|
this.popup = popup;
|
||||||
|
}
|
||||||
|
doConfirm() {
|
||||||
|
this.popup.confirm({
|
||||||
|
title: "Use this lightsaber?",
|
||||||
|
subTitle: "You can't exchange lightsabers",
|
||||||
|
template: "Do you agree to use this lightsaber to do good across the intergalactic galaxy?",
|
||||||
|
cancelText: "Disagree",
|
||||||
|
okText: "Agree"
|
||||||
|
}).then((result, ev) => {
|
||||||
|
console.log('Confirmed!', result);
|
||||||
|
}, () => {
|
||||||
|
console.error('Not confirmed!');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Now:
|
||||||
|
|
||||||
|
```
|
||||||
|
import {Alert, NavController} from 'ionic/ionic';
|
||||||
|
|
||||||
|
@Page(...)
|
||||||
|
class MyPage {
|
||||||
|
constructor(nav: NavController) {
|
||||||
|
this.nav = nav;
|
||||||
|
}
|
||||||
|
doConfirm() {
|
||||||
|
let alert = Alert.create({
|
||||||
|
title: "New Friend!",
|
||||||
|
body: "Obi wan Kenobi just accepted your friend request!",
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
text: 'Agree',
|
||||||
|
handler: () => {
|
||||||
|
console.log('Agreed!');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Disagree',
|
||||||
|
handler: () => {
|
||||||
|
console.log('Disagreed :(');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
this.nav.present(alert);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Prompt Refactor
|
||||||
|
|
||||||
|
Was:
|
||||||
|
|
||||||
|
```
|
||||||
|
import {Popup} from 'ionic/ionic';
|
||||||
|
|
||||||
|
@Page(...)
|
||||||
|
class MyPage {
|
||||||
|
constructor(popup: Popup) {
|
||||||
|
this.popup = popup;
|
||||||
|
}
|
||||||
|
doPrompt() {
|
||||||
|
this.popup.prompt({
|
||||||
|
title: "New Album",
|
||||||
|
template: "Enter a name for this new album you're so keen on adding",
|
||||||
|
inputPlaceholder: "Album Name",
|
||||||
|
okText: "Save",
|
||||||
|
okType: "secondary"
|
||||||
|
}).then((name) => {
|
||||||
|
console.log('Name entered:', name);
|
||||||
|
}, () => {
|
||||||
|
console.error('Prompt closed');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Now:
|
||||||
|
|
||||||
|
```
|
||||||
|
import {Alert, NavController} from 'ionic/ionic';
|
||||||
|
|
||||||
|
@Page(...)
|
||||||
|
class MyPage {
|
||||||
|
constructor(nav: NavController) {
|
||||||
|
this.nav = nav;
|
||||||
|
}
|
||||||
|
doConfirm() {
|
||||||
|
let alert = Alert.create({
|
||||||
|
title: "New Album",
|
||||||
|
body: "Enter a name for this new album you're so keen on adding",
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: 'album',
|
||||||
|
placeholder: 'Album Name'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
text: 'Cancel',
|
||||||
|
handler: data => {
|
||||||
|
console.log('Canceled!', data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Ok',
|
||||||
|
handler: data => {
|
||||||
|
console.log('Submitted', data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
this.nav.present(alert);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
<a name="2.0.0-alpha.42"></a>
|
<a name="2.0.0-alpha.42"></a>
|
||||||
# 2.0.0-alpha.42 (2015-12-11)
|
# 2.0.0-alpha.42 (2015-12-11)
|
||||||
|
|
||||||
|
@ -38,15 +38,15 @@ import {Animation} from '../../animations/animation';
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTitle(title) {
|
setTitle(title) {
|
||||||
this._data.title = title;
|
this.data.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSubTitle(subTitle) {
|
setSubTitle(subTitle) {
|
||||||
this._data.subTitle = subTitle;
|
this.data.subTitle = subTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
addButton(button) {
|
addButton(button) {
|
||||||
this._data.buttons.push(button);
|
this.data.buttons.push(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
static create(data={}) {
|
static create(data={}) {
|
||||||
|
@ -24,23 +24,23 @@ export class Alert extends ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTitle(title) {
|
setTitle(title) {
|
||||||
this._data.title = title;
|
this.data.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
setSubTitle(subTitle) {
|
setSubTitle(subTitle) {
|
||||||
this._data.subTitle = subTitle;
|
this.data.subTitle = subTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
setBody(body) {
|
setBody(body) {
|
||||||
this._data.body = body;
|
this.data.body = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
addInput(input) {
|
addInput(input) {
|
||||||
this._data.inputs.push(input);
|
this.data.inputs.push(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
addButton(button) {
|
addButton(button) {
|
||||||
this._data.buttons.push(button);
|
this.data.buttons.push(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
static create(data={}) {
|
static create(data={}) {
|
||||||
|
@ -32,8 +32,8 @@ class E2EPage {
|
|||||||
let modal = Modal.create(ModalPassData, { userId: 8675309 });
|
let modal = Modal.create(ModalPassData, { userId: 8675309 });
|
||||||
this.nav.present(modal);
|
this.nav.present(modal);
|
||||||
|
|
||||||
modal.data.subscribe(data => {
|
modal.onDismiss(data => {
|
||||||
console.log('data', data);
|
console.log('modal data', data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +45,10 @@ class E2EPage {
|
|||||||
presentToolbarModal() {
|
presentToolbarModal() {
|
||||||
let modal = Modal.create(ToolbarModal);
|
let modal = Modal.create(ToolbarModal);
|
||||||
this.nav.present(modal);
|
this.nav.present(modal);
|
||||||
|
|
||||||
|
modal.subscribe(data => {
|
||||||
|
console.log('modal data', data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
presentModalCustomAnimation() {
|
presentModalCustomAnimation() {
|
||||||
@ -86,8 +90,7 @@ class ModalPassData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
this.viewCtrl.data.emit(this.data);
|
this.viewCtrl.dismiss(this.data);
|
||||||
this.viewCtrl.dismiss();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +119,9 @@ class ToolbarModal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dismiss() {
|
dismiss() {
|
||||||
|
this.viewCtrl.emit({
|
||||||
|
toolbar: 'data'
|
||||||
|
});
|
||||||
this.viewCtrl.dismiss();
|
this.viewCtrl.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,20 +17,32 @@ import {NavParams} from './nav-controller';
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export class ViewController {
|
export class ViewController {
|
||||||
@Output() data: EventEmitter<any> = new EventEmitter();
|
@Output() _emitter: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
constructor(componentType, data={}) {
|
constructor(componentType, data={}) {
|
||||||
this.componentType = componentType;
|
this.componentType = componentType;
|
||||||
this._data = data;
|
this.data = data;
|
||||||
this.instance = {};
|
this.instance = {};
|
||||||
this.state = 0;
|
this.state = 0;
|
||||||
this._destroys = [];
|
this._destroys = [];
|
||||||
this._loaded = false;
|
this._loaded = false;
|
||||||
this._outputData = null;
|
|
||||||
this.shouldDestroy = false;
|
this.shouldDestroy = false;
|
||||||
this.shouldCache = false;
|
this.shouldCache = false;
|
||||||
this.viewType = '';
|
this.viewType = '';
|
||||||
this._leavingOpts = null;
|
this._leavingOpts = null;
|
||||||
|
this._onDismiss = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribe(callback) {
|
||||||
|
this._emitter.subscribe(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(data) {
|
||||||
|
this._emitter.emit(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
onDismiss(callback) {
|
||||||
|
this._onDismiss = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
setNav(navCtrl) {
|
setNav(navCtrl) {
|
||||||
@ -42,10 +54,11 @@ export class ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getNavParams() {
|
getNavParams() {
|
||||||
return new NavParams(this._data);
|
return new NavParams(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
dismiss() {
|
dismiss(data) {
|
||||||
|
this._onDismiss && this._onDismiss(data);
|
||||||
return this._nav.remove(this._nav.indexOf(this), this._leavingOpts);
|
return this._nav.remove(this._nav.indexOf(this), this._leavingOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user