Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 780 Bytes

react-native-cemera.md

File metadata and controls

48 lines (39 loc) · 780 Bytes

React Native Camera

By default, it reads the barcode multiple times. Use a flagging variable to handle it only once

let read = false


function getModel(e) {
if (read) {
  return
}
read = true

const model = findModel(e.data)

if(!model||model==='') {
  Alert.alert(
    'Model not found',
    'The barcode does not match any model. Please enter the model manually. If you are not sure, please contact Navienuk.',
    [
      {
        text: 'Ok',
        style: "ok",
        onPress: () => {
          read = false
        }
      },
    ],
    {
      cancelable: true,
      onDismiss: () => {
        read = false
      }
    }
  )
  return
}

setRegistration({ ...registration,
  model: model,
  serialNumber: e.data
})

navigation.navigate('Form')
}