Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(camera): Add Camera option for disabling PWA elements picker #2142

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions camera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Request camera and photo album permissions
| **`direction`** | <code><a href="#cameradirection">CameraDirection</a></code> | iOS and Web only: The camera direction. | <code>: CameraDirection.Rear</code> | 1.0.0 |
| **`presentationStyle`** | <code>'fullscreen' \| 'popover'</code> | iOS only: The presentation style of the Camera. | <code>: 'fullscreen'</code> | 1.0.0 |
| **`webUseInput`** | <code>boolean</code> | Web only: Whether to use the PWA Element experience or file input. The default is to use PWA Elements if installed and fall back to file input. To always use file input, set this to `true`. Learn more about PWA Elements: https://capacitorjs.com/docs/web/pwa-elements | | 1.0.0 |
| **`webHidePicker`** | <code>boolean</code> | Hide the PWA elements file picker button from the camera UI. Requires PWA elements 3.3.0 or newer. | <code>false</code> | 6.1.0 |
| **`promptLabelHeader`** | <code>string</code> | Text value to use when displaying the prompt. | <code>: 'Photo'</code> | 1.0.0 |
| **`promptLabelCancel`** | <code>string</code> | Text value to use when displaying the prompt. iOS only: The label of the 'cancel' button. | <code>: 'Cancel'</code> | 1.0.0 |
| **`promptLabelPhoto`** | <code>string</code> | Text value to use when displaying the prompt. The label of the button to select a saved image. | <code>: 'From Photos'</code> | 1.0.0 |
Expand Down
9 changes: 9 additions & 0 deletions camera/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export interface ImageOptions {
*/
webUseInput?: boolean;

/**
* Hide the PWA elements file picker button from the camera UI.
* Requires PWA elements 3.3.0 or newer.
* @default false
*
* @since 6.1.0
*/
webHidePicker?: boolean;

/**
* Text value to use when displaying the prompt.
* @default: 'Photo'
Expand Down
3 changes: 3 additions & 0 deletions camera/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
});
}

async pickImages(_options: GalleryImageOptions): Promise<GalleryPhotos> {

Check warning on line 45 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

'_options' is defined but never used
// eslint-disable-next-line no-async-promise-executor
return new Promise<GalleryPhotos>(async (resolve, reject) => {
this.multipleFileInputExperience(resolve, reject);
Expand All @@ -58,6 +58,9 @@
const cameraModal: any = document.createElement('pwa-camera-modal');
cameraModal.facingMode =
options.direction === CameraDirection.Front ? 'user' : 'environment';
if (options.webHidePicker) {
cameraModal.hidePicker = options.webHidePicker;
}
document.body.appendChild(cameraModal);
try {
await cameraModal.componentOnReady();
Expand Down Expand Up @@ -107,8 +110,8 @@
input.type = 'file';
input.hidden = true;
document.body.appendChild(input);
input.addEventListener('change', (_e: any) => {

Check warning on line 113 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

'_e' is defined but never used
const file = input.files![0];

Check warning on line 114 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

Forbidden non-null assertion
let format = 'jpeg';

if (file.type === 'image/png') {
Expand Down Expand Up @@ -149,7 +152,7 @@
cleanup();
}
});
input.addEventListener('cancel', (_e: any) => {

Check warning on line 155 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

'_e' is defined but never used
reject(new CapacitorException('User cancelled photos app'));
cleanup();
});
Expand Down Expand Up @@ -188,11 +191,11 @@
input.hidden = true;
input.multiple = true;
document.body.appendChild(input);
input.addEventListener('change', (_e: any) => {

Check warning on line 194 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

'_e' is defined but never used
const photos = [];
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < input.files!.length; i++) {

Check warning on line 197 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

Forbidden non-null assertion
const file = input.files![i];

Check warning on line 198 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

Forbidden non-null assertion
let format = 'jpeg';

if (file.type === 'image/png') {
Expand All @@ -208,7 +211,7 @@
resolve({ photos });
cleanup();
});
input.addEventListener('cancel', (_e: any) => {

Check warning on line 214 in camera/src/web.ts

View workflow job for this annotation

GitHub Actions / lint (camera)

'_e' is defined but never used
reject(new CapacitorException('User cancelled photos app'));
cleanup();
});
Expand Down
Loading