react-native-qrcode-scanner icon indicating copy to clipboard operation
react-native-qrcode-scanner copied to clipboard

Camera sizing dont work (Android)

Open messenja opened this issue 2 years ago • 4 comments

I want to show camera as square in center of screen. But it always the same size. I see right styles dimensions (had to mark borders) before camera starts, but when it starts it always overflow that dimensions. Is there a solution?

import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import QRCodeScanner from 'react-native-qrcode-scanner';


class ScanScreen extends Component {
  onSuccess = e => {
    console.log('Data: ', JSON.stringify(e.data, null, 2));
  };

  render() {
    return (
      <QRCodeScanner
        onRead={this.onSuccess}
        containerStyle={styles.container}
        cameraStyle={styles.camera}
        cameraContainerStyle={styles.cameraContainer}
        cameraProps={{ratio: '4:3'}}
      />
    );
  }
}

const styles = StyleSheet.create({
  container: {
    borderColor: 'green',
    borderWidth: 1,
    paddingVertical: 32,
  },
  camera: {
    borderColor: 'red',
    borderWidth: 1,
    width: 300,
    height: 300,
  },
  cameraContainer: {
    flex:1,
    alignItems: 'center',
    justifyContent: 'center',
    width: 300,
    height: 300,
  },

});

export default ScanScreen;

photo_2021-11-19_12-33-54

messenja avatar Nov 19 '21 09:11 messenja

Try adding following styles to QRCodeScanner component.

containerStyle={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'red',
}}
topViewStyle={{flex: 0}}
bottomViewStyle={{flex: 0}}
cameraStyle={{overflow: 'hidden'}}

pakkibokati2012 avatar Nov 20 '21 14:11 pakkibokati2012

@pakkibokati2012 i got this, but how to decrease viewport of camera? Is it posible to show it as a box with dimensions 300x300? photo_2021-11-22_07-58-28

messenja avatar Nov 22 '21 05:11 messenja

@messenja, try applying height and width to the cameraStyle prop.

pakkibokati2012 avatar Nov 22 '21 16:11 pakkibokati2012

This will help you https://www.youtube.com/watch?v=sE0MEyFA7E4&list=PLQhQEGkwKZUrempLnmxjt7ZCZJu1W3p2i&index=10

BraveEvidence avatar Feb 25 '23 14:02 BraveEvidence