Jump to content

when ever i scan a barcode in it reads but does not send any data or type and just sends an undefined value for it and thus i get an undifined is not a function error when I pass it to my action

import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";
import { connect } from 'react-redux';
import { Button } from "react-native-elements";
import { BarCodeScanner, Permissions } from "expo";
import { itemUPC } from "../actions";
import { PRIMARY_COLOR } from "../constants/style";


class CameraScreen extends Component {

  static navigationOptions = ({ navigation }) => (
    {
       // tabBarVisible: false,
        title: "Camera",
        tabBarLabel: "main",
        headerTitleStyle: {
          textAlign: "center",
          alignSelf: "center"
        }, 
        headerLeft: (
            <Button
              navigate={navigation.navigate}
              large
              icon={{ name: "menu" }}
              backgroundColor={PRIMARY_COLOR}
              onPress={() => navigation.navigate("DrawerOpen")}
            />
          )
        });
        state = {
          hasCameraPermission: null
        };

        async componentWillMount() {
          const { status } = await Permissions.askAsync(Permissions.CAMERA);
          this.setState({ hasCameraPermission: status === 'granted' });
          }
          _handleBarCodeRead = ({ type, data }) => {
            this.props.navigation.navigate('searchResults');
            this.props.itemUPC({ type, data });
          }

        render() {
          const { hasCameraPermission } = this.state;

          if (hasCameraPermission === null) {
            return <Text>Requesting for camera permission</Text>;
          } else if (hasCameraPermission === false) {
            return <Text>No access to camera</Text>;
          } 
            return (
              <View style={{ flex: 1 }}>
                <BarCodeScanner
                  torchMode="on"
                  onBarCodeRead={this._handleBarCodeRead}
                  style={StyleSheet.absoluteFill}
                />
              </View>
            );
        }
      }


  export default connect(null, itemUPC)(CameraScreen);

 

Link to comment
https://linustechtips.com/topic/879600-onbarcoderead-returning-undefined/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×