You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add onThumbnailReady callback for photo capture
Add support for generating thumbnails during photo capture with an
asynchronous callback that fires before the full photo is saved. This
enables instant preview functionality and better UX in camera
applications.
**Changes:**
- Add `thumbnailSize` and `onThumbnailReady` options to
`TakePhotoOptions`
- Add `ThumbnailFile` type for thumbnail metadata
- iOS: Extract embedded thumbnail from AVCapturePhoto using ImageIO for
maximum performance
- Android: Implement memory-efficient downsampling with
hardware-accelerated decoding
- Add event bridge `onThumbnailReady` for both platforms
- Update documentation with usage examples and platform implementation
details
- Add thumbnail display in example app
**Platform implementations:**
- iOS: Uses embedded thumbnail from camera capture if available
- Android: Uses BitmapFactory.Options.inSampleSize for efficient
downsampling without loading full image into memory
Both implementations are asynchronous and non-blocking.
Tested on iPhone 14, iOS 18.6.2
Android implementation compiles successfully (needs device testing)
Note that flash is only available on camera devices where [`hasFlash`](/docs/api/interfaces/CameraDevice#hasflash) is `true`; for example most front cameras don't have a flash.
83
83
84
+
### Thumbnail Generation
85
+
86
+
For a better user experience, you can generate a low-resolution thumbnail that loads while the full photo is being processed and saved. This is especially useful for displaying a preview in your UI without waiting for the full-resolution image.
87
+
88
+
To generate a thumbnail, provide the [`thumbnailSize`](/docs/api/interfaces/TakePhotoOptions#thumbnailsize) and [`onThumbnailReady`](/docs/api/interfaces/TakePhotoOptions#onthumbnailready) options:
89
+
90
+
```tsx
91
+
const photo =awaitcamera.current.takePhoto({
92
+
thumbnailSize: { width: 200, height: 200 },
93
+
onThumbnailReady: (thumbnail) => {
94
+
// Thumbnail is ready! Display it immediately
95
+
setThumbnailUri(`file://${thumbnail.path}`)
96
+
}
97
+
})
98
+
99
+
// Full photo is now ready
100
+
setPhotoUri(`file://${photo.path}`)
101
+
```
102
+
103
+
The `onThumbnailReady` callback is invoked as soon as the thumbnail is generated, which typically happens before the full photo is saved. This allows you to:
104
+
- Display a preview to the user immediately
105
+
- Show a loading state with the thumbnail while uploading the full image
106
+
- Reduce memory usage by rendering thumbnails in lists instead of full photos
107
+
108
+
**Platform implementations:**
109
+
-**iOS**: Uses the embedded thumbnail from the camera capture if available for maximum performance
110
+
-**Android**: Uses memory-efficient downsampling with hardware-accelerated decoding (never loads the full image into memory)
111
+
112
+
Both implementations are optimized for their respective platforms and generate thumbnails asynchronously without blocking photo capture.
113
+
114
+
:::tip
115
+
The thumbnail is stored in a temporary directory just like the main photo. Remember to clean up temporary files when you're done with them.
116
+
:::
117
+
84
118
### Photo Quality Balance
85
119
86
120
The photo capture pipeline can be configured to prioritize speed over quality, quality over speed or balance both quality and speed using the [`photoQualityBalance`](/docs/api/interfaces/CameraProps#photoQualityBalance) prop.
0 commit comments