Created
July 28, 2021 16:46
-
-
Save felisio/075ebcbabd05e46fee3818c73f6331f1 to your computer and use it in GitHub Desktop.
React Native Fingerprint scanner code example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
Button, | |
Dimensions, | |
SafeAreaView, | |
ScrollView, | |
StyleSheet, | |
Text, | |
View, | |
} from 'react-native'; | |
import FingerprintScanner from 'react-native-fingerprint-scanner'; | |
async function verifyIfSensorIsAvailable() { | |
const biometryType = await FingerprintScanner.isSensorAvailable(); | |
if ( | |
biometryType === 'Touch ID' || | |
biometryType === 'Face ID' || | |
biometryType === 'Biometrics' | |
) { | |
return true; | |
} | |
return false; | |
} | |
async function getCredentials() { | |
try { | |
await FingerprintScanner.authenticate({ | |
description: 'Biometric Scan Test', | |
}); | |
console.log('BIOMETRIC SUCESS 😎'); | |
} catch (error) { | |
console.error('Biometric Erro authenticate:', error); | |
} | |
} | |
function loginByBiometric() { | |
if (verifyIfSensorIsAvailable()) { | |
getCredentials(); | |
} | |
} | |
function App() { | |
return ( | |
<SafeAreaView> | |
<ScrollView contentInsetAdjustmentBehavior="automatic"> | |
<View style={styles.viewContainer}> | |
<Text>React Native App Test</Text> | |
<Button onPress={loginByBiometric} title="Test Biometric Login" /> | |
</View> | |
</ScrollView> | |
</SafeAreaView> | |
); | |
} | |
const WINDOW_WIDTH = Dimensions.get('window').width; | |
const WINDOW_HEIGHT = Dimensions.get('window').height; | |
const styles = StyleSheet.create({ | |
viewContainer: { | |
flex: 1, | |
justifyContent: 'flex-start', | |
alignItems: 'center', | |
padding: 10, | |
width: WINDOW_WIDTH, | |
height: WINDOW_HEIGHT - 30, | |
}, | |
}); | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment