A high performance, easy to use, rock solid camera library for React Native apps.
Go to file
Ran Greenberg 2a4f155601 in progress 2016-06-22 18:28:24 +03:00
example first version on objective-c implementation 2016-06-15 14:40:04 +03:00
ios/lib in progress 2016-06-22 18:28:24 +03:00
src in progress 2016-06-22 18:28:24 +03:00
.flowconfig Camera kit initial commit 2016-04-14 10:44:00 +03:00
.gitignore Camera kit initial commit 2016-04-14 10:44:00 +03:00
.watchmanconfig Camera kit initial commit 2016-04-14 10:44:00 +03:00
LICENSE Create LICENSE 2016-04-14 14:39:54 +03:00
README.md Update README 2016-04-18 12:40:16 +03:00
index.js in progress 2016-06-22 18:28:24 +03:00
package.json initial new camera kit objc 2016-05-31 14:46:49 +03:00

README.md

react-native-camera-kit

Currently work-in-progress

Advanced native camera control with pre-defined aspect ratio, crop, etc

Install

  1. In your project folder run npm install react-native-camera-kit --save
  2. Install Cocoa Pods by running sudo gem install cocoapods
  3. Go to 'your-project-folder/ios' and run pod install
  4. Close your XCode and open the your-project.xcworkspace that was created

Usage

All you need is to require the react-native-camera-kit module, import NativeModules from react-native and then use the ReactNativeCameraKit native module.

Example

import React from 'react-native';

const {
    AppRegistry,
    Component,
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity,
    PixelRatio,
    NativeModules: {
        ReactNativeCameraKit
        }
    } = React;

class Example extends Component {
  state = {
    photoSource: null,
    error: null
  };

  selectPhotoTapped() {
    const options = {
      takePhotoActionTitle: 'Take a photo',
      pickPhotoActionTitle: 'Gallery',
      cancelActionTitle: 'Cancel',
      sendSelectedPhotosTitle: 'Send %lu photo(s)',
      aspectRatioInfoMessage: 'Your images look best with 16:9 ratio',
      aspectRatios: ["16:9", "1:1", "4:3"],
      collectionName: 'your-folder'
    };

      ReactNativeCameraKit.presentPhotoPicker(options, (response) => {
      if (response.images) {
        const source = {uri: 'data:image/jpeg;base64,' + response.images[response.images.length -1], isStatic: true};
        this.setState({
          photoSource: source
        });
      }
      if (response.error) {
        this.setState({
          error: response.error
        });
      }
    });
  }
  
  render() {
    return (
        <View style={styles.container}>
            <TouchableOpacity onPress={this.selectPhotoTapped.bind(this)}>
                <View style={[styles.photo, styles.photoContainer, {marginBottom: 20}]}>
                { this.state.photoSource === null 
                  ? <Text>Select a Photo</Text> 
                  : <Image style={styles.photo} source={this.state.photoSource} />
                }
                </View>
                { this.state.error ? <Text>this.state.error</Text> : null }
            </TouchableOpacity>
        </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  photoContainer: {
    borderColor: '#9B9B9B',
    justifyContent: 'center',
    alignItems: 'center',
    borderWidth: 1 / PixelRatio.get()
  },
  photo: {
    width: 100,
    height: 100
  }
});

AppRegistry.registerComponent('ReactNativeCameraKit', () => Example);