Skip to content

Instantly share code, notes, and snippets.

@vlastachu
Created April 15, 2019 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlastachu/ad8019c850a033042e0892bfcbd9a8e1 to your computer and use it in GitHub Desktop.
Save vlastachu/ad8019c850a033042e0892bfcbd9a8e1 to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Button } from 'react-native';
import { NativeModules, NativeEventEmitter } from 'react-native';
const { Captuvo, CaptuvoEventEmitter } = NativeModules;
const eventEmitter = new NativeEventEmitter(CaptuvoEventEmitter);
const instructions = Platform.select({
ios: 'Press Cmd+R fdgdfgto reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.onBarCodeScan = this.onBarCodeScan.bind(this);
this.state = { barcode: "----" };
}
launch = () => {
Captuvo.startDecoderHardware();
/* const subscription = */eventEmitter.addListener('onBarCodeScan', this.onBarCodeScan);
eventEmitter.addListener('onDecoderReady', this.justLog);
}
scan = () => {
Captuvo.scan();
}
onBarCodeScan = e => {
this.setState({ barcode: e.data });
}
justLog = e => {
console.log(e)
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>barcode: {this.state.barcode}</Text>
<Button
onPress={this.launch}
title="Launch scanner"
color="#FF6347" />
<Button
onPress={this.scan}
title="Scan"
color="#FF6347" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment