@oiti/rn-liveness3d 1.1.2 → 2.1.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.
Files changed (154) hide show
  1. package/README.md +33 -237
  2. package/android/build.gradle +4 -18
  3. package/android/settings.gradle +2 -2
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/java/br/com/oiti/rnliveness3d/RnLiveness3dModule.kt +198 -132
  6. package/android/src/main/java/br/com/oiti/rnliveness3d/theme/Liveness3DFonts.kt +44 -0
  7. package/android/src/main/java/br/com/oiti/rnliveness3d/theme/Liveness3DText.kt +68 -0
  8. package/android/src/main/java/br/com/oiti/rnliveness3d/theme/Liveness3DTheme.kt +147 -0
  9. package/ios/Podfile +2 -1
  10. package/ios/Pods/Manifest.lock +23 -19
  11. package/ios/RnLiveness3d.m +8 -3
  12. package/ios/RnLiveness3d.swift +198 -114
  13. package/lib/commonjs/@types/ArgsType.js +4 -0
  14. package/lib/commonjs/@types/FontsType.js +2 -0
  15. package/lib/commonjs/@types/FontsType.js.map +1 -0
  16. package/lib/commonjs/@types/ResultType.js +2 -0
  17. package/lib/commonjs/@types/ResultType.js.map +1 -0
  18. package/lib/commonjs/@types/ResultTypes.js +6 -0
  19. package/lib/commonjs/@types/ResultTypes.js.map +1 -0
  20. package/lib/commonjs/@types/TextsType.js +2 -0
  21. package/lib/commonjs/@types/TextsType.js.map +1 -0
  22. package/lib/commonjs/@types/ThemeType.js +2 -0
  23. package/lib/commonjs/@types/ThemeType.js.map +1 -0
  24. package/lib/commonjs/actions/BackButton.js +35 -0
  25. package/lib/commonjs/actions/BackButton.js.map +1 -0
  26. package/lib/commonjs/actions/ContinueButton.js +43 -0
  27. package/lib/commonjs/actions/ContinueButton.js.map +1 -0
  28. package/lib/commonjs/actions/PermissionButton.js +35 -0
  29. package/lib/commonjs/actions/PermissionButton.js.map +1 -0
  30. package/lib/commonjs/context/Liveness3DContext.js +104 -0
  31. package/lib/commonjs/context/Liveness3DContext.js.map +1 -0
  32. package/lib/commonjs/helpers/Liveness3DHelper.js +34 -0
  33. package/lib/commonjs/helpers/Liveness3DHelper.js.map +1 -0
  34. package/lib/commonjs/index.js +121 -78
  35. package/lib/commonjs/index.js.map +1 -1
  36. package/lib/commonjs/interfaces/Liveness3DHelper.js +6 -0
  37. package/lib/commonjs/interfaces/Liveness3DHelper.js.map +1 -0
  38. package/lib/commonjs/interfaces/OitiBackButtonInterface.js +6 -0
  39. package/lib/commonjs/interfaces/OitiBackButtonInterface.js.map +1 -0
  40. package/lib/commonjs/interfaces/OitiContinueButton.js +6 -0
  41. package/lib/commonjs/interfaces/OitiContinueButton.js.map +1 -0
  42. package/lib/commonjs/interfaces/OitiPermissionButtonInterface.js +6 -0
  43. package/lib/commonjs/interfaces/OitiPermissionButtonInterface.js.map +1 -0
  44. package/lib/commonjs/screens/Liveness3D/InstructionsView.js +4 -4
  45. package/lib/commonjs/screens/Liveness3D/InstructionsView.js.map +1 -1
  46. package/lib/commonjs/utils/continueButton.js +17 -0
  47. package/lib/commonjs/utils/continueButton.js.map +1 -0
  48. package/lib/commonjs/utils/permissions.js +30 -0
  49. package/lib/commonjs/utils/permissions.js.map +1 -0
  50. package/lib/commonjs/utils/screenStore.js +12 -0
  51. package/lib/commonjs/utils/screenStore.js.map +1 -0
  52. package/lib/module/@types/ArgsType.js +1 -1
  53. package/lib/module/@types/FontsType.js +2 -0
  54. package/lib/module/@types/FontsType.js.map +1 -0
  55. package/lib/module/@types/ResultType.js +2 -0
  56. package/lib/module/@types/ResultType.js.map +1 -0
  57. package/lib/module/@types/ResultTypes.js +2 -0
  58. package/lib/module/@types/ResultTypes.js.map +1 -0
  59. package/lib/module/@types/TextsType.js +2 -0
  60. package/lib/module/@types/TextsType.js.map +1 -0
  61. package/lib/module/@types/ThemeType.js +2 -0
  62. package/lib/module/@types/ThemeType.js.map +1 -0
  63. package/lib/module/actions/BackButton.js +26 -0
  64. package/lib/module/actions/BackButton.js.map +1 -0
  65. package/lib/module/actions/ContinueButton.js +34 -0
  66. package/lib/module/actions/ContinueButton.js.map +1 -0
  67. package/lib/module/actions/PermissionButton.js +26 -0
  68. package/lib/module/actions/PermissionButton.js.map +1 -0
  69. package/lib/module/context/Liveness3DContext.js +92 -0
  70. package/lib/module/context/Liveness3DContext.js.map +1 -0
  71. package/lib/module/helpers/Liveness3DHelper.js +25 -0
  72. package/lib/module/helpers/Liveness3DHelper.js.map +1 -0
  73. package/lib/module/index.js +97 -75
  74. package/lib/module/index.js.map +1 -1
  75. package/lib/module/interfaces/Liveness3DHelper.js +2 -0
  76. package/lib/module/interfaces/Liveness3DHelper.js.map +1 -0
  77. package/lib/module/interfaces/OitiBackButtonInterface.js +2 -0
  78. package/lib/module/interfaces/OitiBackButtonInterface.js.map +1 -0
  79. package/lib/module/interfaces/OitiContinueButton.js +2 -0
  80. package/lib/module/interfaces/OitiContinueButton.js.map +1 -0
  81. package/lib/module/interfaces/OitiPermissionButtonInterface.js +2 -0
  82. package/lib/module/interfaces/OitiPermissionButtonInterface.js.map +1 -0
  83. package/lib/module/screens/Liveness3D/InstructionsView.js +4 -4
  84. package/lib/module/screens/Liveness3D/InstructionsView.js.map +1 -1
  85. package/lib/module/utils/continueButton.js +10 -0
  86. package/lib/module/utils/continueButton.js.map +1 -0
  87. package/lib/module/utils/permissions.js +21 -0
  88. package/lib/module/utils/permissions.js.map +1 -0
  89. package/lib/module/utils/screenStore.js +5 -0
  90. package/lib/module/utils/screenStore.js.map +1 -0
  91. package/lib/typescript/@types/ArgsType.d.ts +9 -9
  92. package/lib/typescript/@types/ArgsType.d.ts.map +1 -1
  93. package/lib/typescript/@types/FontsType.d.ts +12 -0
  94. package/lib/typescript/@types/FontsType.d.ts.map +1 -0
  95. package/lib/typescript/@types/ResultType.d.ts +13 -0
  96. package/lib/typescript/@types/ResultType.d.ts.map +1 -0
  97. package/lib/typescript/@types/ResultTypes.d.ts +6 -0
  98. package/lib/typescript/@types/ResultTypes.d.ts.map +1 -0
  99. package/lib/typescript/@types/TextsType.d.ts +36 -0
  100. package/lib/typescript/@types/TextsType.d.ts.map +1 -0
  101. package/lib/typescript/@types/ThemeType.d.ts +48 -0
  102. package/lib/typescript/@types/ThemeType.d.ts.map +1 -0
  103. package/lib/typescript/actions/BackButton.d.ts +4 -0
  104. package/lib/typescript/actions/BackButton.d.ts.map +1 -0
  105. package/lib/typescript/actions/ContinueButton.d.ts +4 -0
  106. package/lib/typescript/actions/ContinueButton.d.ts.map +1 -0
  107. package/lib/typescript/actions/PermissionButton.d.ts +4 -0
  108. package/lib/typescript/actions/PermissionButton.d.ts.map +1 -0
  109. package/lib/typescript/context/Liveness3DContext.d.ts +28 -0
  110. package/lib/typescript/context/Liveness3DContext.d.ts.map +1 -0
  111. package/lib/typescript/helpers/Liveness3DHelper.d.ts +4 -0
  112. package/lib/typescript/helpers/Liveness3DHelper.d.ts.map +1 -0
  113. package/lib/typescript/index.d.ts +21 -8
  114. package/lib/typescript/index.d.ts.map +1 -1
  115. package/lib/typescript/interfaces/Liveness3DHelper.d.ts +7 -0
  116. package/lib/typescript/interfaces/Liveness3DHelper.d.ts.map +1 -0
  117. package/lib/typescript/interfaces/OitiBackButtonInterface.d.ts +6 -0
  118. package/lib/typescript/interfaces/OitiBackButtonInterface.d.ts.map +1 -0
  119. package/lib/typescript/interfaces/OitiContinueButton.d.ts +6 -0
  120. package/lib/typescript/interfaces/OitiContinueButton.d.ts.map +1 -0
  121. package/lib/typescript/interfaces/OitiPermissionButtonInterface.d.ts +6 -0
  122. package/lib/typescript/interfaces/OitiPermissionButtonInterface.d.ts.map +1 -0
  123. package/lib/typescript/screens/Liveness3D/InstructionsView.d.ts +1 -0
  124. package/lib/typescript/screens/Liveness3D/InstructionsView.d.ts.map +1 -1
  125. package/lib/typescript/screens/PermissionView.d.ts +1 -0
  126. package/lib/typescript/screens/PermissionView.d.ts.map +1 -1
  127. package/lib/typescript/utils/continueButton.d.ts +2 -0
  128. package/lib/typescript/utils/continueButton.d.ts.map +1 -0
  129. package/lib/typescript/utils/permissions.d.ts +4 -0
  130. package/lib/typescript/utils/permissions.d.ts.map +1 -0
  131. package/lib/typescript/utils/screenStore.d.ts +5 -0
  132. package/lib/typescript/utils/screenStore.d.ts.map +1 -0
  133. package/oiti-rn-liveness3d.podspec +2 -1
  134. package/package.json +3 -6
  135. package/src/@types/ArgsType.ts +10 -10
  136. package/src/@types/FontsType.ts +22 -0
  137. package/src/@types/ResultType.ts +13 -0
  138. package/src/@types/ResultTypes.ts +6 -0
  139. package/src/@types/TextsType.ts +41 -0
  140. package/src/@types/ThemeType.ts +64 -0
  141. package/src/actions/BackButton.tsx +27 -0
  142. package/src/actions/ContinueButton.tsx +35 -0
  143. package/src/actions/PermissionButton.tsx +27 -0
  144. package/src/context/Liveness3DContext.tsx +122 -0
  145. package/src/helpers/Liveness3DHelper.tsx +24 -0
  146. package/src/index.tsx +120 -87
  147. package/src/interfaces/Liveness3DHelper.tsx +7 -0
  148. package/src/interfaces/OitiBackButtonInterface.tsx +6 -0
  149. package/src/interfaces/OitiContinueButton.tsx +6 -0
  150. package/src/interfaces/OitiPermissionButtonInterface.tsx +6 -0
  151. package/src/screens/Liveness3D/InstructionsView.tsx +8 -8
  152. package/src/utils/continueButton.tsx +12 -0
  153. package/src/utils/permissions.tsx +30 -0
  154. package/src/utils/screenStore.tsx +4 -0
