forked from faizalshap/react-native-otp-verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
31 lines (26 loc) · 900 Bytes
/
index.ts
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
import {DeviceEventEmitter, NativeModules, Platform} from 'react-native';
const RNOtpVerify = NativeModules.RNOtpVerify;
interface OtpVerify {
getOtp: () => Promise<boolean>;
getHash: () => Promise<string[]>;
addListener: (handler: (value: string) => any) => void;
removeListener: () => void;
}
// @ts-ignore
let OtpVerify: OtpVerify = null;
if (Platform.OS === "android") {
OtpVerify = {
getOtp: RNOtpVerify.getOtp,
getHash: RNOtpVerify.getHash,
addListener: (handler) =>{
RNOtpVerify.registerReceiver();
DeviceEventEmitter
.addListener('com.faizalshap.otpVerify:otpReceived', handler)
},
removeListener: () => {
DeviceEventEmitter.removeAllListeners('com.faizalshap.otpVerify:otpReceived')
RNOtpVerify.unregisterReceiver();
},
}
}
export default OtpVerify;