【问题标题】:How to reduce size on QR code scanner, customize QR code scanner如何缩小二维码扫描仪的尺寸,定制二维码扫描仪
【发布时间】:2019-06-12 09:35:56
【问题描述】:

如何减小 QR 码扫描仪的尺寸。 当我尝试应用样式道具时,它不起作用
在下面的代码中,我的扫描仪正在工作,但它正在全屏显示,我必须减小它的高度和宽度

 import React, { Component } from 'react';

    import {
      AppRegistry,
      StyleSheet,
      Text,
      TouchableOpacity,
      Linking,
      View,
    } from 'react-native';
    import {  Dimensions } from "react-native";

    const SCREEN_HEIGHT = Dimensions.get("window").height;
    const SCREEN_WIDTH = Dimensions.get("window").width;
    const scanBarWidth = SCREEN_WIDTH * 0.46;

    import QRCodeScanner from 'react-native-qrcode-scanner';

    export default class OpenTicket extends Component {
      onSuccess(e) {
    //    console.log(e.data);
        this.props.navigation.navigate('OpenApplianceIssue', {
          data: e.data,
          } );
      }


      render() {
        return (
    // this below scanner size I have to reduce 

          <QRCodeScanner style={{height: 50, width: 50, 
             borderRadius: 10}}
            onRead={this.onSuccess.bind(this)}
            cameraStyle={{ height: SCREEN_HEIGHT }}
            cameraProps={{captureAudio: false}}
            bottomContent={
                <Text style={styles.buttonText}>SCAN ITEM</Text>


            }

          />
        );
      }
    }

    const styles = StyleSheet.create({
      centerText: {
        flex: 1,
        fontSize: 18,
        padding: 32,
        color: '#777',
      },
      textBold: {
        fontWeight: '500',
        color: '#000',
      },
      buttonText: {
        fontSize: 21,
        color: 'rgb(0,122,255)',
      },
      buttonTouchable: {
        padding: 16,
      },
    });

// 我已经附上了我正在使用的完整代码。 // 谢谢..

【问题讨论】:

    标签: javascript reactjs react-native ecmascript-6 react-redux


    【解决方案1】:

    您可以使用 cameraStyle 固定高度而不是整个屏幕高度 这是我的工作道具:

    containerStyle={{height:300}}
    cameraStyle={[{height:300}]}
    

    【讨论】: