Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i remove extra white space in expo BarCodeScanner

iOS is working fine BarCodeScanner take full screen but when i use android there is extra white space.

<BarCodeScanner
  onBarCodeScanned={scanned ? undefined : this._handleBarCodeScanned}
  style={[StyleSheet.absoluteFill, { flex: 1 }]}
/>

I have also checked by giving a different style like but no luck

style={{
  height: Dimensions.get('window').height,
  width: Dimensions.get('window').width,
}}

White space example

like image 430
Zeeshan Ansari Avatar asked Jul 17 '19 08:07

Zeeshan Ansari


3 Answers

This seems to be an issue in recent versions of expo-barcode-scanner. One possible workaround is to explicitly set the dimensions of the BarCodeScanner to the dimensions of the screen:

import { Dimensions } from 'react-native';

<BarCodeScanner style={{
    width: Dimensions.get('screen').width,
    height: Dimensions.get('screen').height,
}} />           

Note that setting it to the dimensions of the window, like you tried, does not work.

like image 171
FrederikVds Avatar answered Oct 28 '22 18:10

FrederikVds


FrederikVds's answer not worked for me. So I have changed the expo camera which has the barcode scanner functionality too. You can do it like following:

import { Camera } from 'expo-camera'

<Camera
  onBarCodeScanned={scanned ? undefined : this._handleBarCodeScanned}
  style={StyleSheet.absoluteFillObject}
/>

Optionally you can use ratio='16:9'.

If you need to use expo libraries in react-native cli, you should follow these setups

Here is the issue discussion: https://github.com/expo/expo/issues/5212

like image 39
Fahry Mohammed Avatar answered Oct 28 '22 17:10

Fahry Mohammed


import { BarCodeScanner, BarCodeScannerResult } from 
'expo-barcode-scanner'


const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;

export default function XYZ() {            

 return(
  <BarCodeScanner
   onBarCodeScanned={scanned ? undefined : 
   handleBarCodeScanned}
   style={{ width: height - 188, height: height, 
   alignSelf: "center" }}
  />
 )
}
like image 1
Bilal Sabugar Avatar answered Oct 28 '22 17:10

Bilal Sabugar