react-native-nfc-manager icon indicating copy to clipboard operation
react-native-nfc-manager copied to clipboard

Update readme

Open ShiriNmi1520 opened this issue 2 years ago • 9 comments

Changes

  • Update basic usage example code

  • Fixed some typos

  • The other example code such as registerTagEvent, NDEF-Writing and Mifare Ultralight might be improved in future

ShiriNmi1520 avatar May 06 '22 05:05 ShiriNmi1520

It seems that the code snippet want to demonstrate how to start NFC scanning automatically without pressing a button, but I think it will be easier to understand if the whole process starts from a button press.

In such a case, we can avoid extra useEffect hook and focus our code on NFC part, since it serves as the most basic example for the library.

About the scan without button press scenario, I think it might deserve another README section since people often ask about it.

whitedogg13 avatar May 06 '22 09:05 whitedogg13

So it might be better to move this part to the new MD file and give the link in the original README right? Or I can add new section in README

ShiriNmi1520 avatar May 06 '22 09:05 ShiriNmi1520

Yes, I think this will be great!

whitedogg13 avatar May 06 '22 09:05 whitedogg13

Ok I'll mark this PR as a draft till I have done with this part

ShiriNmi1520 avatar May 06 '22 09:05 ShiriNmi1520

Both new MD or new section are good to me

whitedogg13 avatar May 06 '22 09:05 whitedogg13

I'd prefer new section

ShiriNmi1520 avatar May 06 '22 09:05 ShiriNmi1520

It seems that the code snippet wants to demonstrate how to start NFC scanning automatically without pressing a button, but I think it will be easier to understand if the whole process starts from a button press.

In such a case, we can avoid the extra useEffect hook and focus our code on the NFC part, since it serves as the most basic example for the library.

About the scan without button press scenario, I think it might deserve another README section since people often ask about it.

About extra useEffect, did you mean the following code about initializing nfcManager? I implement nfcManager.start() this way to prevent multi time initalize, or there's might be better way to implement this

  // Initialize the NFC manager (This will run only once)
  useEffect(() => {
    nfcManager.isSupported().then(supported => {
      if (supported) {
        nfcManager.start();
      } else {
        setNfcData('NFC not supported');
      }
    })
  }, [])

ShiriNmi1520 avatar May 10 '22 04:05 ShiriNmi1520

I understand you're using a standard zero deps pattern to initialize the native module.

The problem is inside the next hook:

  // Listen to NFC events (This will run every-time after nfcData changes)
  useEffect(() => {
    getNFCInfo();
  }, [nfcData])

Two points here:

  • Once nfcData changed, the getNFCInfo() will be called, which is generally not desired.
  • It cannot garuantee native NfcManager.start() is successfully called

And one extra point to be aware is that: NfcManager.start() is also async call, so there might be a chance that you trigger the NFC scan before the native module is fully initialized.

whitedogg13 avatar May 10 '22 06:05 whitedogg13

I understand you're using a standard zero deps pattern to initialize the native module.

The problem is inside the next hook:

  // Listen to NFC events (This will run every-time after nfcData changes)
  useEffect(() => {
    getNFCInfo();
  }, [nfcData])

Two points here:

  • Once nfcData changed, the getNFCInfo() will be called, which is generally not desired.
  • It cannot garuantee native NfcManager.start() is successfully called

And one extra point to be aware is that: NfcManager.start() is also async call, so there might be a chance that you trigger the NFC scan before the native module is fully initialized.

I got it, thanks for your feedback, appreciated :)

ShiriNmi1520 avatar May 10 '22 09:05 ShiriNmi1520

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Aug 15 '22 02:08 github-actions[bot]

This PR was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar Aug 30 '22 02:08 github-actions[bot]