Skip to content

Commit 0da981a

Browse files
committed
feat(example-app): add partial mode to example-app
1 parent 4061367 commit 0da981a

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

example-app/src/app/home/home.page.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
Camera Preview</ion-button>
2626
<ion-button expand="block" color="secondary" class="action-button" (click)="showRearCameraPreview()">Show Rear
2727
Camera Preview</ion-button>
28+
<div style="text-align: center; margin: 20px 0;">
29+
<ion-checkbox label-placement="end" [(ngModel)]="partialMode">Partial</ion-checkbox>
30+
</div>
2831
<ion-button expand="block" color="tertiary" class="action-button" (click)="stop()">Stop</ion-button>
2932
<ion-button expand="block" color="success" class="action-button" (click)="flip()">Flip</ion-button>
3033
<ion-button expand="block" color="warning" class="action-button" (click)="captureSample()">Capture

example-app/src/app/home/home.page.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,64 @@
11
import { Component } from '@angular/core';
22
import { NgIf } from '@angular/common';
33
import {
4-
IonHeader, IonButton, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent
4+
IonHeader, IonButton, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonCheckbox
55
} from '@ionic/angular/standalone';
66

77
// NATIVE
88
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+
};
917

1018
@Component({
1119
selector: 'app-home',
1220
templateUrl: 'home.page.html',
1321
styleUrls: ['home.page.scss'],
1422
imports: [
15-
IonButton, IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, NgIf
23+
IonButton, IonHeader, IonToolbar, IonTitle, IonContent, IonCard, IonCardContent, IonCheckbox, NgIf, FormsModule
1624
]
1725
})
1826
export class HomePage {
1927

2028
public imageData: string | undefined;
2129

30+
protected partialMode = false;
31+
2232
constructor() { }
2333

2434
public async showFrontCameraPreview(): Promise<void> {
2535
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);
3247
}
3348

3449
public async showRearCameraPreview(): Promise<void> {
3550
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);
4262
}
4363

4464
public async stop(): Promise<void> {

0 commit comments

Comments
 (0)