React Native Camera

React Native Camera

  • Docs
  • Guides
  • API
  • Help
  • For Enterprise
  • GitHub

›API

Getting Started

  • Installation
  • Contributing

Guides

  • Expo Usage
  • Gradle Upgrade Guide
  • Migrating from RCTCamera to RNCamera
  • Migrating from version 1.x to 2.x
  • React Navigation
  • Recipes
  • RNCamera
  • Testing

API

  • Work in progress

Help

  • Q & A

Enterprise

  • React-Native-Camera for Enterprise
Edit

Work in progress

Props Index

[wip]

  • zoom
  • maxZoom
  • type
  • cameraId
  • flashMode
  • exposure
  • whiteBalance
  • autoFocus
  • ratio
  • focusDepth
  • onMountError
  • onCameraReady

Methods Index

  • takePictureAsync
  • recordAsync
  • refreshAuthorizationStatus
  • stopRecording
  • pausePreview
  • resumePreview
  • getAvailablePictureSizes
  • getSupportedRatiosAsync
  • isRecording
  • getSupportedPreviewFpsRange

Props


zoom

This property specifies the zoom value of the camera. Ranges from 0 to 1. Default to 0.

TypeDefault Value
number0

maxZoom

The maximum zoom value of the camera. Defaults to 0.

TypeDefault Value
number0

type

This property defines which camera on the phone the component is using. Possible values:

  • front
  • back
TypeDefault Value
number'back'

cameraId

For selecting from multiple cameras on Android devices. See 2492 for more info. Can be retrieved with getCameraIds()

TypeDefault ValuePlatform
StringnullAndroid

flashMode

Determines the state of the camera flash. Has the following possible states.

on: 'auto',
auto: 'torch',
torch: 'off'
TypeDefault Value
object{ off: 1 }

Methods

takePictureAsync()

Returns a promise with TakePictureResponse.

Method type

takePictureAsync(options?: TakePictureOptions): Promise<TakePictureResponse>;
interface TakePictureOptions {
  quality?: number;
  orientation?: keyof Orientation | OrientationNumber;
  base64?: boolean;
  exif?: boolean;
  width?: number;
  mirrorImage?: boolean;
  doNotSave?: boolean;
  pauseAfterCapture?: boolean;
  writeExif?: boolean | { [name: string]: any };

  /** Android only */
  fixOrientation?: boolean;

  /** iOS only */
  forceUpOrientation?: boolean;
}

interface TakePictureResponse {
  width: number;
  height: number;
  uri: string;
  base64?: string;
  exif?: { [name: string]: any };
  pictureOrientation: number;
  deviceOrientation: number;
}

Usage example

takePicture = async () => {
  if (this.camera) {
    const data = await this.camera.takePictureAsync();
    console.warn('takePictureResponse ', data);
  }
};

recordAsync()

Returns a promise with RecordResponse.

Method type

recordAsync(options?: RecordOptions): Promise<RecordResponse>;
interface RecordOptions {
  quality?: keyof VideoQuality;
  orientation?: keyof Orientation | OrientationNumber;
  maxDuration?: number;
  maxFileSize?: number;
  mute?: boolean;
  mirrorVideo?: boolean;
  path?: string;
  videoBitrate?: number;
  fps?: number;

  /** iOS only */
  codec?: keyof VideoCodec | VideoCodec[keyof VideoCodec];
}

interface RecordResponse {
  /** Path to the video saved on your app's cache directory. */
  uri: string;
  videoOrientation: number;
  deviceOrientation: number;
  isRecordingInterrupted: boolean;
  /** iOS only */
  codec: VideoCodec[keyof VideoCodec];
}

Usage example

takeVideo = async () => {
  if (this.camera) {
    try {
      const promise = this.camera.recordAsync(this.state.recordOptions);

      if (promise) {
        this.setState({ isRecording: true });
        const data = await promise;
        this.setState({ isRecording: false });
        console.warn('takeVideo', data);
      }
    } catch (e) {
      console.error(e);
    }
  }
};

refreshAuthorizationStatus()

Allows to make RNCamera check Permissions again and set status accordingly. Making it possible to refresh status of RNCamera after user initially rejected the permissions.

Method type

refreshAuthorizationStatus(): Promise<void>;

Usage example

/* -> {

} */

stopRecording()

Should be called after recordAsync() to make the promise be fulfilled and get the video uri.

Method type

stopRecording(): void;

Usage example

stopRecording(): void;
/* -> {

} */

pausePreview()

Pauses the preview. The preview can be resumed again by using resumePreview().

Method type

pausePreview(): void;

Usage example

/* -> {

} */

resumePreview()

Resumes the preview after pausePreview() has been called.

Method type

resumePreview(): void;

Usage example

/* -> {

} */

getAvailablePictureSizes()

Returns a promise with getAvailablePictureSizes.

Method type

getAvailablePictureSizes(): Promise<string[]>;

Usage example

/* -> {

} */

getSupportedRatiosAsync() - Android only

Android only. Returns a promise. The promise will be fulfilled with an object with an array containing strings with all camera aspect ratios supported by the device.

Method type

getSupportedRatiosAsync(): Promise<string[]>;

Usage example

/* -> {

} */

isRecording() - iOS only

iOS only. Returns a promise. The promise will be fulfilled with a boolean indicating if currently recording is started or stopped.

Method type

isRecording(): Promise<boolean>;

Usage example

const isRecording = await isRecording();
/* -> {
  isRecording = true
} */
  • getSupportedPreviewFpsRange

getSupportedPreviewFpsRange - Android only

Android only. Returns a promise. The promise will be fulfilled with a json object including the fps ranges available for those devices (android docs)

Method type

getSupportedPreviewFpsRange(): Promise<[{MINIMUM_FPS: string, MAXIMUM_FPS: string}]>;

Usage example

const previewRange = await this.camera.getSupportedPreviewFpsRange();
/* -> [
  {
    MINIMUM_FPS: "15000",
    MAXIMUM_FPS: "15000"
  },
  { 
    MINIMUM_FPS: "20000",
    MAXIMUM_FPS: "20000"
  }
] */

Last updated on 6/10/2020 by luism3861
← TestingQ & A →
  • Props Index
  • Methods Index
  • Props
    • zoom
    • maxZoom
    • type
    • cameraId
    • flashMode
  • Methods
  • takePictureAsync()
    • Method type
    • Usage example
  • recordAsync()
    • Method type
    • Usage example
  • refreshAuthorizationStatus()
    • Method type
    • Usage example
  • stopRecording()
    • Method type
    • Usage example
  • pausePreview()
    • Method type
    • Usage example
  • resumePreview()
    • Method type
    • Usage example
  • getAvailablePictureSizes()
    • Method type
    • Usage example
  • getSupportedRatiosAsync() - Android only
    • Method type
    • Usage example
  • isRecording() - iOS only
    • Method type
    • Usage example
  • getSupportedPreviewFpsRange - Android only
    • Method type
    • Usage example
React Native Camera
Docs
Getting StartedGuidesAPI Reference
Community
User ShowcaseStack OverflowProject Chat
More
GitHubStars
Facebook Open Source
Copyright © 2020