@@ -0,0 +1,122 @@
1
+ import { startLiveness3d } from '../index';
2
+ import React, { createContext, FC, useContext, useState } from 'react';
3
+ import { ArgsType } from '../@types/ArgsType';
4
+ import { onErrorType, onSuccessType } from '../@types/ResultType';
5
+ import { ResultType } from '../@types/ResultTypes';
6
+ import { askPermission } from '../utils/permissions';
7
+ import { Platform } from 'react-native';
8
+
9
+ export const SCREEN = Object.freeze({
10
+ INSTRUCTION_VIEW: 1,
11
+ PERMISSION_VIEW: 2,
12
+ } as const);
13
+
14
+ interface Liveness3DContextType {
15
+ screen: number;
16
+ setScreen: React.Dispatch<React.SetStateAction<number>>;
17
+ navigation: any;
18
+ setNavigation: React.Dispatch<React.SetStateAction<any>>;
19
+ options: ArgsType | undefined;
20
+ setOptions: React.Dispatch<React.SetStateAction<ArgsType | undefined>>;
21
+ onLiveness3DError: (error: onErrorType) => void;
22
+ onLiveness3DSuccess: (result: onSuccessType) => void;
23
+ onBack: () => any;
24
+ onAskPermission: () => any;
25
+ startLiveness: () => any;
26
+ callbackView: string;
27
+ setCallbackView: React.Dispatch<React.SetStateAction<string>>;
28
+ }
29
+
30
+ const Liveness3DContext = createContext<Liveness3DContextType | undefined>(
31
+ undefined
32
+ );
33
+
34
+ export const Liveness3DProvider: FC<ResultType> = ({
35
+ children,
36
+ onError,
37
+ onSuccess,
38
+ }) => {
39
+ const [screen, setScreen] = useState<number>(1);
40
+ const [navigation, setNavigation] = useState<any>();
41
+ const [options, setOptions] = useState<ArgsType>();
42
+ const [callbackView, setCallbackView] = useState<string>('');
43
+
44
+ const onLiveness3DError = (error: onErrorType) => {
45
+ onError(error);
46
+ };
47
+
48
+ const onLiveness3DSuccess = (result: onSuccessType) => {
49
+ onSuccess(result);
50
+ };
51
+
52
+ function onBack() {
53
+ switch (screen) {
54
+ case SCREEN.INSTRUCTION_VIEW:
55
+ onLiveness3DError({ code: '0', message: 'RESULT_CANCELED' });
56
+ break;
57
+ case SCREEN.PERMISSION_VIEW:
58
+ setScreen(1);
59
+ break;
60
+ }
61
+ }
62
+
63
+ function startLiveness() {
64
+ if (options) {
65
+ startLiveness3d(options)
66
+ .then((result) => {
67
+ {
68
+ if (Platform.OS == 'android') {
69
+ //@ts-ignore
70
+ onSuccess(JSON.parse(result) as onSuccessType);
71
+ } else {
72
+ onSuccess(result as onSuccessType);
73
+ }
74
+ }
75
+ })
76
+ .catch((error) => {
77
+ onError(error as onErrorType);
78
+ });
79
+ }
80
+ }
81
+ function onAskPermission() {
82
+ askPermission().then((result) => {
83
+ result === true && startLiveness();
84
+ result === false && setScreen(1);
85
+ });
86
+ }
87
+
88
+ const contextValue: Liveness3DContextType = {
89
+ screen,
90
+ setScreen,
91
+ navigation,
92
+ setNavigation,
93
+ onLiveness3DError,
94
+ onLiveness3DSuccess,
95
+ onBack,
96
+ options,
97
+ setOptions,
98
+ startLiveness,
99
+ onAskPermission,
100
+ callbackView,
101
+ setCallbackView,
102
+ };
103
+
104
+ return (
105
+ //@ts-ignore
106
+ <Liveness3DContext.Provider value={contextValue}>
107
+ {children}
108
+ </Liveness3DContext.Provider>
109
+ );
110
+ };
111
+
112
+ export const useLiveness3DContext = (): Liveness3DContextType => {
113
+ const context = useContext(Liveness3DContext);
114
+ if (!context) {
115
+ throw new Error(
116
+ 'useLiveness3DContext must be used within a Liveness3DProvider'
117
+ );
118
+ }
119
+ return context;
120
+ };
121
+
122
+ export default Liveness3DContext;
@@ -0,0 +1,24 @@
1
+ import React, { useEffect, type FC } from 'react';
2
+ import { useLiveness3DContext } from '../context/Liveness3DContext';
3
+ import type { Liveness3DHelperInterface } from '../interfaces/Liveness3DHelper';
4
+
5
+ export const Liveness3DHelper: FC<Liveness3DHelperInterface> = ({
6
+ children,
7
+ options,
8
+ onError,
9
+ }) => {
10
+ const { setNavigation, setOptions, setCallbackView } = useLiveness3DContext();
11
+
12
+ useEffect(() => {
13
+ if (
14
+ options.appkey === null ||
15
+ options.appkey === undefined ||
16
+ options.appkey === ''
17
+ ) {
18
+ onError({ code: '0', message: 'invalidAppKey' });
19
+ }
20
+ setOptions(options);
21
+ }, [options, onError, setNavigation, setOptions, setCallbackView]);
22
+
23
+ return <>{children}</>;
24
+ };
package/src/index.tsx CHANGED
@@ -1,8 +1,15 @@
1
- import React, { FC, useEffect, useState } from 'react';
2
- import { NativeModules, Platform, PermissionsAndroid } from 'react-native';
1
+ import React, { FC } from 'react';
2
+ import { NativeModules, Platform } from 'react-native';
3
3
  import type { ArgsType, LoadingType } from './@types/ArgsType';
