Skip to content

Instantly share code, notes, and snippets.

@goodpic
Last active April 4, 2019 12:44
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 goodpic/72365ffb5890046eb796ecc0455236b0 to your computer and use it in GitHub Desktop.
Save goodpic/72365ffb5890046eb796ecc0455236b0 to your computer and use it in GitHub Desktop.
React Native Expo Barcode Scanner
import React from 'react';
import {
ActivityIndicator,
View,
} from 'react-native'
import { ExpoScanner } from '../components/scanner/ExpoScanner';
class ScannerScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
isFocused: false
};
}
componentDidMount() {
this.focusListner = this.props.navigation.addListener(
'didFocus',
() => this.setState({ isFocused: true }),
);
this.blurListner = this.props.navigation.addListener(
'willBlur',
() => this.setState({ isFocused: false }),
);
}
componentWillUnmount() {
this.focusListner.remove();
this.blurListner.remove();
}
render() {
if (!this.state.isFocused) {
return (
<View contentContainerStyle={styles.container} style={styles.spinner}>
<ActivityIndicator size='large' />
</View>
);
}
return (<ExpoScanner navigation={this.props.navigation} />);
}
}
const styles = {
container: {
flexGrow: 1
},
spinner: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
};
export default ScannerScreen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment