mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 21:48:42 +08:00
refactor(modal): add css classes after createComponent
This commit is contained in:
@ -1,10 +1,10 @@
|
|||||||
import {Component, ComponentResolver, HostListener, ViewChild, ViewContainerRef} from '@angular/core';
|
import {Component, ComponentResolver, HostListener, Renderer, ViewChild, ViewContainerRef} from '@angular/core';
|
||||||
|
|
||||||
import {addSelector} from '../../config/bootstrap';
|
import {addSelector} from '../../config/bootstrap';
|
||||||
import {Animation} from '../../animations/animation';
|
import {Animation} from '../../animations/animation';
|
||||||
import {NavParams} from '../nav/nav-params';
|
|
||||||
import {isPresent, pascalCaseToDashCase} from '../../util/util';
|
import {isPresent, pascalCaseToDashCase} from '../../util/util';
|
||||||
import {Key} from '../../util/key';
|
import {Key} from '../../util/key';
|
||||||
|
import {NavParams} from '../nav/nav-params';
|
||||||
import {PageTransition} from '../../transitions/page-transition';
|
import {PageTransition} from '../../transitions/page-transition';
|
||||||
import {TransitionOptions} from '../../transitions/transition';
|
import {TransitionOptions} from '../../transitions/transition';
|
||||||
import {ViewController} from '../nav/view-controller';
|
import {ViewController} from '../nav/view-controller';
|
||||||
@ -113,23 +113,20 @@ import {windowDimensions} from '../../util/dom';
|
|||||||
*/
|
*/
|
||||||
export class Modal extends ViewController {
|
export class Modal extends ViewController {
|
||||||
|
|
||||||
public modalViewType: string;
|
|
||||||
|
|
||||||
constructor(componentType: any, data: any = {}, opts: ModalOptions = {}) {
|
constructor(componentType: any, data: any = {}, opts: ModalOptions = {}) {
|
||||||
data.componentType = componentType;
|
data.componentType = componentType;
|
||||||
opts.showBackdrop = isPresent(opts.showBackdrop) ? !!opts.showBackdrop : true;
|
opts.showBackdrop = isPresent(opts.showBackdrop) ? !!opts.showBackdrop : true;
|
||||||
opts.enableBackdropDismiss = isPresent(opts.enableBackdropDismiss) ? !!opts.enableBackdropDismiss : true;
|
opts.enableBackdropDismiss = isPresent(opts.enableBackdropDismiss) ? !!opts.enableBackdropDismiss : true;
|
||||||
data.opts = opts;
|
data.opts = opts;
|
||||||
|
|
||||||
super(ModalCmp, data);
|
super(ModalCmp, data);
|
||||||
this.modalViewType = componentType.name;
|
|
||||||
this.viewType = 'modal';
|
|
||||||
this.isOverlay = true;
|
this.isOverlay = true;
|
||||||
this.usePortal = true;
|
this.usePortal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
getTransitionName(direction: string) {
|
getTransitionName(direction: string) {
|
||||||
let key = (direction === 'back' ? 'modalLeave' : 'modalEnter');
|
let key = (direction === 'back' ? 'modalLeave' : 'modalEnter');
|
||||||
return this._nav && this._nav.config.get(key);
|
return this._nav && this._nav.config.get(key);
|
||||||
@ -176,7 +173,7 @@ export interface ModalOptions {
|
|||||||
template:
|
template:
|
||||||
'<ion-backdrop disableScroll="false" (click)="bdClick($event)"></ion-backdrop>' +
|
'<ion-backdrop disableScroll="false" (click)="bdClick($event)"></ion-backdrop>' +
|
||||||
'<div class="modal-wrapper">' +
|
'<div class="modal-wrapper">' +
|
||||||
'<div #viewport></div>' +
|
'<div #viewport nav-viewport></div>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
})
|
})
|
||||||
export class ModalCmp {
|
export class ModalCmp {
|
||||||
@ -186,16 +183,18 @@ export class ModalCmp {
|
|||||||
private d: any;
|
private d: any;
|
||||||
private enabled: boolean;
|
private enabled: boolean;
|
||||||
|
|
||||||
constructor(private _compiler: ComponentResolver, private _navParams: NavParams, private _viewCtrl: ViewController) {
|
constructor(private _compiler: ComponentResolver, private _renderer: Renderer, private _navParams: NavParams, private _viewCtrl: ViewController) {
|
||||||
this.d = _navParams.data.opts;
|
this.d = _navParams.data.opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadComponent(done: Function) {
|
loadComponent(done: Function) {
|
||||||
addSelector(this._navParams.data.componentType, 'ion-page');
|
let componentType = this._navParams.data.componentType;
|
||||||
|
addSelector(componentType, 'ion-page');
|
||||||
|
|
||||||
this._compiler.resolveComponent(this._navParams.data.componentType).then((componentFactory) => {
|
this._compiler.resolveComponent(componentType).then((componentFactory) => {
|
||||||
let componentRef = this.viewport.createComponent(componentFactory, this.viewport.length, this.viewport.parentInjector);
|
let componentRef = this.viewport.createComponent(componentFactory, this.viewport.length, this.viewport.parentInjector);
|
||||||
|
this._renderer.setElementClass(componentRef.location.nativeElement, 'show-page', true);
|
||||||
|
this._renderer.setElementClass(componentRef.location.nativeElement, componentType.name, true);
|
||||||
this._viewCtrl.setInstance(componentRef.instance);
|
this._viewCtrl.setInstance(componentRef.instance);
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
done();
|
done();
|
||||||
@ -235,13 +234,6 @@ export class ModalCmp {
|
|||||||
let backdropEle = ele.querySelector('ion-backdrop');
|
let backdropEle = ele.querySelector('ion-backdrop');
|
||||||
let backdrop = new Animation(backdropEle);
|
let backdrop = new Animation(backdropEle);
|
||||||
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
|
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
|
||||||
let page = <HTMLElement> ele.querySelector('ion-page');
|
|
||||||
let pageAnimation = new Animation(page);
|
|
||||||
|
|
||||||
// auto-add page css className created from component JS class name
|
|
||||||
let cssClassName = pascalCaseToDashCase((<Modal>enteringView).modalViewType);
|
|
||||||
pageAnimation.before.addClass(cssClassName);
|
|
||||||
pageAnimation.before.addClass('show-page');
|
|
||||||
|
|
||||||
backdrop.fromTo('opacity', 0.01, 0.4);
|
backdrop.fromTo('opacity', 0.01, 0.4);
|
||||||
wrapper.fromTo('translateY', '100%', '0%');
|
wrapper.fromTo('translateY', '100%', '0%');
|
||||||
@ -252,8 +244,7 @@ export class ModalCmp {
|
|||||||
.easing('cubic-bezier(0.36,0.66,0.04,1)')
|
.easing('cubic-bezier(0.36,0.66,0.04,1)')
|
||||||
.duration(400)
|
.duration(400)
|
||||||
.add(backdrop)
|
.add(backdrop)
|
||||||
.add(wrapper)
|
.add(wrapper);
|
||||||
.add(pageAnimation);
|
|
||||||
|
|
||||||
if (enteringView.hasNavbar()) {
|
if (enteringView.hasNavbar()) {
|
||||||
// entering page has a navbar
|
// entering page has a navbar
|
||||||
@ -300,14 +291,6 @@ class ModalMDSlideIn extends PageTransition {
|
|||||||
let ele = enteringView.pageRef().nativeElement;
|
let ele = enteringView.pageRef().nativeElement;
|
||||||
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
|
let backdrop = new Animation(ele.querySelector('ion-backdrop'));
|
||||||
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
|
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
|
||||||
let page = <HTMLElement> ele.querySelector('ion-page');
|
|
||||||
let pageAnimation = new Animation(page);
|
|
||||||
|
|
||||||
// auto-add page css className created from component JS class name
|
|
||||||
let cssClassName = pascalCaseToDashCase((<Modal>enteringView).modalViewType);
|
|
||||||
pageAnimation.before.addClass(cssClassName);
|
|
||||||
pageAnimation.before.addClass('show-page');
|
|
||||||
|
|
||||||
|
|
||||||
backdrop.fromTo('opacity', 0.01, 0.4);
|
backdrop.fromTo('opacity', 0.01, 0.4);
|
||||||
wrapper.fromTo('translateY', '40px', '0px');
|
wrapper.fromTo('translateY', '40px', '0px');
|
||||||
@ -317,8 +300,7 @@ class ModalMDSlideIn extends PageTransition {
|
|||||||
const EASING = 'cubic-bezier(0.36,0.66,0.04,1)';
|
const EASING = 'cubic-bezier(0.36,0.66,0.04,1)';
|
||||||
this.element(enteringView.pageRef()).easing(EASING).duration(DURATION)
|
this.element(enteringView.pageRef()).easing(EASING).duration(DURATION)
|
||||||
.add(backdrop)
|
.add(backdrop)
|
||||||
.add(wrapper)
|
.add(wrapper);
|
||||||
.add(pageAnimation);
|
|
||||||
|
|
||||||
if (enteringView.hasNavbar()) {
|
if (enteringView.hasNavbar()) {
|
||||||
// entering page has a navbar
|
// entering page has a navbar
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {ionicBootstrap, Config, Platform} from '../../../../../src';
|
import {ionicBootstrap, Config, Platform} from '../../../../../src';
|
||||||
import {Modal, ActionSheet, NavController, NavParams, Transition, TransitionOptions, ViewController} from '../../../../../src';
|
import {Modal, ActionSheet, NavController, NavParams, PageTransition, TransitionOptions, ViewController} from '../../../../../src';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: 'main.html'
|
templateUrl: 'main.html'
|
||||||
})
|
})
|
||||||
class E2EPage {
|
class E2EPage {
|
||||||
platforms;
|
platforms: string[];
|
||||||
|
|
||||||
constructor(private nav: NavController, config: Config, platform: Platform) {
|
constructor(private nav: NavController, config: Config, platform: Platform) {
|
||||||
console.log('platforms', platform.platforms());
|
console.log('platforms', platform.platforms());
|
||||||
@ -36,7 +36,7 @@ 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.onDismiss(data => {
|
modal.onDismiss((data: any) => {
|
||||||
console.log('modal data', data);
|
console.log('modal data', data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -50,14 +50,14 @@ class E2EPage {
|
|||||||
let modal = Modal.create(ToolbarModal);
|
let modal = Modal.create(ToolbarModal);
|
||||||
this.nav.present(modal);
|
this.nav.present(modal);
|
||||||
|
|
||||||
modal.subscribe(data => {
|
modal.subscribe((data: any) => {
|
||||||
console.log('modal data', data);
|
console.log('modal data', data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
presentModalWithInputs() {
|
presentModalWithInputs() {
|
||||||
let modal = Modal.create(ModalWithInputs);
|
let modal = Modal.create(ModalWithInputs);
|
||||||
modal.onDismiss((data) => {
|
modal.onDismiss((data: any) => {
|
||||||
console.log('Modal with inputs data:', data);
|
console.log('Modal with inputs data:', data);
|
||||||
});
|
});
|
||||||
this.nav.present(modal);
|
this.nav.present(modal);
|
||||||
@ -79,9 +79,12 @@ class E2EPage {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
<ion-navbar *navbar>
|
<ion-header>
|
||||||
<ion-title>Page One</ion-title>
|
<ion-navbar>
|
||||||
</ion-navbar>
|
<ion-title>Page One</ion-title>
|
||||||
|
</ion-navbar>
|
||||||
|
</ion-header>
|
||||||
|
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<button full (click)="submit()">Submit</button>
|
<button full (click)="submit()">Submit</button>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
@ -98,9 +101,12 @@ class NavigableModal{
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
<ion-navbar *navbar>
|
<ion-header>
|
||||||
<ion-title>Page Two</ion-title>
|
<ion-navbar>
|
||||||
</ion-navbar>
|
<ion-title>Page Two</ion-title>
|
||||||
|
</ion-navbar>
|
||||||
|
</ion-header>
|
||||||
|
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<button full (click)="submit()">Submit</button>
|
<button full (click)="submit()">Submit</button>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
@ -119,9 +125,11 @@ class NavigableModal2{
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
<ion-navbar *navbar>
|
<ion-header>
|
||||||
<ion-title>Data in/out</ion-title>
|
<ion-navbar>
|
||||||
</ion-navbar>
|
<ion-title>Data in/out</ion-title>
|
||||||
|
</ion-navbar>
|
||||||
|
</ion-header>
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<ion-list>
|
<ion-list>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
@ -138,7 +146,7 @@ class NavigableModal2{
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
class ModalPassData {
|
class ModalPassData {
|
||||||
data;
|
data: any;
|
||||||
|
|
||||||
constructor(params: NavParams, private viewCtrl: ViewController) {
|
constructor(params: NavParams, private viewCtrl: ViewController) {
|
||||||
this.data = {
|
this.data = {
|
||||||
@ -175,13 +183,15 @@ class ModalPassData {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
<ion-toolbar primary>
|
<ion-header>
|
||||||
<ion-title>Toolbar 1</ion-title>
|
<ion-toolbar primary>
|
||||||
</ion-toolbar>
|
<ion-title>Toolbar 1</ion-title>
|
||||||
|
</ion-toolbar>
|
||||||
|
|
||||||
<ion-toolbar>
|
<ion-toolbar>
|
||||||
<ion-title>Toolbar 2</ion-title>
|
<ion-title>Toolbar 2</ion-title>
|
||||||
</ion-toolbar>
|
</ion-toolbar>
|
||||||
|
</ion-header>
|
||||||
|
|
||||||
<ion-content padding>
|
<ion-content padding>
|
||||||
<button block danger (click)="dismiss()" class="e2eCloseToolbarModal">
|
<button block danger (click)="dismiss()" class="e2eCloseToolbarModal">
|
||||||
@ -220,12 +230,15 @@ class ToolbarModal {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
<ion-toolbar secondary>
|
<ion-header>
|
||||||
<ion-buttons start>
|
<ion-toolbar secondary>
|
||||||
<button (click)="dismiss()">Close</button>
|
<ion-buttons start>
|
||||||
</ion-buttons>
|
<button (click)="dismiss()">Close</button>
|
||||||
<ion-title>Modal w/ Inputs</ion-title>
|
</ion-buttons>
|
||||||
</ion-toolbar>
|
<ion-title>Modal w/ Inputs</ion-title>
|
||||||
|
</ion-toolbar>
|
||||||
|
</ion-header>
|
||||||
|
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<form #addForm="ngForm" (submit)="save($event)" novalidate>
|
<form #addForm="ngForm" (submit)="save($event)" novalidate>
|
||||||
<ion-list>
|
<ion-list>
|
||||||
@ -250,7 +263,7 @@ class ToolbarModal {
|
|||||||
`
|
`
|
||||||
})
|
})
|
||||||
class ModalWithInputs {
|
class ModalWithInputs {
|
||||||
data;
|
data: any;
|
||||||
|
|
||||||
constructor(private viewCtrl: ViewController) {
|
constructor(private viewCtrl: ViewController) {
|
||||||
this.data = {
|
this.data = {
|
||||||
@ -260,7 +273,7 @@ class ModalWithInputs {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public save(ev) {
|
public save(ev: any) {
|
||||||
this.viewCtrl.dismiss(this.data);
|
this.viewCtrl.dismiss(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,11 +287,10 @@ class ModalWithInputs {
|
|||||||
template: '<ion-nav [root]="root"></ion-nav>'
|
template: '<ion-nav [root]="root"></ion-nav>'
|
||||||
})
|
})
|
||||||
class ContactUs {
|
class ContactUs {
|
||||||
root;
|
root = ModalFirstPage;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log('ContactUs constructor');
|
console.log('ContactUs constructor');
|
||||||
this.root = ModalFirstPage;
|
|
||||||
}
|
}
|
||||||
ionViewLoaded() {
|
ionViewLoaded() {
|
||||||
console.log('ContactUs ionViewLoaded');
|
console.log('ContactUs ionViewLoaded');
|
||||||
@ -306,12 +318,15 @@ class ContactUs {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
<ion-navbar *navbar>
|
<ion-header>
|
||||||
<ion-title>First Page Header</ion-title>
|
<ion-navbar>
|
||||||
<ion-buttons start>
|
<ion-title>First Page Header</ion-title>
|
||||||
<button class="e2eCloseMenu" (click)="dismiss()">Close</button>
|
<ion-buttons start>
|
||||||
</ion-buttons>
|
<button class="e2eCloseMenu" (click)="dismiss()">Close</button>
|
||||||
</ion-navbar>
|
</ion-buttons>
|
||||||
|
</ion-navbar>
|
||||||
|
</ion-header>
|
||||||
|
|
||||||
<ion-content padding>
|
<ion-content padding>
|
||||||
<p>
|
<p>
|
||||||
<button (click)="push()">Push (Go to 2nd)</button>
|
<button (click)="push()">Push (Go to 2nd)</button>
|
||||||
@ -414,9 +429,11 @@ class ModalFirstPage {
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `
|
||||||
<ion-navbar *navbar>
|
<ion-header>
|
||||||
<ion-title>Second Page Header</ion-title>
|
<ion-navbar>
|
||||||
</ion-navbar>
|
<ion-title>Second Page Header</ion-title>
|
||||||
|
</ion-navbar>
|
||||||
|
</ion-header>
|
||||||
<ion-content padding>
|
<ion-content padding>
|
||||||
<p>
|
<p>
|
||||||
<button (click)="nav.pop()">Pop (Go back to 1st)</button>
|
<button (click)="nav.pop()">Pop (Go back to 1st)</button>
|
||||||
@ -455,29 +472,29 @@ class E2EApp {
|
|||||||
ionicBootstrap(E2EApp);
|
ionicBootstrap(E2EApp);
|
||||||
|
|
||||||
|
|
||||||
class FadeIn extends Transition {
|
class FadeIn extends PageTransition {
|
||||||
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
|
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
|
||||||
super(opts);
|
super(enteringView, leavingView, opts);
|
||||||
this
|
this
|
||||||
.element(enteringView.pageRef())
|
.element(enteringView.pageRef())
|
||||||
.easing('ease')
|
.easing('ease')
|
||||||
.duration(1000)
|
.duration(1000)
|
||||||
.fromTo('translateY', '0%', '0%')
|
.fromTo('translateY', '0%', '0%')
|
||||||
.fadeIn()
|
.fromTo('opacity', 0, 1, true)
|
||||||
.before.addClass('show-page');
|
.before.addClass('show-page');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Transition.register('my-fade-in', FadeIn);
|
PageTransition.register('my-fade-in', FadeIn);
|
||||||
|
|
||||||
class FadeOut extends Transition {
|
class FadeOut extends PageTransition {
|
||||||
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
|
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
|
||||||
super(opts);
|
super(enteringView, leavingView, opts);
|
||||||
this
|
this
|
||||||
.element(leavingView.pageRef())
|
.element(leavingView.pageRef())
|
||||||
.easing('ease')
|
.easing('ease')
|
||||||
.duration(500)
|
.duration(500)
|
||||||
.fadeOut()
|
.fromTo('opacity', 1, 0)
|
||||||
.before.addClass('show-page');
|
.before.addClass('show-page');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Transition.register('my-fade-out', FadeOut);
|
PageTransition.register('my-fade-out', FadeOut);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<ion-navbar *navbar>
|
<ion-header>
|
||||||
<ion-title>Modals</ion-title>
|
<ion-navbar>
|
||||||
</ion-navbar>
|
<ion-title>Modals</ion-title>
|
||||||
|
</ion-navbar>
|
||||||
|
</ion-header>
|
||||||
|
|
||||||
<ion-content padding>
|
<ion-content padding>
|
||||||
<p>
|
<p>
|
||||||
|
Reference in New Issue
Block a user