A Camera component for React Native. Also supports barcode scanning!
Go to file
Loch Wansbrough 6db17c8db4 Improved getting started 2015-04-01 09:49:08 -07:00
RCTCamera.xcodeproj Pushing files 2015-03-31 18:02:57 -07:00
.gitignore Added Xcode project user data to gitignore 2015-03-31 18:03:22 -07:00
Camera.ios.js Support for aspect (fit, fill, stretch) and orientation 2015-03-31 19:27:18 -07:00
LICENSE Initial commit 2015-03-31 17:54:41 -07:00
RCTCamera.h Pushing files 2015-03-31 18:02:57 -07:00
RCTCamera.m Support for aspect (fit, fill, stretch) and orientation 2015-03-31 19:27:18 -07:00
RCTCameraManager.h Pushing files 2015-03-31 18:02:57 -07:00
RCTCameraManager.m Support for aspect (fit, fill, stretch) and orientation 2015-03-31 19:27:18 -07:00
README.md Improved getting started 2015-04-01 09:49:08 -07:00
ViewfinderView.h Pushing files 2015-03-31 18:02:57 -07:00
ViewfinderView.m Pushing files 2015-03-31 18:02:57 -07:00
package.json Pushing files 2015-03-31 18:02:57 -07:00

README.md

react-native-camera

A camera viewport for React Native. This module is currently in the very early stages of development and does not support image capture at this time, though it is coming.

Getting started

  1. npm install react-native-camera --save
  2. In XCode, right click Libraries ➜ Add Files to ______
  3. Go to node_modulesreact-native-camera and add RCTCamera.xcodeproj
  4. Add libRCTCamera.a (it's in workspace) to Build PhasesLink Binary With Libraries
  5. Click RCTCamera.xcodeproj in the project navigator and go the Build Phases tab. Look for Header Search Paths and make sure it contains $(SRCROOT)../react-native/React.
  6. Run (Cmd+R)

Usage

All you need is to require the react-native-camera module and then use the <Camera/> tag.

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
} = React;
var Camera = require('react-native-camera');

var cameraApp = React.createClass({
  render: function() {
    return (
      <View>
        <Camera
          aspect="Stretch"
          orientation="PortraitUpsideDown"
          style={{height: 200, width: 200}}
        />
      </View>
    );
  }
});

AppRegistry.registerComponent('cameraApp', () => cameraApp);

Props

aspect

Values: Fit, Fill (default), Stretch

The aspect prop allows you to define how your viewfinder renders the camera's view. For instance, if you have a square viewfinder and you want to fill the it entirely, you have two options: Fill, where the aspect ratio of the camera's view is preserved by cropping the view or Stretch, where the aspect ratio is skewed in order to fit the entire image inside the viewfinder. The other option is Fit, which ensures the camera's entire view fits inside your viewfinder without altering the aspect ratio.

orientation

Values: LandscapeLeft, LandscapeRight, Portrait (default), PortraitUpsideDown

The orientation prop allows you to specify the current orientation of the phone to ensure the viewfinder is "the right way up."

TODO: Add support for an Auto value to automatically adjust for orientation changes.


Thanks to Brent Vatne (@brentvatne) for the react-native-video module which provided me with a great example of how to set up this module.