-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.js
More file actions
63 lines (52 loc) · 1.68 KB
/
index.android.js
File metadata and controls
63 lines (52 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {
NativeModules,
DeviceEventEmitter,
} from 'react-native';
import invariant from 'fbjs/lib/invariant';
const FingerPrintNative = NativeModules.FingerPrintAndroid;
const _handlers = new Map();
class FingerPrintAndroid {
static addEventListener(type: string, handler: Function) {
invariant(
[FingerPrintNative.ERROR_EVENT_NAME].indexOf(type) !== -1,
'Trying to subscribe to unknown event: "%s"', type,
);
_handlers.set(
handler,
DeviceEventEmitter.addListener(FingerPrintNative.ERROR_EVENT_NAME, handler),
);
}
static removeEventListener(type: string, handler: Function) {
invariant(
[FingerPrintNative.ERROR_EVENT_NAME].indexOf(type) !== -1,
'Trying to subscribe to unknown event: "%s"', type,
);
const emitterHandler = _handlers.get(handler);
if (emitterHandler) {
emitterHandler.remove();
_handlers.delete(handler);
}
}
}
Object.keys(FingerPrintNative).forEach((k) => {
FingerPrintAndroid[k] = FingerPrintNative[k];
});
FingerPrintAndroid.authenticate = () => {
return FingerPrintNative.authenticate()
.catch((error) => {
throw new AuthError(error.code, error.message);
});
};
FingerPrintAndroid.cancelAuthentication = FingerPrintNative.cancelAuthentication;
FingerPrintAndroid.isHardwareDetected = FingerPrintNative.isHardwareDetected;
FingerPrintAndroid.hasEnrolledFingerprints = FingerPrintNative.hasEnrolledFingerprints;
FingerPrintAndroid.hasPermission = FingerPrintNative.hasPermission;
class AuthError extends Error {
constructor(alias, message) {
super();
this.type = 'ERROR';
this.message_alias = alias;
this.message = message;
}
}
export default FingerPrintAndroid;