darryncampbell / DataWedgeReactNative

Demo app to show how to access Zebra's DataWedge with React Native
https://developer.zebra.com/community/home/blog/2018/10/29/developing-react-native-applications-on-zebra-devices
MIT License
40 stars 13 forks source link

Unable to use scanner for multiple purpose/inputs #23

Closed saurabhshah23 closed 3 years ago

saurabhshah23 commented 3 years ago

In react native, I am unable to remove the broadcast registration. I tried below code:

`

  const registerBroadcastReceiver = () => {
    DataWedgeIntents.registerBroadcastReceiver({
      filterActions: [
          'com.zebra.reactnativedemo.ACTION',
          'com.symbol.datawedge.api.RESULT_ACTION'
      ],
      filterCategories: [
          'android.intent.category.DEFAULT'
      ]
    });
  }
  const broadcastReceiver = (intent) => {
    //  Broadcast received
    console.log('Received Intent: ' + JSON.stringify(intent));
  }
  // let deviceEmitterSubscription;
  useEffect(() => {
    const deviceEmitterSubscription = DeviceEventEmitter.addListener('datawedge_broadcast_intent', (intent) => {broadcastReceiver(intent)});
    registerBroadcastReceiver();
    return () => {
      deviceEmitterSubscription.remove();
    }
  }, [])

`

It still continues to execute same function on every scan even on other screens/pages of my app.

darryncampbell commented 3 years ago

There is no ability to unregister a receiver (which I admit is a bit of an oversight!). If you try to register a second receiver the first one will be overwritten so you could register with an action that would never be invoked to achieve the same aim.