Last active
June 22, 2020 13:53
-
-
Save shahnawaz/c47b874911b455245469541d0bc8e504 to your computer and use it in GitHub Desktop.
react-native-barcode-mask onLayoutMeasured (Provides event so we could get mask position on screen and filter coordinates from camera component)
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 { StyleSheet, Text, View, Button } from 'react-native'; | |
import { RNCamera } from 'react-native-camera'; | |
import BarcodeMask, { LayoutChangeEvent } from 'react-native-barcode-mask'; | |
export default function App() { | |
const [isCameraOpen, setIsCameraOpen] = React.useState(false); | |
const onLayoutMeasuredHandler = (e: LayoutChangeEvent) => { | |
alert(JSON.stringify(e)); | |
} | |
return ( | |
<View style={styles.container}> | |
{ | |
!isCameraOpen && ( | |
<Button title="Open Camera" onPress={() => setIsCameraOpen(!isCameraOpen)} /> | |
) | |
} | |
{ | |
isCameraOpen && ( | |
<> | |
<View style={styles.upperSection}> | |
<RNCamera | |
type={RNCamera.Constants.Type.back} | |
flashMode={RNCamera.Constants.FlashMode.auto} | |
captureAudio={false} | |
playSoundOnCapture={true} | |
style={styles.camera} | |
> | |
<BarcodeMask onLayoutMeasured={onLayoutMeasuredHandler}/> | |
</RNCamera> | |
</View> | |
<View style={styles.lowerSection}> | |
<Button title="Close Camera" onPress={() => setIsCameraOpen(!isCameraOpen)} /> | |
</View> | |
</> | |
) | |
} | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
}, | |
upperSection: { | |
flex: 1 | |
}, | |
lowerSection: { | |
paddingVertical: 30, | |
paddingHorizontal: 20, | |
backgroundColor: 'white', | |
}, | |
camera: { | |
height: '100%', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment