|
| 1 | +import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'; |
| 2 | +import {generateJsxCodeBlock} from '../helpers/generateCodeBlock'; |
| 3 | + |
| 4 | +const generateJsxCodeBlockForCameraApi = (title: string, fileName: string) => |
| 5 | + generateJsxCodeBlock(title, 'camera-api', fileName); |
| 6 | + |
| 7 | +const data: ReferenceEntityTemplateSchema = { |
| 8 | + name: 'Camera API', |
| 9 | + description: |
| 10 | + "The Camera API provides access to the device's camera, enabling photo capture directly within POS UI extensions. The API requests camera permissions if not already enabled, opens the native camera interface, and returns the image data including dimensions, file size, and base64 string for immediate display or server upload.", |
| 11 | + isVisualComponent: false, |
| 12 | + type: 'APIs', |
| 13 | + definitions: [ |
| 14 | + { |
| 15 | + title: 'CameraApi', |
| 16 | + description: |
| 17 | + 'The `CameraApi` object provides methods for capturing photos using the device camera. Access these methods through `shopify.camera` to take photos and retrieve image data with metadata.', |
| 18 | + type: 'CameraApiContent', |
| 19 | + }, |
| 20 | + ], |
| 21 | + category: 'Target APIs', |
| 22 | + subCategory: 'Standard APIs', |
| 23 | + subSections: [ |
| 24 | + { |
| 25 | + type: 'Generic', |
| 26 | + anchorLink: 'best-practices', |
| 27 | + title: 'Best practices', |
| 28 | + sectionContent: ` |
| 29 | +- **Optimize image quality:** Use appropriate quality and size settings to balance image quality with file size and upload performance. |
| 30 | +- **Provide feedback:** Show loading states while processing images and clear success/error messages after capture. |
| 31 | +- **Handle errors gracefully:** Account for scenarios where users cancel, camera is unavailable, or permissions are denied. |
| 32 | +`, |
| 33 | + }, |
| 34 | + { |
| 35 | + type: 'Generic', |
| 36 | + anchorLink: 'limitations', |
| 37 | + title: 'Limitations', |
| 38 | + sectionContent: ` |
| 39 | +- Camera functionality requires the device to have a camera and appropriate permissions granted by the user. |
| 40 | +- 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\`, \`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. |
| 43 | +`, |
| 44 | + }, |
| 45 | + ], |
| 46 | + related: [], |
| 47 | + examples: { |
| 48 | + description: |
| 49 | + 'Learn how to capture photos using the device camera and handle the resulting image data.', |
| 50 | + examples: [ |
| 51 | + { |
| 52 | + codeblock: generateJsxCodeBlockForCameraApi( |
| 53 | + 'Capture and upload photo to server', |
| 54 | + 'take-photo-upload', |
| 55 | + ), |
| 56 | + description: |
| 57 | + 'This example demonstrates capturing a photo using `shopify.camera.takePhoto()` and uploading it to a backend server for further processing. It shows loading states during capture and upload, handles errors appropriately, and confirms successful upload with toast notifications.', |
| 58 | + }, |
| 59 | + { |
| 60 | + codeblock: generateJsxCodeBlockForCameraApi( |
| 61 | + 'Capture and display a photo', |
| 62 | + 'take-photo-display', |
| 63 | + ), |
| 64 | + description: |
| 65 | + 'This example demonstrates using `shopify.camera.takePhoto()` to capture an image with the device camera and displaying it immediately using the `image` component.', |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | +}; |
| 70 | + |
| 71 | +export default data; |
0 commit comments