From d3b9a53f922fb2ac042085f76f8e9196ecd5179e Mon Sep 17 00:00:00 2001 From: Richie Date: Sat, 25 Jun 2022 20:17:32 +0800 Subject: [PATCH] feat: detect Android NFC on / off state --- src/Screens/Home/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Screens/Home/index.js b/src/Screens/Home/index.js index f7ba218..9ce74ba 100644 --- a/src/Screens/Home/index.js +++ b/src/Screens/Home/index.js @@ -101,6 +101,21 @@ function HomeScreen(props) { onBackgroundTag, ); + // listen to the NFC on/off state on Android device + if (Platform.OS === 'android') { + NfcManager.setEventListener( + NfcEvents.StateChanged, + ({state} = {}) => { + NfcManager.cancelTechnologyRequest().catch(() => 0); + if (state === 'off') { + setEnabled(false); + } else if (state === 'on') { + setEnabled(true); + } + }, + ); + } + Linking.addEventListener('url', (event) => { if (event.url) { onDeepLink(event.url, false);