react-native-fingerprint-scanner
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "react-native-fingerprint-scanner", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "React Native Fingerprint Scanner for Android and iOS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
184
README.md
@@ -1,2 +0,2 @@ | ||
# react-native-fingerprint-scanner | ||
# React Native Fingerprint Scanner | ||
@@ -6,2 +6,9 @@ [![Version](https://img.shields.io/npm/v/react-native-fingerprint-scanner.svg)](https://www.npmjs.com/package/react-native-fingerprint-scanner) | ||
React Native Fingerprint Scanner is a [React Native](http://facebook.github.io/react-native/) library for authenticating users with Fingerprint (TouchID). | ||
### iOS Version | ||
The usage of the TouchID is based on a framework, named **Local Authentication**. | ||
It provides a **Default View** that prompts the user to place a finger to the iPhone’s button for scanning. | ||
<div> | ||
@@ -12,2 +19,7 @@ <img src="https://github.com/hieuvp/react-native-fingerprint-scanner/raw/master/screenshots/ios-availability.png" height="600"> | ||
### Android Version | ||
Using an expandable Android Fingerprint API library, which combines [Samsung](http://developer.samsung.com/galaxy/pass#) and [MeiZu](http://open-wiki.flyme.cn/index.php?title=%E6%8C%87%E7%BA%B9%E8%AF%86%E5%88%ABAPI)'s official Fingerprint API. | ||
Samsung and MeiZu's Fingerprint SDK supports most devices which system versions less than Android 6.0. | ||
<div> | ||
@@ -18,13 +30,18 @@ <img src="https://github.com/hieuvp/react-native-fingerprint-scanner/raw/master/screenshots/android-availability.png" height="600"> | ||
## Getting started | ||
### Table of Contents | ||
- [Installation](#installation) | ||
- [Example](#example) | ||
- [API](#api) | ||
## Installation | ||
`$ npm install react-native-fingerprint-scanner --save` | ||
### Mostly automatic installation | ||
### Automatically | ||
`$ react-native link react-native-fingerprint-scanner` | ||
### Manual installation | ||
### Manually | ||
#### iOS | ||
@@ -52,6 +69,159 @@ | ||
### Extra Steps | ||
## Usage | ||
1. Make sure the following versions are all correct in `android/app/build.gradle` | ||
``` | ||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.3" | ||
... | ||
defaultConfig { | ||
targetSdkVersion 25 | ||
``` | ||
2. Add necessary rules to `android/app/proguard-rules.pro` | ||
``` | ||
# MeiZu Fingerprint | ||
-keep class com.fingerprints.service.** { *; } | ||
# Samsung Fingerprint | ||
-keep class com.samsung.android.sdk.** { *; } | ||
``` | ||
## Example | ||
[Example Source Code](https://github.com/hieuvp/react-native-fingerprint-scanner/tree/master/examples) | ||
**iOS Implementation** | ||
```javascript | ||
import ReactNativeFingerprintScanner from 'react-native-fingerprint-scanner'; | ||
import React, { Component, PropTypes } from 'react'; | ||
import { AlertIOS } from 'react-native'; | ||
import FingerprintScanner from 'react-native-fingerprint-scanner'; | ||
class FingerprintPopup extends Component { | ||
componentDidMount() { | ||
FingerprintScanner | ||
.authenticate({ description: 'Scan your fingerprint on the device scanner to continue' }) | ||
.then(() => { | ||
this.props.handlePopupDismissed(); | ||
AlertIOS.alert('Authenticated successfully'); | ||
}) | ||
.catch((error) => { | ||
this.props.handlePopupDismissed(); | ||
AlertIOS.alert(error.message); | ||
}); | ||
} | ||
render() { | ||
return false; | ||
} | ||
} | ||
FingerprintPopup.propTypes = { | ||
handlePopupDismissed: PropTypes.func.isRequired, | ||
}; | ||
export default FingerprintPopup; | ||
``` | ||
**Android Implementation** | ||
```javascript | ||
import React, { Component, PropTypes } from 'react'; | ||
import { | ||
Alert, | ||
Image, | ||
Text, | ||
TouchableOpacity, | ||
View, | ||
ViewPropTypes | ||
} from 'react-native'; | ||
import FingerprintScanner from 'react-native-fingerprint-scanner'; | ||
import ShakingText from './ShakingText.component'; | ||
import styles from './FingerprintPopup.component.styles'; | ||
class FingerprintPopup extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { errorMessage: undefined }; | ||
} | ||
componentDidMount() { | ||
FingerprintScanner | ||
.authenticate({ onAttempt: this.handleAuthenticationAttempted }) | ||
.then(() => { | ||
this.props.handlePopupDismissed(); | ||
Alert.alert('Fingerprint Authentication', 'Authenticated successfully'); | ||
}) | ||
.catch((error) => { | ||
this.setState({ errorMessage: error.message }); | ||
this.description.shake(); | ||
}); | ||
} | ||
componentWillUnmount() { | ||
FingerprintScanner.release(); | ||
} | ||
handleAuthenticationAttempted = (error) => { | ||
this.setState({ errorMessage: error.message }); | ||
this.description.shake(); | ||
}; | ||
render() { | ||
const { errorMessage } = this.state; | ||
const { style, handlePopupDismissed } = this.props; | ||
return ( | ||
<View style={styles.container}> | ||
<View style={[styles.contentContainer, style]}> | ||
<Image | ||
style={styles.logo} | ||
source={require('./assets/finger_print.png')} | ||
/> | ||
<Text style={styles.heading}> | ||
Fingerprint{'\n'}Authentication | ||
</Text> | ||
<ShakingText | ||
ref={(instance) => { this.description = instance; }} | ||
style={styles.description(!!errorMessage)}> | ||
{errorMessage || 'Scan your fingerprint on the\ndevice scanner to continue'} | ||
</ShakingText> | ||
<TouchableOpacity | ||
style={styles.buttonContainer} | ||
onPress={handlePopupDismissed} | ||
> | ||
<Text style={styles.buttonText}> | ||
BACK TO MAIN | ||
</Text> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
); | ||
} | ||
} | ||
FingerprintPopup.propTypes = { | ||
style: ViewPropTypes.style, | ||
handlePopupDismissed: PropTypes.func.isRequired, | ||
}; | ||
export default FingerprintPopup; | ||
``` | ||
## API | ||
| Method | Description | Example | | ||
|---|---|---| | ||
| `isSensorAvailable` (ios, android) | Returns a Promise. | `FingerprintScanner.isSensorAvailable()` | | ||
| `authenticate` (ios) | Returns a Promise. | `FingerprintScanner.authenticate({ description })` | | ||
| `authenticate` (android) | Returns a Promise. | `FingerprintScanner.authenticate({ onAttempt })` | | ||
| `release` (android only) | Stops Fingerprint Scanner listener and optimizes memory. | `FingerprintScanner.release();` | |
62388
224