@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.
- package/README.md +33 -237
- package/android/build.gradle +4 -18
- package/android/settings.gradle +2 -2
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/br/com/oiti/rnliveness3d/RnLiveness3dModule.kt +198 -132
- package/android/src/main/java/br/com/oiti/rnliveness3d/theme/Liveness3DFonts.kt +44 -0
- package/android/src/main/java/br/com/oiti/rnliveness3d/theme/Liveness3DText.kt +68 -0
- package/android/src/main/java/br/com/oiti/rnliveness3d/theme/Liveness3DTheme.kt +147 -0
- package/ios/Podfile +2 -1
- package/ios/Pods/Manifest.lock +23 -19
- package/ios/RnLiveness3d.m +8 -3
- package/ios/RnLiveness3d.swift +198 -114
- package/lib/commonjs/@types/ArgsType.js +4 -0
- package/lib/commonjs/@types/FontsType.js +2 -0
- package/lib/commonjs/@types/FontsType.js.map +1 -0
- package/lib/commonjs/@types/ResultType.js +2 -0
- package/lib/commonjs/@types/ResultType.js.map +1 -0
- package/lib/commonjs/@types/ResultTypes.js +6 -0
- package/lib/commonjs/@types/ResultTypes.js.map +1 -0
- package/lib/commonjs/@types/TextsType.js +2 -0
- package/lib/commonjs/@types/TextsType.js.map +1 -0
- package/lib/commonjs/@types/ThemeType.js +2 -0
- package/lib/commonjs/@types/ThemeType.js.map +1 -0
- package/lib/commonjs/actions/BackButton.js +35 -0
- package/lib/commonjs/actions/BackButton.js.map +1 -0
- package/lib/commonjs/actions/ContinueButton.js +43 -0
- package/lib/commonjs/actions/ContinueButton.js.map +1 -0
- package/lib/commonjs/actions/PermissionButton.js +35 -0
- package/lib/commonjs/actions/PermissionButton.js.map +1 -0
- package/lib/commonjs/context/Liveness3DContext.js +104 -0
- package/lib/commonjs/context/Liveness3DContext.js.map +1 -0
- package/lib/commonjs/helpers/Liveness3DHelper.js +34 -0
- package/lib/commonjs/helpers/Liveness3DHelper.js.map +1 -0
- package/lib/commonjs/index.js +121 -78
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/interfaces/Liveness3DHelper.js +6 -0
- package/lib/commonjs/interfaces/Liveness3DHelper.js.map +1 -0
- package/lib/commonjs/interfaces/OitiBackButtonInterface.js +6 -0
- package/lib/commonjs/interfaces/OitiBackButtonInterface.js.map +1 -0
- package/lib/commonjs/interfaces/OitiContinueButton.js +6 -0
- package/lib/commonjs/interfaces/OitiContinueButton.js.map +1 -0
- package/lib/commonjs/interfaces/OitiPermissionButtonInterface.js +6 -0
- package/lib/commonjs/interfaces/OitiPermissionButtonInterface.js.map +1 -0
- package/lib/commonjs/screens/Liveness3D/InstructionsView.js +4 -4
- package/lib/commonjs/screens/Liveness3D/InstructionsView.js.map +1 -1
- package/lib/commonjs/utils/continueButton.js +17 -0
- package/lib/commonjs/utils/continueButton.js.map +1 -0
- package/lib/commonjs/utils/permissions.js +30 -0
- package/lib/commonjs/utils/permissions.js.map +1 -0
- package/lib/commonjs/utils/screenStore.js +12 -0
- package/lib/commonjs/utils/screenStore.js.map +1 -0
- package/lib/module/@types/ArgsType.js +1 -1
- package/lib/module/@types/FontsType.js +2 -0
- package/lib/module/@types/FontsType.js.map +1 -0
- package/lib/module/@types/ResultType.js +2 -0
- package/lib/module/@types/ResultType.js.map +1 -0
- package/lib/module/@types/ResultTypes.js +2 -0
- package/lib/module/@types/ResultTypes.js.map +1 -0
- package/lib/module/@types/TextsType.js +2 -0
- package/lib/module/@types/TextsType.js.map +1 -0
- package/lib/module/@types/ThemeType.js +2 -0
- package/lib/module/@types/ThemeType.js.map +1 -0
- package/lib/module/actions/BackButton.js +26 -0
- package/lib/module/actions/BackButton.js.map +1 -0
- package/lib/module/actions/ContinueButton.js +34 -0
- package/lib/module/actions/ContinueButton.js.map +1 -0
- package/lib/module/actions/PermissionButton.js +26 -0
- package/lib/module/actions/PermissionButton.js.map +1 -0
- package/lib/module/context/Liveness3DContext.js +92 -0
- package/lib/module/context/Liveness3DContext.js.map +1 -0
- package/lib/module/helpers/Liveness3DHelper.js +25 -0
- package/lib/module/helpers/Liveness3DHelper.js.map +1 -0
- package/lib/module/index.js +97 -75
- package/lib/module/index.js.map +1 -1
- package/lib/module/interfaces/Liveness3DHelper.js +2 -0
- package/lib/module/interfaces/Liveness3DHelper.js.map +1 -0
- package/lib/module/interfaces/OitiBackButtonInterface.js +2 -0
- package/lib/module/interfaces/OitiBackButtonInterface.js.map +1 -0
- package/lib/module/interfaces/OitiContinueButton.js +2 -0
- package/lib/module/interfaces/OitiContinueButton.js.map +1 -0
- package/lib/module/interfaces/OitiPermissionButtonInterface.js +2 -0
- package/lib/module/interfaces/OitiPermissionButtonInterface.js.map +1 -0
- package/lib/module/screens/Liveness3D/InstructionsView.js +4 -4
- package/lib/module/screens/Liveness3D/InstructionsView.js.map +1 -1
- package/lib/module/utils/continueButton.js +10 -0
- package/lib/module/utils/continueButton.js.map +1 -0
- package/lib/module/utils/permissions.js +21 -0
- package/lib/module/utils/permissions.js.map +1 -0
- package/lib/module/utils/screenStore.js +5 -0
- package/lib/module/utils/screenStore.js.map +1 -0
- package/lib/typescript/@types/ArgsType.d.ts +9 -9
- package/lib/typescript/@types/ArgsType.d.ts.map +1 -1
- package/lib/typescript/@types/FontsType.d.ts +12 -0
- package/lib/typescript/@types/FontsType.d.ts.map +1 -0
- package/lib/typescript/@types/ResultType.d.ts +13 -0
- package/lib/typescript/@types/ResultType.d.ts.map +1 -0
- package/lib/typescript/@types/ResultTypes.d.ts +6 -0
- package/lib/typescript/@types/ResultTypes.d.ts.map +1 -0
- package/lib/typescript/@types/TextsType.d.ts +36 -0
- package/lib/typescript/@types/TextsType.d.ts.map +1 -0
- package/lib/typescript/@types/ThemeType.d.ts +48 -0
- package/lib/typescript/@types/ThemeType.d.ts.map +1 -0
- package/lib/typescript/actions/BackButton.d.ts +4 -0
- package/lib/typescript/actions/BackButton.d.ts.map +1 -0
- package/lib/typescript/actions/ContinueButton.d.ts +4 -0
- package/lib/typescript/actions/ContinueButton.d.ts.map +1 -0
- package/lib/typescript/actions/PermissionButton.d.ts +4 -0
- package/lib/typescript/actions/PermissionButton.d.ts.map +1 -0
- package/lib/typescript/context/Liveness3DContext.d.ts +28 -0
- package/lib/typescript/context/Liveness3DContext.d.ts.map +1 -0
- package/lib/typescript/helpers/Liveness3DHelper.d.ts +4 -0
- package/lib/typescript/helpers/Liveness3DHelper.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +21 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/interfaces/Liveness3DHelper.d.ts +7 -0
- package/lib/typescript/interfaces/Liveness3DHelper.d.ts.map +1 -0
- package/lib/typescript/interfaces/OitiBackButtonInterface.d.ts +6 -0
- package/lib/typescript/interfaces/OitiBackButtonInterface.d.ts.map +1 -0
- package/lib/typescript/interfaces/OitiContinueButton.d.ts +6 -0
- package/lib/typescript/interfaces/OitiContinueButton.d.ts.map +1 -0
- package/lib/typescript/interfaces/OitiPermissionButtonInterface.d.ts +6 -0
- package/lib/typescript/interfaces/OitiPermissionButtonInterface.d.ts.map +1 -0
- package/lib/typescript/screens/Liveness3D/InstructionsView.d.ts +1 -0
- package/lib/typescript/screens/Liveness3D/InstructionsView.d.ts.map +1 -1
- package/lib/typescript/screens/PermissionView.d.ts +1 -0
- package/lib/typescript/screens/PermissionView.d.ts.map +1 -1
- package/lib/typescript/utils/continueButton.d.ts +2 -0
- package/lib/typescript/utils/continueButton.d.ts.map +1 -0
- package/lib/typescript/utils/permissions.d.ts +4 -0
- package/lib/typescript/utils/permissions.d.ts.map +1 -0
- package/lib/typescript/utils/screenStore.d.ts +5 -0
- package/lib/typescript/utils/screenStore.d.ts.map +1 -0
- package/oiti-rn-liveness3d.podspec +2 -1
- package/package.json +3 -6
- package/src/@types/ArgsType.ts +10 -10
- package/src/@types/FontsType.ts +22 -0
- package/src/@types/ResultType.ts +13 -0
- package/src/@types/ResultTypes.ts +6 -0
- package/src/@types/TextsType.ts +41 -0
- package/src/@types/ThemeType.ts +64 -0
- package/src/actions/BackButton.tsx +27 -0
- package/src/actions/ContinueButton.tsx +35 -0
- package/src/actions/PermissionButton.tsx +27 -0
- package/src/context/Liveness3DContext.tsx +122 -0
- package/src/helpers/Liveness3DHelper.tsx +24 -0
- package/src/index.tsx +120 -87
- package/src/interfaces/Liveness3DHelper.tsx +7 -0
- package/src/interfaces/OitiBackButtonInterface.tsx +6 -0
- package/src/interfaces/OitiContinueButton.tsx +6 -0
- package/src/interfaces/OitiPermissionButtonInterface.tsx +6 -0
- package/src/screens/Liveness3D/InstructionsView.tsx +8 -8
- package/src/utils/continueButton.tsx +12 -0
- package/src/utils/permissions.tsx +30 -0
- 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
|
|
2
|
-
import { NativeModules, Platform
|
|
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
|
|
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?:
|
|
32
|
-
): Promise<
|
|
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 ? '
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
56
|
-
loading?.
|
|
57
|
-
loading?.
|
|
58
|
-
loading?.
|
|
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
|
-
|
|
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 ===
|
|
90
|
-
|
|
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 ===
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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 ===
|
|
129
|
+
if (grantediso === true) {
|
|
120
130
|
return true;
|
|
121
131
|
}
|
|
122
|
-
if (grantediso ===
|
|
132
|
+
if (grantediso === false) {
|
|
123
133
|
return false;
|
|
124
134
|
}
|
|
125
135
|
}
|
|
126
|
-
const granted = await
|
|
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
|
|
141
|
-
CustomPermissionView
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
162
|
-
CustomPermissionView
|
|
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
|
|
196
|
+
const { setScreen, screen } = useLiveness3DContext();
|
|
167
197
|
|
|
168
|
-
function
|
|
198
|
+
function onBackScreen() {
|
|
169
199
|
switch (screen) {
|
|
170
200
|
case SCREEN.INSTRUCTION_VIEW:
|
|
171
|
-
|
|
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)
|
|
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
|
-
|
|
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={
|
|
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={
|
|
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';
|
|
@@ -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:
|
|
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
|
+
}
|