Skip to content

Commit db7e21b

Browse files
refactor(example-app): improve configurability for pages
TakePicture, EditURIPhoto, and RecordVideo - following previous commit
1 parent bf9bc80 commit db7e21b

3 files changed

Lines changed: 14 additions & 60 deletions

File tree

example-app/src/components/camera/EditURIPhotoConfigurable.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@ import {
99
IonToggle,
1010
} from "@ionic/react";
1111
import React from "react";
12-
import { Camera, MediaResult } from "@capacitor/camera";
12+
import { Camera, MediaResult, EditURIPhotoOptions } from "@capacitor/camera";
1313
import { Filesystem, Directory } from "@capacitor/filesystem";
1414
import { Capacitor } from "@capacitor/core";
1515
import { TestImage } from "./TestImageData";
1616
import { MediaHistoryService } from "../../services/MediaHistoryService";
1717

18-
interface EditURIPhotoConfig {
19-
saveToGallery: boolean;
20-
includeMetadata: boolean;
21-
}
22-
2318
interface EditURIPhotoConfigurableProps {
2419
selectedImage: TestImage | null;
2520
}
@@ -28,7 +23,7 @@ interface EditURIPhotoConfigurableState {
2823
savedFileUri: string | null;
2924
savedFileWebPath: string | null;
3025
editedPhoto: MediaResult | null;
31-
config: EditURIPhotoConfig;
26+
config: Omit<EditURIPhotoOptions, 'uri'>; // Config excludes 'uri' since it comes from saved file
3227
isLoading: boolean;
3328
}
3429

@@ -38,6 +33,7 @@ class EditURIPhotoConfigurable extends React.Component<
3833
> {
3934
constructor(props: EditURIPhotoConfigurableProps) {
4035
super(props);
36+
// Initialize with API defaults from EditURIPhotoOptions
4137
this.state = {
4238
savedFileUri: null,
4339
savedFileWebPath: null,
@@ -60,7 +56,7 @@ class EditURIPhotoConfigurable extends React.Component<
6056
}
6157
}
6258

63-
updateConfig = (field: keyof EditURIPhotoConfig, value: boolean): void => {
59+
updateConfig = (field: keyof Omit<EditURIPhotoOptions, 'uri'>, value: boolean): void => {
6460
this.setState({
6561
config: { ...this.state.config, [field]: value },
6662
});

example-app/src/components/camera/RecordVideoConfigurable.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@ import {
77
IonToggle,
88
} from "@ionic/react";
99
import React from "react";
10-
import { Camera, MediaResult } from "@capacitor/camera";
11-
12-
interface RecordVideoConfig {
13-
saveToGallery: boolean;
14-
includeMetadata: boolean;
15-
isPersistent: boolean;
16-
}
10+
import { Camera, MediaResult, RecordVideoOptions } from "@capacitor/camera";
1711

1812
interface RecordVideoConfigurableProps {
1913
buttonLabel?: string;
2014
onVideoResult: (result: MediaResult) => void;
2115
}
2216

2317
interface RecordVideoConfigurableState {
24-
config: RecordVideoConfig;
18+
config: RecordVideoOptions;
2519
}
2620

2721
class RecordVideoConfigurable extends React.Component<
@@ -30,16 +24,17 @@ class RecordVideoConfigurable extends React.Component<
3024
> {
3125
constructor(props: RecordVideoConfigurableProps) {
3226
super(props);
27+
// Initialize with API defaults from RecordVideoOptions
3328
this.state = {
3429
config: {
3530
saveToGallery: false,
36-
includeMetadata: true,
31+
includeMetadata: false,
3732
isPersistent: true,
3833
},
3934
};
4035
}
4136

42-
updateConfig = (field: keyof RecordVideoConfig, value: any): void => {
37+
updateConfig = (field: keyof RecordVideoOptions, value: any): void => {
4338
this.setState({
4439
config: { ...this.state.config, [field]: value },
4540
});
@@ -58,12 +53,7 @@ class RecordVideoConfigurable extends React.Component<
5853

5954
executeWithConfig = async (): Promise<void> => {
6055
try {
61-
const config = this.state.config;
62-
const result = await Camera.recordVideo({
63-
saveToGallery: config.saveToGallery,
64-
includeMetadata: config.includeMetadata,
65-
isPersistent: config.isPersistent,
66-
});
56+
const result = await Camera.recordVideo(this.state.config);
6757
this.props.onVideoResult(result);
6858
} catch (e) {
6959
const error = e as any;

example-app/src/components/camera/TakePictureConfigurable.tsx

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,13 @@ import {
1818
CameraDirection,
1919
} from "@capacitor/camera";
2020

21-
interface TakePictureConfig {
22-
quality: number;
23-
allowEdit: boolean;
24-
encodingType: EncodingType;
25-
saveToGallery: boolean;
26-
width: number | undefined;
27-
height: number | undefined;
28-
correctOrientation: boolean;
29-
cameraDirection: CameraDirection;
30-
presentationStyle: 'fullscreen' | 'popover';
31-
editInApp: boolean;
32-
includeMetadata: boolean;
33-
webUseInput: boolean;
34-
}
35-
3621
interface TakePictureConfigurableProps {
3722
buttonLabel?: string;
3823
onPhotoResult: (result: MediaResult) => void;
3924
}
4025

4126
interface TakePictureConfigurableState {
42-
config: TakePictureConfig;
27+
config: TakePhotoOptions;
4328
}
4429

4530
class TakePictureConfigurable extends React.Component<
@@ -48,25 +33,23 @@ class TakePictureConfigurable extends React.Component<
4833
> {
4934
constructor(props: TakePictureConfigurableProps) {
5035
super(props);
36+
// Initialize with API defaults from TakePhotoOptions
5137
this.state = {
5238
config: {
5339
quality: 100,
5440
allowEdit: false,
5541
encodingType: EncodingType.JPEG,
5642
saveToGallery: false,
57-
width: undefined,
58-
height: undefined,
5943
correctOrientation: true,
6044
cameraDirection: CameraDirection.Rear,
6145
presentationStyle: 'fullscreen',
6246
editInApp: true,
6347
includeMetadata: false,
64-
webUseInput: false,
6548
},
6649
};
6750
}
6851

69-
updateConfig = (field: keyof TakePictureConfig, value: any): void => {
52+
updateConfig = (field: keyof TakePhotoOptions, value: any): void => {
7053
this.setState({
7154
config: { ...this.state.config, [field]: value },
7255
});
@@ -86,22 +69,7 @@ class TakePictureConfigurable extends React.Component<
8669

8770
executeWithConfig = async (): Promise<void> => {
8871
try {
89-
const config = this.state.config;
90-
const options: TakePhotoOptions = {
91-
quality: config.quality,
92-
allowEdit: config.allowEdit,
93-
encodingType: config.encodingType,
94-
saveToGallery: config.saveToGallery,
95-
width: config.width,
96-
height: config.height,
97-
correctOrientation: config.correctOrientation,
98-
cameraDirection: config.cameraDirection,
99-
presentationStyle: config.presentationStyle,
100-
editInApp: config.editInApp,
101-
includeMetadata: config.includeMetadata,
102-
webUseInput: config.webUseInput,
103-
};
104-
const result = await Camera.takePhoto(options);
72+
const result = await Camera.takePhoto(this.state.config);
10573
this.props.onPhotoResult(result);
10674
} catch (e) {
10775
const error = e as any;

0 commit comments

Comments
 (0)