Skip to content

Commit f7137ba

Browse files
committed
ステップ2「アプリにネイティブ機能をつけよう」
ステップ3「カメラとPWA Elementsを使ってみよう」
1 parent dd79f18 commit f7137ba

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@ionic-native/splash-screen": "^5.0.0",
2929
"@ionic-native/status-bar": "^5.0.0",
3030
"@ionic/angular": "^4.7.1",
31+
"@ionic/pwa-elements": "1.3.0",
3132
"@rdlabo/capacitor-admob": "^0.1.4",
3233
"cordova-plugin-badge": "^0.8.8",
3334
"core-js": "^2.5.4",

src/app/tab3/tab3.page.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@
66
</ion-toolbar>
77
</ion-header>
88

9-
<ion-content></ion-content>
9+
<ion-content>
10+
<img [src]="photo" *ngIf="photo">
11+
<ion-fab vertical="bottom" horizontal="center" slot="fixed">
12+
<ion-fab-button (click)="takePicture()">
13+
<ion-icon name="camera"></ion-icon>
14+
</ion-fab-button>
15+
</ion-fab>
16+
</ion-content>

src/app/tab3/tab3.page.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { Component } from '@angular/core';
2+
import { Plugins, CameraResultType, CameraSource } from '@capacitor/core';
23

34
@Component({
45
selector: 'app-tab3',
56
templateUrl: 'tab3.page.html',
67
styleUrls: ['tab3.page.scss']
78
})
89
export class Tab3Page {
9-
10+
photo;
1011
constructor() {}
1112

13+
async takePicture() {
14+
const image = await Plugins.Camera.getPhoto({
15+
quality: 100,
16+
resultType: CameraResultType.DataUrl,
17+
});
18+
this.photo = image.dataUrl;
19+
}
1220
}

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
44
import { AppModule } from './app/app.module';
55
import { environment } from './environments/environment';
66

7+
import { defineCustomElements } from '@ionic/pwa-elements/loader';
8+
79
if (environment.production) {
810
enableProdMode();
911
}
1012

1113
platformBrowserDynamic().bootstrapModule(AppModule)
1214
.catch(err => console.log(err));
15+
defineCustomElements(window);

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@
395395
ionicons "^4.6.3"
396396
tslib "^1.10.0"
397397

398+
399+
version "1.3.0"
400+
resolved "https://registry.yarnpkg.com/@ionic/pwa-elements/-/pwa-elements-1.3.0.tgz#9f27b1d3d408542528279209817d534f55957921"
401+
integrity sha512-nCi4mpOpRmpNbpVN60NSAch61XxEOr4ulw7irWdsIpt1WOXmsfmc0IWYZCRtpeQsiLAHvBFoFoNhELdjirmHgA==
402+
398403
"@ngtools/[email protected]":
399404
version "8.1.3"
400405
resolved "https://registry.yarnpkg.com/@ngtools/webpack/-/webpack-8.1.3.tgz#9df049b14539109b60590a1ca64cbd80b6e49909"

0 commit comments

Comments
 (0)