Skip to content

Instantly share code, notes, and snippets.

@weeravit
Created March 12, 2018 16:31
Show Gist options
  • Select an option

  • Save weeravit/a8a5590bdb5a9ee76c57c1dea4bba8be to your computer and use it in GitHub Desktop.

Select an option

Save weeravit/a8a5590bdb5a9ee76c57c1dea4bba8be to your computer and use it in GitHub Desktop.

Revisions

  1. weeravit created this gist Mar 12, 2018.
    44 changes: 44 additions & 0 deletions App.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    import React from 'react';
    import {StyleSheet, Text, View} from 'react-native';
    import {BarCodeScanner, Permissions} from 'expo';

    export default class App extends React.Component {
    state = {
    hasCameraPermission: null,
    }

    async componentWillMount() {
    const {status} = await Permissions.askAsync(Permissions.CAMERA);
    this.setState({hasCameraPermission: status === 'granted'});
    }

    render() {
    const {hasCameraPermission} = this.state;

    if (hasCameraPermission === null) {
    return <Text>Requesting for camera permission</Text>;
    } else if (hasCameraPermission === false) {
    return <Text>No access to camera</Text>;
    } else {
    return (
    <View style={{flex: 1}}>
    <View style={{flex: 0.2, justifyContent: 'center', alignItems: 'center'}}>
    <Text style={{fontSize: 25}}>HELLO QR SCANNER</Text>
    </View>
    <View style={{flex: 0.6}}>
    <BarCodeScanner
    onBarCodeRead={this._handleBarCodeRead}
    style={StyleSheet.absoluteFill}
    />
    </View>
    <View style={{flex: 0.2}}/>
    </View>
    );
    }
    }

    _handleBarCodeRead = ({type, data}) => {
    // หลังจากที่มันอ่าน data ได้ ให้ handle api ตรงนี้ต่อเลย
    alert(data);
    }
    }