otpless-headless-rn 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +16 -0
- package/android/build.gradle +86 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/otplessheadlessrn/OtplessReactNativeManager.kt +12 -0
- package/android/src/main/java/com/otplessheadlessrn/OtplessReactNativeModule.kt +170 -0
- package/android/src/main/java/com/otplessheadlessrn/OtplessReactNativePackage.kt +17 -0
- package/android/src/main/java/com/otplessheadlessrn/utils.kt +121 -0
- package/ios/OtplessHeadlessRN.h +3 -0
- package/ios/OtplessHeadlessRN.m +27 -0
- package/ios/OtplessHeadlessRN.swift +187 -0
- package/ios/OtplessHeadlessRN.xcodeproj/project.pbxproj +283 -0
- package/ios/OtplessHeadlessRN.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/OtplessHeadlessRN.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/OtplessHeadlessRN.xcodeproj/project.xcworkspace/xcuserdata/sparsh.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/OtplessHeadlessRN.xcodeproj/xcuserdata/sparsh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/index.js +60 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +54 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/index.d.ts +16 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/otpless-headless-rn.podspec +37 -0
- package/package.json +165 -0
- package/src/index.tsx +74 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const LINKING_ERROR =
|
|
5
|
+
`The package 'otpless-headless-rn' doesn't seem to be linked. Make sure: \n\n` +
|
|
6
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
7
|
+
'- You rebuilt the app after installing the package\n' +
|
|
8
|
+
'- You are not using Expo Go\n';
|
|
9
|
+
|
|
10
|
+
const OtplessHeadlessRN = NativeModules.OtplessHeadlessRN
|
|
11
|
+
? NativeModules.OtplessHeadlessRN
|
|
12
|
+
: new Proxy(
|
|
13
|
+
{},
|
|
14
|
+
{
|
|
15
|
+
get() {
|
|
16
|
+
throw new Error(LINKING_ERROR);
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
interface OtplessResultCallback {
|
|
22
|
+
(result: any): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class OtplessHeadlessModule {
|
|
26
|
+
private eventEmitter: NativeEventEmitter | null = null;
|
|
27
|
+
|
|
28
|
+
constructor() {
|
|
29
|
+
this.eventEmitter = null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
clearListener() {
|
|
33
|
+
this.eventEmitter?.removeAllListeners('OTPlessEventResult');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
initialize(appId: String, loginUri: string | null = null) {
|
|
37
|
+
if (this.eventEmitter == null) {
|
|
38
|
+
this.eventEmitter = new NativeEventEmitter(OtplessHeadlessRN);
|
|
39
|
+
}
|
|
40
|
+
// call the native method
|
|
41
|
+
OtplessHeadlessRN.initialize(appId, loginUri);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setResponseCallback(callback: OtplessResultCallback) {
|
|
45
|
+
this.eventEmitter!!.addListener('OTPlessEventResult', callback);
|
|
46
|
+
// call the native method
|
|
47
|
+
OtplessHeadlessRN.setResponseCallback()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
start(input: any) {
|
|
51
|
+
OtplessHeadlessRN.start(input);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
commitResponse(response: any) {
|
|
55
|
+
OtplessHeadlessRN.commitResponse(response);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
performOneTap(data: any) {
|
|
59
|
+
OtplessHeadlessRN.performOneTap(data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Checks if whatsapp is installed on android device
|
|
63
|
+
isWhatsappInstalled(callback: (hasWhatsapp: boolean) => void) {
|
|
64
|
+
if (Platform.OS === 'android') {
|
|
65
|
+
OtplessHeadlessRN.isWhatsappInstalled((result: any) => {
|
|
66
|
+
const hasWhatsapp = result.hasWhatsapp === true;
|
|
67
|
+
callback(hasWhatsapp);
|
|
68
|
+
});
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { OtplessHeadlessModule };
|