|
1 | 1 | import { Component } from '@angular/core'; |
2 | 2 | import { NgIf } from '@angular/common'; |
3 | 3 | import { |
4 | | - IonHeader, IonButton, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent |
| 4 | + IonHeader, IonButton, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonCheckbox |
5 | 5 | } from '@ionic/angular/standalone'; |
6 | 6 |
|
7 | 7 | // NATIVE |
8 | 8 | import { CameraPreview } from '@capacitor-community/camera-preview'; |
| 9 | +import type { CameraPreviewOptions } from '@capacitor-community/camera-preview'; |
| 10 | +import { FormsModule } from '@angular/forms'; |
| 11 | + |
| 12 | +const DEFAULT_PREVIEW_OPTIONS: CameraPreviewOptions = { |
| 13 | + parent: 'content', |
| 14 | + disableAudio: true, |
| 15 | + toBack: true, |
| 16 | +}; |
9 | 17 |
|
10 | 18 | @Component({ |
11 | 19 | selector: 'app-home', |
12 | 20 | templateUrl: 'home.page.html', |
13 | 21 | styleUrls: ['home.page.scss'], |
14 | 22 | imports: [ |
15 | | - IonButton, IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, NgIf |
| 23 | + IonButton, IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonCheckbox, NgIf, FormsModule |
16 | 24 | ] |
17 | 25 | }) |
18 | 26 | export class HomePage { |
19 | 27 |
|
20 | 28 | public imageData: string | undefined; |
21 | 29 |
|
| 30 | + protected partialMode = false; |
| 31 | + |
22 | 32 | constructor() { } |
23 | 33 |
|
24 | 34 | public async showFrontCameraPreview(): Promise<void> { |
25 | 35 | this.imageData = undefined; |
26 | | - await CameraPreview.start({ |
27 | | - parent: 'content', |
28 | | - toBack: true, |
29 | | - position: 'front', |
30 | | - disableAudio: true |
31 | | - }); |
| 36 | + |
| 37 | + const options = { ...DEFAULT_PREVIEW_OPTIONS, position: 'front' }; |
| 38 | + if (this.partialMode) { |
| 39 | + options.x = 50; |
| 40 | + options.y = 500; |
| 41 | + options.width = 200; |
| 42 | + options.height = 200; |
| 43 | + options.toBack = false; |
| 44 | + } |
| 45 | + |
| 46 | + await CameraPreview.start(options); |
32 | 47 | } |
33 | 48 |
|
34 | 49 | public async showRearCameraPreview(): Promise<void> { |
35 | 50 | this.imageData = undefined; |
36 | | - await CameraPreview.start({ |
37 | | - parent: 'content', |
38 | | - toBack: true, |
39 | | - position: 'rear', |
40 | | - disableAudio: true |
41 | | - }); |
| 51 | + |
| 52 | + const options = { ...DEFAULT_PREVIEW_OPTIONS, position: 'rear' }; |
| 53 | + if (this.partialMode) { |
| 54 | + options.x = 50; |
| 55 | + options.y = 500; |
| 56 | + options.width = 200; |
| 57 | + options.height = 200; |
| 58 | + options.toBack = false; |
| 59 | + } |
| 60 | + |
| 61 | + await CameraPreview.start(options); |
42 | 62 | } |
43 | 63 |
|
44 | 64 | public async stop(): Promise<void> { |
|
0 commit comments