Guest User

Untitled

a guest
Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. 'use strict';
  2. import React, { Component } from 'react';
  3. import {
  4. AppRegistry,
  5. Dimensions,
  6. StyleSheet,
  7. Text,
  8. TouchableHighlight,
  9. View
  10. } from 'react-native';
  11. import Camera from 'react-native-camera';
  12.  
  13. class camera_app extends Component {
  14.  
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. showCamera: true,
  19. };
  20. }
  21.  
  22. renderCamera = () => {
  23. if(this.state.showCamera) {
  24. return (
  25. <Camera
  26. ref={(cam) => {
  27. this.camera = cam;
  28. }}
  29. style={styles.container}
  30. aspect={Camera.constants.Aspect.fill}
  31. onBarCodeRead={this._onBarCodeRead}>
  32. </Camera>
  33. );
  34. } else {
  35. return (
  36. <View></View>
  37. );
  38. }
  39. }
  40.  
  41. render() {
  42. return (
  43. this.renderCamera()
  44. );
  45. }
  46.  
  47. _onBarCodeRead = (e) => {
  48. this.setState({showCamera: false});
  49. alert("Barcode Found!",
  50. "Type: " + e.type + "nData: " + e.data);
  51. }
  52. }
  53.  
  54. const styles = StyleSheet.create({
  55. container: {
  56. flex: 1,
  57. justifyContent: "center",
  58. alignItems: "center",
  59. backgroundColor: "transparent",
  60. },
  61. });
  62.  
  63. AppRegistry.registerComponent('rn_camera', () => camera_app);
Add Comment
Please, Sign In to add comment