expo-camera/next is ready for a close up

Product5 minutes read

Alan Hughes

Alan Hughes

Engineering

Expo-camera/next is a modern, stable, easy to use camera app capable of handling common cases for using a camera in most apps.

Introducing expo-camera/next

In Expo SDK 50, we released expo-camera/next - this takes one of our oldest and most popular libraries and brings it up to date with native platform best practices.

Accessing the device camera is a fundamental capability of mobile apps and we believe that this should be both simple and reliable. In the time since its initial release in 2018, expo-camera has gained a number of features that, while useful, could also be considered “niche” use cases that greatly increased the complexity of the library for a small return.

Some examples of this are pausing and resuming the camera preview and the texture integration with expo-gl. Recently, with the introduction of libraries like react-native-vision-camera that target these more advanced use cases, it was time for us to revisit expo-camera and redefine it’s place in the React Native ecosystem: we want it to be modern, stable, easy to use, and to handle the common cases for using a camera in most apps.

Our goals for expo-camera/next

  • Rewrite the Android implementation using CameraX (the recommended API by Google).
  • Improve barcode scanning reliability, and add support for DataScannerViewController on devices running iOS 16+
  • Make most configuration options available through props, to prevent issues like https://github.com/expo/expo/pull/23834
  • Remove niche features that would require using brittle lower-level camera APIs, rather than the modern, recommended APIs. For example, whiteBalance and focusDepth are options that are handled automatically by CameraX by querying the current device hardware and selecting the optimal configuration.
  • Remove face detection — it’s a fun novelty, but not what people typically want when they reach for a camera library, and if they do want it, they may want more control than the old implementation provided.

CameraX on Android

CameraX is Google's answer to the powerful, but difficult to use Camera2 API.

CameraX greatly reduces the complexity of the Android implementation, while increasing the reliability on the wide range of possible Android devices your app can run on. It provides better management of the camera lifecycle, guaranteed device compatibility back to API 21, and ensures that pictures and videos are captured with the best available configuration, based on the current devices hardware. As a Jetpack library, it receives consistent attention from Google and is improving all the time. This puts expo-camera in a position to take advantage of new features when they arrive.

Reliable barcode scanning

Barcode scanning is a popular feature of the camera, and something that users expect to work great out of the box. expo-camera/next improves the reliability of barcode scanning by building it directly into the library.

Additionally, devices running iOS 16, now have access to DataScannerViewController, a new API provided by VisionKit which provides nice features like guidance and highlighting.

Configuration through props

In the legacy expo-camera API, configuration options were passed to the takePictureAsync() and recordAsync() functions. The problem with this is when you make configuration changes, the camera preview flickers as it reloads with the new configuration. When this is done just before a picture is taken, you might capture this flicker, leading to dark frames or blurry images.

In expo-camera/next configuration changes will never happen at the time the picture or video is about to be captured. Configuration is done through props, this means that the camera can be configured correctly before attempting to take a picture leading to consistent image and video quality.

Example expo-camera/next usage

Code
<CameraView
ref={cameraRef}
style={styles.camera}
/>

Changes to the API have been kept to a minimum. We have renamed the component to CameraView, added new props and removed others. The callbacks have kept the same names as before so migrating should just involve changing some names on the component itself. Learn more in the expo-camera/next documentation.

Try out expo-camera/next!

We would love to get your feedback! expo-camera/next will remain in beta throughout the SDK 50 lifecycle, after which we will deprecate and archive the legacy API. Please reach out to us in

our Discord

or on social with any issues or suggestions you may have so we can deliver a smooth stable release with SDK 51.

SDK 50
dev tools

Accelerate building apps with Expo and AI

Learn more