rn-sms-otp-autofill
Version:
React Native SMS OTP autofill for Android - TurboModule implementation for automatic SMS OTP code detection and filling
45 lines (42 loc) • 1.19 kB
JavaScript
;
import { NativeEventEmitter, Platform } from 'react-native';
import RnSmsOtpAutofill from './NativeRnSmsOtpAutofill';
// Export the TurboModule for direct access
export { default as RnSmsOtpAutofill } from './NativeRnSmsOtpAutofill';
export function requestOtpAutofill() {
if (Platform.OS === 'android') {
RnSmsOtpAutofill.requestOtpAutofill();
}
}
export function stopOtpAutofill() {
if (Platform.OS === 'android') {
RnSmsOtpAutofill.stopOtpAutofill();
}
}
export function listenOtpAutofill(callback, onError) {
if (Platform.OS === 'android') {
const emitter = new NativeEventEmitter();
const subOtp = emitter.addListener('onOtpAutofill', event => {
if (event?.otp) callback(event.otp);
});
let subError;
if (onError) {
subError = emitter.addListener('onOtpAutofillError', event => {
if (event?.error) onError(event.error);
});
}
return () => {
subOtp.remove();
subError?.remove();
};
}
return () => {};
}
// Default export with all functions
export default {
requestOtpAutofill,
stopOtpAutofill,
listenOtpAutofill,
RnSmsOtpAutofill
};
//# sourceMappingURL=index.js.map