0
votes
use strict';
import React, { Component } from 'react';
import {
  AppRegistry,
  Dimensions,
  StyleSheet,
  Text,
  TouchableHighlight,
  View
} from 'react-native';
import Camera from 'react-native-camera';

class BadInstagramCloneApp extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Camera
          ref={(cam) => {
            this.camera = cam;
          }}
          style={styles.preview}
          aspect={Camera.constants.Aspect.fill}>
          <Text style={styles.capture} onPress={this.takePicture.bind(this)}>[CAPTURE]</Text>
        </Camera>
      </View>
    );
  }
  takePicture() {
    this.camera.capture()
      .then((data) => console.log(data))
      .catch(err => console.error(err));
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  preview: {
    flex: 1,
    justifyContent: 'flex-end',
    alignItems: 'center',
    height: Dimensions.get('window').height,
    width: Dimensions.get('window').width
  },
  capture: {
    flex: 0,
    backgroundColor: '#fff',
    borderRadius: 5,
    color: '#000',
    padding: 10,
    margin: 40
  }
});

AppRegistry.registerComponent('AwesomeProject', () => BadInstagramCloneApp);

I used the following steps to resolve the issue : Delete the node_modules folder - rm -rf node_modules && npm install Reset packager cache - rm -fr $TMPDIR/react-* or node_modules/react-native/packager/packager.sh --reset-cache Clear watchman watches - watchman watch-del-all Recreate the project from scratch But i still get an error.

3
have you configured the native side of the react-native-camera component?Radek Czemerys

3 Answers

1
votes

Make sure you have made the settings right, including running $ react-native link react-native-camera and others according the documentation.

0
votes

You can try to use

var Camera = require('react-native-camera')
0
votes

Replace the line:

import Camera from 'react-native-camera';

With this line:

import {RNCamera} from 'react-native-camera';

Change <Camera></Camera> tag to <RNCamera></RNCamera>. Remove the aspect attribute from RNCamera tag.