mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 02:31:34 +08:00
refactor(modal): use framework delegate for mounting the user's component
This commit is contained in:
@ -10,7 +10,8 @@ const routes: Routes = [
|
||||
{ path: 'actionSheet', loadChildren: 'app/action-sheet/action-sheet.module#ActionSheetModule' },
|
||||
{ path: 'toast', loadChildren: 'app/toast/toast.module#ToastModule' },
|
||||
{ path: 'loading', loadChildren: 'app/loading/loading.module#LoadingModule' },
|
||||
{ path: 'nav', loadChildren: 'app/nav/nav.module#NavModule' }
|
||||
{ path: 'nav', loadChildren: 'app/nav/nav.module#NavModule' },
|
||||
{ path: 'modal', loadChildren: 'app/modal/modal.module#ModalModule' }
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
@ -24,4 +24,7 @@
|
||||
<li>
|
||||
<a href='nav'>Nav Page</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href='modal'>Modal Page</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -0,0 +1,35 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'page-one',
|
||||
template: `
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-title>Page One</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content>
|
||||
Page One
|
||||
<ul>
|
||||
<li>ngOnInit - {{ngOnInitDetection}}</li>
|
||||
</ul>
|
||||
</ion-content>
|
||||
`
|
||||
})
|
||||
export class ModalPageToPresent {
|
||||
|
||||
ngOnInitDetection = 'initial';
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
console.log('page one ngOnInit');
|
||||
setInterval(() => {
|
||||
this.ngOnInitDetection = '' + Date.now();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
}
|
35
packages/demos/angular/src/app/modal/modal-page.component.ts
Normal file
35
packages/demos/angular/src/app/modal/modal-page.component.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
import { ModalController } from '@ionic/angular';
|
||||
import { ModalPageToPresent } from './modal-page-to-present';
|
||||
|
||||
@Component({
|
||||
selector: 'app-modal-page',
|
||||
template: `
|
||||
<ion-app>
|
||||
<ion-page class="show-page">
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-title>Test</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content padding>
|
||||
<ion-button (click)="clickMe()">Open Basic Modal</ion-button>
|
||||
</ion-content>
|
||||
</ion-page>
|
||||
</ion-app>
|
||||
`
|
||||
})
|
||||
export class ModalPageComponent {
|
||||
|
||||
constructor(private modalController: ModalController) {
|
||||
}
|
||||
|
||||
clickMe() {
|
||||
const modal = this.modalController.create({
|
||||
component: ModalPageToPresent
|
||||
});
|
||||
return modal.present();
|
||||
}
|
||||
|
||||
}
|
14
packages/demos/angular/src/app/modal/modal-routing.module.ts
Normal file
14
packages/demos/angular/src/app/modal/modal-routing.module.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
import { ModalPageComponent } from './modal-page.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: '', component: ModalPageComponent }
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class ModalRoutingModule { }
|
27
packages/demos/angular/src/app/modal/modal.module.ts
Normal file
27
packages/demos/angular/src/app/modal/modal.module.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { IonicAngularModule } from '@ionic/angular';
|
||||
|
||||
import { ModalPageComponent } from './modal-page.component';
|
||||
import { ModalRoutingModule } from './modal-routing.module';
|
||||
|
||||
import { ModalPageToPresent } from './modal-page-to-present';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
IonicAngularModule.forRoot(),
|
||||
ModalRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
ModalPageComponent,
|
||||
ModalPageToPresent
|
||||
],
|
||||
providers: [
|
||||
],
|
||||
entryComponents: [
|
||||
ModalPageToPresent
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
export class ModalModule { }
|
49
packages/demos/react/src/pages/ModalPage.js
Normal file
49
packages/demos/react/src/pages/ModalPage.js
Normal file
@ -0,0 +1,49 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import PageThree from './PageThree';
|
||||
|
||||
export default class ModalPage extends Component {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.style = {
|
||||
height: '100%'
|
||||
};
|
||||
this.state = {
|
||||
content: 'modal page - ' + 50
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
console.log('componentDidMount');
|
||||
setInterval(() => {
|
||||
this.setState({ content: 'Modal page - ' + Math.random() * 1000});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
dismiss() {
|
||||
return this.props.modal.dismiss();
|
||||
}
|
||||
|
||||
render() {
|
||||
return [
|
||||
<ion-header ref={(element) => this.element = element}>
|
||||
<ion-toolbar>
|
||||
<ion-title>Modal Page</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>,
|
||||
<ion-content>
|
||||
Modal Page
|
||||
<div>
|
||||
<ion-button onClick={() => this.dismiss()}>Dismiss</ion-button>
|
||||
</div>
|
||||
<div>
|
||||
Some random content: {this.state.content}
|
||||
</div>
|
||||
<div>
|
||||
Props : {this.props.paramOne}
|
||||
</div>
|
||||
</ion-content>
|
||||
];
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
import { createModal } from '@ionic/react';
|
||||
|
||||
import PageTwo from './PageTwo';
|
||||
import ModalPage from './ModalPage';
|
||||
|
||||
export default class PageOne extends Component {
|
||||
|
||||
@ -35,6 +38,14 @@ export default class PageOne extends Component {
|
||||
nav.push(PageTwo, { paramOne: 'Tobey Flenderson'});
|
||||
}
|
||||
|
||||
openModal() {
|
||||
return createModal({
|
||||
component: ModalPage
|
||||
}).then((modal) => {
|
||||
return modal.present();
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
setInterval(() => {
|
||||
this.setState({ content: Math.random() * 1000});
|
||||
@ -54,6 +65,9 @@ export default class PageOne extends Component {
|
||||
<div>
|
||||
<ion-button onClick={() => this.goToPageTwo()}>Go to Page Two</ion-button>
|
||||
</div>
|
||||
<div>
|
||||
<ion-button onClick={() => this.openModal()}>OpenModal</ion-button>
|
||||
</div>
|
||||
<div>
|
||||
Some random content: {this.state.content}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user