Last active
April 4, 2019 12:44
-
-
Save goodpic/72365ffb5890046eb796ecc0455236b0 to your computer and use it in GitHub Desktop.
React Native Expo Barcode Scanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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