Giter VIP home page Giter VIP logo

react-native-camera's Introduction

react-native-camera

A camera viewport for React Native. This module is currently in the very early stages of development.

Known Issues

Below is a list of known issues. Pull requests are welcome for any of these issues!

Getting started

  1. npm install react-native-camera@latest --save
  2. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  3. Go to node_modulesreact-native-camera and add RCTCamera.xcodeproj
  4. In XCode, in the project navigator, select your project. Add libRCTCamera.a to your project's Build PhasesLink Binary With Libraries
  5. Click RCTCamera.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive.
  6. Run your project (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,
  TouchableHighlight
} = React;
var Camera = require('react-native-camera');

var cameraApp = React.createClass({
  render: function() {
    return (
      <View>
        <TouchableHighlight onPress={this._switchCamera}>
          <View>
            <Camera
              ref="cam"
              aspect="Stretch"
              type="Front"
              orientation="PortraitUpsideDown"
              style={{height: 200, width: 200}}
            />
          </View>
        </TouchableHighlight>
      </View>
    );
  },
  _switchCamera: function() {
    this.refs.cam.switch();
  }
});

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

Properties

aspect

Values: Fit, Fill (default), Stretch

The aspect property 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.

type

Values: Front, Back (default)

Use the type property to specify which camera to use.

orientation

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

The orientation property 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.

Component methods

You can access component methods by adding a ref (ie. ref="camera") prop to your <Camera> element, then you can use this.refs.camera.switch(), etc. inside your component.

switch()

The switch() method toggles between the Front and Back cameras.

takePicture(callback)

Basic implementation of image capture. This method is subject to change, but currently works by accepting a callback like function(err, base64EncodedJpeg) { ... }.

Subviews

This component supports subviews, so if you wish to use the camera view as a background or if you want to layout buttons/images/etc. inside the camera then you can do that.

Todo

These are some features I think would be important/beneficial to have included with this module. Pull requests welcome!

  • Video support
  • Flash mode setting
  • Automatic orientation adjustment
  • Tap to focus
  • Optional facial recognition (w/ ability to style box around face)

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.

react-native-camera's People

Contributors

lwansbrough avatar vjeux avatar rojotek avatar scottdixon avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.