4
4
  import InstructionsView from './screens/Liveness3D/InstructionsView';
5
5
  import PermissionView from './screens/PermissionView';
6
+ import type { onErrorType, onSuccessType } from './@types/ResultType';
7
+ import {
8
+ Liveness3DProvider,
9
+ SCREEN,
10
+ useLiveness3DContext,
11
+ } from './context/Liveness3DContext';
12
+ import { Liveness3DHelper } from './helpers/Liveness3DHelper';
6
13
 
7
14
  const LINKING_ERROR =
8
15
  `The package '@oiti/rn-liveness3d' doesn't seem to be linked. Make sure: \n\n` +
@@ -10,12 +17,7 @@ const LINKING_ERROR =
10
17
  '- You rebuilt the app after installing the package\n' +
11
18
  '- You are not using Expo Go\n';
12
19
 
13
- const SCREEN = Object.freeze({
14
- INSTRUCTION_VIEW: 1,
15
- PERMISSION_VIEW: 2,
16
- } as const);
17
-
18
- const RnLiveness3d = NativeModules.RnLiveness3d
20
+ export const RnLiveness3d = NativeModules.RnLiveness3d
19
21
  ? NativeModules.RnLiveness3d
20
22
  : new Proxy(
21
23
  {},
@@ -28,49 +30,35 @@ const RnLiveness3d = NativeModules.RnLiveness3d
28
30
 
29
31
  export function startLiveness3d(
30
32
  options: ArgsType,
31
- loading?: any
32
- ): Promise<any> {
33
+ loading?: LoadingType
34
+ ): Promise<onErrorType | onSuccessType> {
33
35
  let args: ArgsType = {
34
36
  appkey: options?.appkey === undefined ? '' : options?.appkey,
37
+ ticket: options?.ticket,
35
38
  environment:
36
- options?.environment === undefined ? '.HML' : options?.environment,
37
- baseUrl: options?.baseUrl === undefined ? '' : options?.baseUrl,
38
- apparence: {
39
- backgroundColor:
40
- options?.apparence?.backgroundColor === ''
41
- ? '#1E1E1E'
42
- : options?.apparence?.backgroundColor,
43
- loadingColor:
44
- options?.apparence?.loadingColor === ''
45
- ? '#05D758'
46
- : options?.apparence?.loadingColor,
47
- },
48
- liveness3Dtext: options.liveness3Dtext || [],
39
+ options?.environment === undefined ? 'HML' : options?.environment,
40
+ liveness3Dtext: options?.liveness3Dtext || {},
41
+ theme: options?.theme || {},
42
+ fonts: options?.fonts || {},
49
43
  loading: loading,
50
44
  };
51
45
 
52
46
  if (Platform.OS === 'android') {
53
47
  return RnLiveness3d.startliveness3d(
54
48
  args.appkey,
55
- loading?.type,
56
- loading?.size * 200,
57
- loading?.backgroundColor,
58
- loading?.loadingColor
49
+ args.ticket,
50
+ loading?.type ? loading?.type : 'default',
51
+ loading?.size ? loading?.size * 200 : 1 * 200,
52
+ loading?.backgroundColor ? loading?.backgroundColor : '#333333',
53
+ loading?.loadingColor ? loading?.loadingColor : '#05D758',
54
+ args?.theme,
55
+ args?.fonts,
56
+ args?.liveness3Dtext
59
57
  );
60
58
  }
61
-
62
59
  return RnLiveness3d.startliveness3d(args);
63
60
  }
64
61
 
65
- export function logEvent3D(name: string, appkey: string): Promise<any> {
66
- if (Platform.OS === 'ios') {
67
- return RnLiveness3d.logevent({ event: name, appkey: appkey });
68
- } else {
69
- console.log(name, appkey);
70
- return RnLiveness3d.logevent(name, appkey);
71
- }
72
- }
73
-
74
62
  export function checkIosPermission(): Promise<any> {
75
63
  return RnLiveness3d.checkiospermission({ p: 'granted' });
76
64
  }
@@ -78,52 +66,74 @@ export function checkIosPermissionGranted(): Promise<any> {
78
66
  return RnLiveness3d.checkpermissiongranted({ p: 'granted' });
79
67
  }
80
68
 
81
- const PERMISSIONS_REQUEST: any = PermissionsAndroid.PERMISSIONS.CAMERA;
69
+ export function checkcamerapermissionAndroid(): Promise<any> {
70
+ return RnLiveness3d.checkcamerapermission();
71
+ }
72
+ export function askcamerapermissionAndroid(): Promise<any> {
73
+ return RnLiveness3d.askcamerapermission();
74
+ }
82
75
 
83
- const requestCameraPermission = async (
76
+ export const requestCameraPermission = async (
84
77
  options: ArgsType,
78
+ onSuccess: (result: onSuccessType) => void,
79
+ onError: (error: onErrorType) => void,
85
80
  loading?: LoadingType
86
81
  ) => {
87
82
  if (Platform.OS === 'ios') {
88
- checkIosPermission().then((result) => {
89
- if (result === 'true') {
90
- return RnLiveness3d.startliveness3d(options);
83
+ checkIosPermission().then(async (result) => {
84
+ if (result === true) {
85
+ await startLiveness3d(options, loading)
86
+ .then((result) => {
87
+ if (Platform.OS == 'android') {
88
+ //@ts-ignore
89
+ onSuccess(JSON.parse(result) as onSuccessType);
90
+ } else {
91
+ onSuccess(result as onSuccessType);
92
+ }
93
+ })
94
+ .catch((error) => onError(error as onErrorType));
91
95
  }
92
- if (result === 'false') {
96
+ if (result === false) {
93
97
  return;
94
98
  }
95
99
  });
96
100
  }
97
- try {
98
- const granted = await PermissionsAndroid.request(PERMISSIONS_REQUEST, {
99
- title: '',
100
- message: 'Precisamos acessar sua câmera',
101
- buttonNeutral: 'Ver Depois',
102
- buttonNegative: 'Cancelar',
103
- buttonPositive: 'OK',
104
- });
105
101
 
106
- if (granted === PermissionsAndroid.RESULTS.GRANTED) {
107
- startLiveness3d(options, loading).then((result) => console.log(result));
108
- } else {
109
- console.log('Camera permission denied');
102
+ if (Platform.OS === 'android') {
103
+ try {
104
+ await askcamerapermissionAndroid().then(async (res) => {
105
+ if (res === true) {
106
+ await startLiveness3d(options, loading)
107
+ .then((result) => {
108
+ if (Platform.OS == 'android') {
109
+ //@ts-ignore
110
+ onSuccess(JSON.parse(result) as onSuccessType);
111
+ } else {
112
+ onSuccess(result as onSuccessType);
113
+ }
114
+ })
115
+ .catch((error) => onError(error as onErrorType));
116
+ } else {
117
+ console.log('Camera permission denied');
118
+ }
119
+ });
120
+ } catch (err) {
121
+ console.warn(err);
110
122
  }
111
- } catch (err) {
112
- console.warn(err);
113
123
  }
114
124
  };
115
125
 
116
126
  async function checkPermission(): Promise<boolean> {
117
127
  if (Platform.OS === 'ios') {
118
128
  const grantediso = await checkIosPermissionGranted();
119
- if (grantediso === 'true') {
129
+ if (grantediso === true) {
120
130
  return true;
121
131
  }
122
- if (grantediso === 'false') {
132
+ if (grantediso === false) {
123
133
  return false;
124
134
  }
125
135
  }
126
- const granted = await PermissionsAndroid.check(PERMISSIONS_REQUEST);
136
+ const granted = await checkcamerapermissionAndroid();
127
137
  if (granted) {
128
138
  return true;
129
139
  } else {
@@ -136,19 +146,33 @@ export function Liveness3dView({
136
146
  CustomPermissionView,
137
147
  options,
138
148
  loading,
149
+ onSuccess,
150
+ onError,
151
+ onBack,
139
152
  }: {
140
- CustomInstructionView: FC;
141
- CustomPermissionView: FC;
153
+ CustomInstructionView?: FC;
154
+ CustomPermissionView?: FC;
142
155
  options: ArgsType;
143
156
  loading: LoadingType;
157
+ onSuccess: (result: onSuccessType) => void;
158
+ onError: (error: onErrorType) => void;
159
+ onBack: () => void;
144
160
  }) {
145
161
  return (
146
- <GetIntructionView
147
- CustomInstructionView={CustomInstructionView}
148
- CustomPermissionView={CustomPermissionView}
149
- options={options}
150
- loading={loading}
151
- />
162
+ //@ts-ignore
163
+ <Liveness3DProvider onError={onError} onSuccess={onSuccess}>
164
+ <Liveness3DHelper options={options} onError={onError}>
165
+ <GetIntructionView
166
+ CustomInstructionView={CustomInstructionView}
167
+ CustomPermissionView={CustomPermissionView}
168
+ options={options}
169
+ loading={loading}
170
+ onSuccess={onSuccess}
171
+ onError={onError}
172
+ onBack={onBack}
173
+ />
174
+ </Liveness3DHelper>
175
+ </Liveness3DProvider>
152
176
  );
153
177
  }
154
178
 
@@ -157,18 +181,24 @@ export function GetIntructionView({
157
181
  CustomPermissionView,
158
182
  options,
159
183
  loading,
184
+ onSuccess,
185
+ onError,
186
+ onBack,
160
187
  }: {
161
- CustomInstructionView: FC;
162
- CustomPermissionView: FC;
188
+ CustomInstructionView?: FC;
189
+ CustomPermissionView?: FC;
163
190
  options: ArgsType;
164
191
  loading: LoadingType;
192
+ onSuccess: (result: onSuccessType) => void;
193
+ onError: (error: onErrorType) => void;
194
+ onBack: () => void;
165
195
  }) {
166
- const [screen, setScreen] = useState(1);
196
+ const { setScreen, screen } = useLiveness3DContext();
167
197
 
168
- function onBack() {
198
+ function onBackScreen() {
169
199
  switch (screen) {
170
200
  case SCREEN.INSTRUCTION_VIEW:
171
- setScreen(1);
201
+ onBack();
172
202
  break;
173
203
  case SCREEN.PERMISSION_VIEW:
174
204
  setScreen(1);
@@ -177,43 +207,46 @@ export function GetIntructionView({
177
207
  }
178
208
  async function verifyPermission() {
179
209
  if (screen === 1) {
180
- logEvent3D('ACTION_L3FT_instructionContinue', options.appkey);
181
210
  if ((await checkPermission()) === true) {
182
- startLiveness3d(options, loading).then((result) => console.log(result));
211
+ startLiveness3d(options, loading)
212
+ .then((result) => {
213
+ if (Platform.OS == 'android') {
214
+ //@ts-ignore
215
+ onSuccess(JSON.parse(result) as onSuccessType);
216
+ } else {
217
+ onSuccess(result as onSuccessType);
218
+ }
219
+ })
220
+ .catch((error) => onError(error as onErrorType));
183
221
  } else {
184
222
  setScreen(2);
185
223
  }
186
224
  }
187
225
  if (screen === 2) {
188
- logEvent3D('ACTION_L3FT_permissionVerify', options.appkey);
189
- await requestCameraPermission(options);
226
+ await requestCameraPermission(options, onSuccess, onError);
190
227
  setScreen(1);
191
228
  }
192
229
  }
193
- useEffect(() => {
194
- if (screen === 1) {
195
- logEvent3D('STATE_L3FT_instructionView', options.appkey);
196
- }
197
- if (screen === 2) {
198
- logEvent3D('STATE_L3FT_permissionView', options.appkey);
199
- }
200
- });
201
230
 
202
231
  return (
203
232
  <>
204
233
  {screen === 1 &&
205
234
  (!CustomInstructionView ? (
206
- <InstructionsView onVerify={verifyPermission} onBack={onBack} />
235
+ <InstructionsView onVerify={verifyPermission} onBack={onBackScreen} />
207
236
  ) : (
208
237
  CustomInstructionView
209
238
  ))}
210
239
 
211
240
  {screen === 2 &&
212
241
  (!CustomPermissionView ? (
213
- <PermissionView onVerify={verifyPermission} onBack={onBack} />
242
+ <PermissionView onVerify={verifyPermission} onBack={onBackScreen} />
214
243
  ) : (
215
244
  CustomPermissionView
216
245
  ))}
217
246
  </>
218
247
  );
219
248
  }
249
+
250
+ export { ContinueButton } from './actions/ContinueButton';
251
+ export { PermissionButton } from './actions/PermissionButton';
252
+ export { BackButton } from './actions/BackButton';
@@ -0,0 +1,7 @@
1
+ import { onErrorType } from '../@types/ResultType';
2
+ import { ArgsType } from '../@types/ArgsType';
3
+
4
+ export interface Liveness3DHelperInterface {
5
+ options: ArgsType;
6
+ onError: (error: onErrorType) => void;
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { TouchableOpacityProps } from 'react-native';
3
+
4
+ export interface OitiBackButtonInterface extends TouchableOpacityProps {
5
+ children: ReactNode;
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { TouchableOpacityProps } from 'react-native';
3
+
4
+ export interface OitiContinueButtonInterface extends TouchableOpacityProps {
5
+ children: ReactNode;
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { TouchableOpacityProps } from 'react-native';
3
+
4
+ export interface OitiPermissionButtonInterface extends TouchableOpacityProps {
5
+ children: ReactNode;
6
+ }
@@ -25,13 +25,13 @@ export default function InstructionsView({
25
25
  }) {
26
26
  return (
27
27
  <View style={styles.container}>
28
+ <TouchableOpacity onPress={() => onBack()} style={styles.navigationBar}>
29
+ <Image
30
+ source={require('../../assets/images/left-arrow.png')}
31
+ style={styles.leftArrow}
32
+ />
33
+ </TouchableOpacity>
28
34
  <View style={styles.boxImg}>
29
- <TouchableOpacity onPress={() => onBack()} style={styles.navigationBar}>
30
- <Image
31
- source={require('../../assets/images/left-arrow.png')}
32
- style={styles.leftArrow}
33
- />
34
- </TouchableOpacity>
35
35
  <View style={styles.imgContainer}>
36
36
  <Image
37
37
  source={require('../../assets/images/img_face.png')}
@@ -193,8 +193,8 @@ const styles = StyleSheet.create({
193
193
  leftArrow: {
194
194
  marginTop: normalize(70, scaleH),
195
195
  marginLeft: 20,
196
- width: 25,
197
- height: 25,
196
+ width: normalize(25, scaleW),
197
+ height: normalize(35, scaleH),
198
198
  },
199
199
  imgFace: {
200
200
  height: '100%',
@@ -0,0 +1,12 @@
1
+ import { verifyPermission } from './permissions';
2
+
3
+ export const continueButton = async (): Promise<boolean> => {
4
+ return verifyPermission()
5
+ .then((result) => {
6
+ return result;
7
+ })
8
+ .catch((error) => {
9
+ console.error(error);
10
+ return false;
11
+ });
12
+ };
@@ -0,0 +1,30 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ export const RnLiveness3d = NativeModules.RnLiveness3d
4
+ ? NativeModules.RnLiveness3d
5
+ : new Proxy(
6
+ {},
7
+ {
8
+ get() {
9
+ throw new Error(LINKING_ERROR);
10
+ },
11
+ }
12
+ );
13
+
14
+ const LINKING_ERROR =
15
+ `The package '@oiti/rn-liveness3d' doesn't seem to be linked. Make sure: \n\n` +
16
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
17
+ '- You rebuilt the app after installing the package\n' +
18
+ '- You are not using Expo Go\n';
19
+
20
+ export function verifyPermission(): Promise<boolean> {
21
+ return Platform.OS === 'android'
22
+ ? RnLiveness3d.checkcamerapermission()
23
+ : RnLiveness3d.checkiospermission({ p: 'granted' });
24
+ }
25
+
26
+ export function askPermission(): Promise<boolean> {
27
+ return Platform.OS === 'android'
28
+ ? RnLiveness3d.askcamerapermission()
29
+ : RnLiveness3d.checkpermissiongranted({ p: 'granted' });
30
+ }
@@ -0,0 +1,4 @@
1
+ export const SCREEN = Object.freeze({
2
+ INSTRUCTION_VIEW: 1,
3
+ PERMISSION_VIEW: 2,
4
+ } as const);