Skip to content

Commit 78ee43a

Browse files
fatbattkandy-chhuon
authored andcommitted
add user cancelled to example and copy tweaks.
1 parent d16a79d commit 78ee43a

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

packages/ui-extensions/docs/surfaces/point-of-sale/reference/apis/camera-api.doc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const data: ReferenceEntityTemplateSchema = {
3838
sectionContent: `
3939
- Camera functionality requires the device to have a camera and appropriate permissions granted by the user.
4040
- Only one camera operation can be in progress at a time. Attempting to call \`takePhoto()\` while a capture is already in progress will result in a rejected promise.
41-
- Base64 strings can be memory-intensive for large images. Use appropriate maxWidth and maxHeight settings to optimize performance.
42-
- The \`facingMode\` parameter may not work reliably on some Android devices to set the initial camera, as camera facing mode handling is not standardized across Android manufacturers. The rear-facing camera is used by default if the specified facing mode is not supported. Users can still manually toggle between cameras once the camera interface is open.
41+
- Base64 strings can be memory-intensive for large images. Use appropriate \`maxWidth\`, \`maxHeight\`, and \`quality\` settings to optimize performance.
42+
- The \`facingMode\` parameter may not behave consistently on all Android devices, because camera-facing behavior varies across manufacturers. If a requested mode isn't supported, the rear-facing camera is used by default, and users can still manually switch cameras from the camera interface.
4343
`,
4444
},
4545
],

packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/camera-api/take-photo-display.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ const Extension = () => {
1616
setImageData(photo);
1717
shopify.toast.show('Photo captured successfully!');
1818
} catch (error) {
19-
shopify.toast.show(`Error: ${error.message}`);
19+
// skip showing errors when the user cancels the photo capture.
20+
if (!error.message.includes('User cancelled')) {
21+
shopify.toast.show(`Error: ${error.message}`);
22+
}
2023
} finally {
2124
setIsCapturing(false);
2225
}
@@ -38,7 +41,9 @@ const Extension = () => {
3841
<s-section heading="Image Details">
3942
<s-text>Width: {imageData.width}px</s-text>
4043
<s-text>Height: {imageData.height}px</s-text>
41-
<s-text>File Size: {(imageData.fileSize / 1024).toFixed(2)} KB</s-text>
44+
<s-text>
45+
File Size: {(imageData.fileSize / 1024).toFixed(2)} KB
46+
</s-text>
4247
<s-text>Type: {imageData.type}</s-text>
4348
</s-section>
4449
</>
@@ -48,4 +53,3 @@ const Extension = () => {
4853
</s-page>
4954
);
5055
};
51-

packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/camera-api/take-photo-upload.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ const Extension = () => {
1111
const handleCaptureAndUpload = async () => {
1212
setIsProcessing(true);
1313
try {
14-
const photo = await shopify.camera.takePhoto({quality: 0.8, maxWidth: 1520, maxHeight: 1520});
14+
const photo = await shopify.camera.takePhoto({
15+
quality: 0.8,
16+
maxWidth: 1520,
17+
maxHeight: 1520,
18+
});
1519

1620
// Upload the image to your backend server
1721
// (Replace with your actual backend endpoint)

packages/ui-extensions/src/surfaces/point-of-sale/api/camera-api/camera-api.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Specifies configuration options for capturing photos using the device camera.
3+
*/
14
export interface CameraMediaOptions {
25
/**
36
* The camera that will be active when the camera interface first opens.
@@ -24,6 +27,9 @@ export interface CameraMediaOptions {
2427
quality?: number;
2528
}
2629

30+
/**
31+
* Represents the captured image and associated metadata returned by `shopify.camera.takePhoto()`.
32+
*/
2733
export interface CameraMediaResponse {
2834
/** The image data as base64 string. */
2935
base64: string;
@@ -37,6 +43,9 @@ export interface CameraMediaResponse {
3743
type: string;
3844
}
3945

46+
/**
47+
* Provides camera capabilities for the POS device.
48+
*/
4049
export interface CameraApiContent {
4150
/**
4251
* Launch the device's camera to take a photo.
@@ -51,6 +60,10 @@ export interface CameraApiContent {
5160
takePhoto: (options?: CameraMediaOptions) => Promise<CameraMediaResponse>;
5261
}
5362

63+
/**
64+
* The `CameraApi` object provides access to device camera functionality for capturing photos.
65+
* Access these properties through `shopify.camera`.
66+
*/
5467
export interface CameraApi {
5568
camera: CameraApiContent;
5669
}

0 commit comments

Comments
 (0)