Skip to content

Commit bf9bc80

Browse files
chore(example-app): Improve configuration for Choose Gallery screen
1 parent 4ea7047 commit bf9bc80

2 files changed

Lines changed: 125 additions & 33 deletions

File tree

example-app/package-lock.json

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 124 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
IonAccordionGroup,
55
IonItem,
66
IonLabel,
7+
IonInput,
78
IonSelect,
89
IonSelectOption,
910
IonToggle,
@@ -13,22 +14,16 @@ import {
1314
Camera,
1415
MediaResult,
1516
MediaType,
17+
ChooseFromGalleryOptions,
1618
} from "@capacitor/camera";
1719

18-
interface ChooseFromGalleryConfig {
19-
mediaType: number;
20-
allowMultipleSelection: boolean;
21-
includeMetadata: boolean;
22-
allowEdit: boolean;
23-
}
24-
2520
interface ChooseFromGalleryConfigurableProps {
2621
buttonLabel?: string;
2722
onMediaResult: (results: MediaResult[]) => void;
2823
}
2924

3025
interface ChooseFromGalleryConfigurableState {
31-
config: ChooseFromGalleryConfig;
26+
config: ChooseFromGalleryOptions;
3227
}
3328

3429
class ChooseFromGalleryConfigurable extends React.Component<
@@ -37,17 +32,23 @@ class ChooseFromGalleryConfigurable extends React.Component<
3732
> {
3833
constructor(props: ChooseFromGalleryConfigurableProps) {
3934
super(props);
35+
// Initialize with API defaults from ChooseFromGalleryOptions
4036
this.state = {
4137
config: {
4238
mediaType: MediaType.picture,
4339
allowMultipleSelection: false,
40+
limit: 0,
4441
includeMetadata: false,
4542
allowEdit: false,
43+
editInApp: true,
44+
presentationStyle: 'fullscreen',
45+
quality: 100,
46+
correctOrientation: true,
4647
},
4748
};
4849
}
4950

50-
updateConfig = (field: keyof ChooseFromGalleryConfig, value: any): void => {
51+
updateConfig = (field: keyof ChooseFromGalleryOptions, value: any): void => {
5152
this.setState({
5253
config: { ...this.state.config, [field]: value },
5354
});
@@ -56,11 +57,7 @@ class ChooseFromGalleryConfigurable extends React.Component<
5657
executeDefault = async (): Promise<void> => {
5758
try {
5859
const result = await Camera.chooseFromGallery({
59-
mediaType: MediaType.all,
60-
allowMultipleSelection: true,
61-
includeMetadata: false,
62-
allowEdit: false,
63-
limit: 2
60+
mediaType: MediaType.picture
6461
});
6562
console.log("chooseFromGallery result", result);
6663

@@ -78,8 +75,16 @@ class ChooseFromGalleryConfigurable extends React.Component<
7875
const result = await Camera.chooseFromGallery({
7976
mediaType: config.mediaType,
8077
allowMultipleSelection: config.allowMultipleSelection,
78+
limit: config.limit,
8179
includeMetadata: config.includeMetadata,
8280
allowEdit: config.allowEdit,
81+
editInApp: config.editInApp,
82+
presentationStyle: config.presentationStyle,
83+
quality: config.quality,
84+
width: config.width,
85+
height: config.height,
86+
correctOrientation: config.correctOrientation,
87+
webUseInput: config.webUseInput,
8388
});
8489
console.log("chooseFromGallery result", result);
8590

@@ -142,6 +147,81 @@ class ChooseFromGalleryConfigurable extends React.Component<
142147
/>
143148
</IonItem>
144149

150+
<IonItem>
151+
<IonLabel position="stacked">
152+
Limit (0 = unlimited, Android 13+ & iOS)
153+
</IonLabel>
154+
<IonInput
155+
type="number"
156+
min="0"
157+
value={config.limit}
158+
onIonChange={(e) =>
159+
this.updateConfig("limit", parseInt(e.detail.value!) || 0)
160+
}
161+
/>
162+
</IonItem>
163+
164+
<IonItem>
165+
<IonLabel position="stacked">Quality (0-100)</IonLabel>
166+
<IonInput
167+
type="number"
168+
min="0"
169+
max="100"
170+
value={config.quality}
171+
onIonChange={(e) =>
172+
this.updateConfig("quality", parseInt(e.detail.value!) || 100)
173+
}
174+
/>
175+
</IonItem>
176+
177+
<IonItem>
178+
<IonLabel position="stacked">Width (optional)</IonLabel>
179+
<IonInput
180+
type="number"
181+
placeholder="Leave empty for no constraint"
182+
value={config.width ?? ""}
183+
onIonChange={(e) =>
184+
this.updateConfig(
185+
"width",
186+
e.detail.value ? parseInt(e.detail.value) : undefined
187+
)
188+
}
189+
/>
190+
</IonItem>
191+
192+
<IonItem>
193+
<IonLabel position="stacked">Height (optional)</IonLabel>
194+
<IonInput
195+
type="number"
196+
placeholder="Leave empty for no constraint"
197+
value={config.height ?? ""}
198+
onIonChange={(e) =>
199+
this.updateConfig(
200+
"height",
201+
e.detail.value ? parseInt(e.detail.value) : undefined
202+
)
203+
}
204+
/>
205+
</IonItem>
206+
207+
<IonItem>
208+
<IonLabel position="stacked">
209+
Presentation Style (iOS)
210+
</IonLabel>
211+
<IonSelect
212+
value={config.presentationStyle}
213+
onIonChange={(e) =>
214+
this.updateConfig("presentationStyle", e.detail.value)
215+
}
216+
>
217+
<IonSelectOption value="fullscreen">
218+
Fullscreen
219+
</IonSelectOption>
220+
<IonSelectOption value="popover">Popover</IonSelectOption>
221+
</IonSelect>
222+
</IonItem>
223+
224+
{/* Boolean toggles */}
145225
<IonItem>
146226
<IonLabel>Include Metadata</IonLabel>
147227
<IonToggle
@@ -162,6 +242,36 @@ class ChooseFromGalleryConfigurable extends React.Component<
162242
/>
163243
</IonItem>
164244

245+
<IonItem>
246+
<IonLabel>Edit In App</IonLabel>
247+
<IonToggle
248+
checked={config.editInApp}
249+
onIonChange={(e) =>
250+
this.updateConfig("editInApp", e.detail.checked)
251+
}
252+
/>
253+
</IonItem>
254+
255+
<IonItem>
256+
<IonLabel>Correct Orientation</IonLabel>
257+
<IonToggle
258+
checked={config.correctOrientation}
259+
onIonChange={(e) =>
260+
this.updateConfig("correctOrientation", e.detail.checked)
261+
}
262+
/>
263+
</IonItem>
264+
265+
<IonItem>
266+
<IonLabel>Web Use Input</IonLabel>
267+
<IonToggle
268+
checked={config.webUseInput}
269+
onIonChange={(e) =>
270+
this.updateConfig("webUseInput", e.detail.checked)
271+
}
272+
/>
273+
</IonItem>
274+
165275
<IonButton
166276
expand="block"
167277
color="primary"

0 commit comments

Comments
 (0)