@@ -40,9 +40,11 @@ export default class CameraScreen extends React.Component {
4040 canDetectFaces : false ,
4141 canDetectText : false ,
4242 canDetectBarcode : false ,
43+ canDetectLabels : false ,
4344 faces : [ ] ,
4445 textBlocks : [ ] ,
4546 barcodes : [ ] ,
47+ labels : [ ] ,
4648 } ;
4749
4850 toggleFacing ( ) {
@@ -234,8 +236,24 @@ export default class CameraScreen extends React.Component {
234236 </ React . Fragment >
235237 ) ;
236238
239+ labelsDetected = ( { labels = [ ] } ) => this . setState ( { labels } ) ;
240+
241+ renderLabels = ( ) => (
242+ < View style = { styles . labelsContainer } pointerEvents = "none" >
243+ { this . state . labels . sort ( ( a , b ) => b . confidence - a . confidence ) . map ( this . renderLabel ) }
244+ </ View >
245+ ) ;
246+
247+ renderLabel = ( { text, confidence } ) => (
248+ < React . Fragment key = { text } >
249+ < View >
250+ < Text style = { [ styles . labelText ] } > { `${ text } ${ confidence . toFixed ( 2 ) } ` } </ Text >
251+ </ View >
252+ </ React . Fragment >
253+ ) ;
254+
237255 renderCamera ( ) {
238- const { canDetectFaces, canDetectText, canDetectBarcode } = this . state ;
256+ const { canDetectFaces, canDetectText, canDetectBarcode, canDetectLabels } = this . state ;
239257 return (
240258 < RNCamera
241259 ref = { ref => {
@@ -271,6 +289,7 @@ export default class CameraScreen extends React.Component {
271289 onFacesDetected = { canDetectFaces ? this . facesDetected : null }
272290 onTextRecognized = { canDetectText ? this . textRecognized : null }
273291 onGoogleVisionBarcodesDetected = { canDetectBarcode ? this . barcodeRecognized : null }
292+ onLabelsDetected = { canDetectLabels ? this . labelsDetected : null }
274293 googleVisionBarcodeType = { RNCamera . Constants . GoogleVisionBarcodeDetection . BarcodeType . ALL }
275294 googleVisionBarcodeMode = {
276295 RNCamera . Constants . GoogleVisionBarcodeDetection . BarcodeMode . ALTERNATE
@@ -306,20 +325,25 @@ export default class CameraScreen extends React.Component {
306325 } }
307326 >
308327 < TouchableOpacity onPress = { this . toggle ( 'canDetectFaces' ) } style = { styles . flipButton } >
309- < Text style = { styles . flipText } >
328+ < Text style = { styles . detectText } >
310329 { ! canDetectFaces ? 'Detect Faces' : 'Detecting Faces' }
311330 </ Text >
312331 </ TouchableOpacity >
313332 < TouchableOpacity onPress = { this . toggle ( 'canDetectText' ) } style = { styles . flipButton } >
314- < Text style = { styles . flipText } >
333+ < Text style = { styles . detectText } >
315334 { ! canDetectText ? 'Detect Text' : 'Detecting Text' }
316335 </ Text >
317336 </ TouchableOpacity >
318337 < TouchableOpacity onPress = { this . toggle ( 'canDetectBarcode' ) } style = { styles . flipButton } >
319- < Text style = { styles . flipText } >
338+ < Text style = { styles . detectText } >
320339 { ! canDetectBarcode ? 'Detect Barcode' : 'Detecting Barcode' }
321340 </ Text >
322341 </ TouchableOpacity >
342+ < TouchableOpacity onPress = { this . toggle ( 'canDetectLabels' ) } style = { styles . flipButton } >
343+ < Text style = { styles . detectText } >
344+ { ! canDetectLabels ? 'Detect Labels' : 'Detecting Labels' }
345+ </ Text >
346+ </ TouchableOpacity >
323347 </ View >
324348 </ View >
325349 < View
@@ -403,6 +427,7 @@ export default class CameraScreen extends React.Component {
403427 { ! ! canDetectFaces && this . renderLandmarks ( ) }
404428 { ! ! canDetectText && this . renderTextBlocks ( ) }
405429 { ! ! canDetectBarcode && this . renderBarcodes ( ) }
430+ { ! ! canDetectLabels && this . renderLabels ( ) }
406431 </ RNCamera >
407432 ) ;
408433 }
@@ -435,6 +460,16 @@ const styles = StyleSheet.create({
435460 color : 'white' ,
436461 fontSize : 15 ,
437462 } ,
463+ detectText : {
464+ color : 'white' ,
465+ fontSize : 12 ,
466+ textAlign : 'center' ,
467+ } ,
468+ labelText : {
469+ color : 'white' ,
470+ fontWeight : 'bold' ,
471+ fontSize : 15 ,
472+ } ,
438473 zoomText : {
439474 position : 'absolute' ,
440475 bottom : 70 ,
@@ -451,6 +486,15 @@ const styles = StyleSheet.create({
451486 left : 0 ,
452487 top : 0 ,
453488 } ,
489+ labelsContainer : {
490+ position : 'absolute' ,
491+ bottom : 0 ,
492+ right : 0 ,
493+ left : 0 ,
494+ top : 0 ,
495+ paddingTop : 150 ,
496+ alignItems : 'center' ,
497+ } ,
454498 face : {
455499 padding : 10 ,
456500 borderWidth : 2 ,
0 commit comments