react-native-timacare 3.3.11 → 3.3.12
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/lib/commonjs/RNTimacare.js +1 -1
- package/lib/commonjs/RNTimacare.js.flow +2 -2
- package/lib/commonjs/RNTimacare.js.map +1 -1
- package/lib/commonjs/screens/camera/CCCDCameraScreen.js +1 -1
- package/lib/commonjs/screens/camera/CCCDCameraScreen.js.flow +248 -112
- package/lib/commonjs/screens/camera/CCCDCameraScreen.js.map +1 -1
- package/lib/commonjs/screens/nationalID/index.js +1 -1
- package/lib/commonjs/screens/nationalID/index.js.flow +4 -2
- package/lib/commonjs/screens/nationalID/index.js.map +1 -1
- package/lib/commonjs/screens/nationalIDBack/index.js +1 -1
- package/lib/commonjs/screens/nationalIDBack/index.js.flow +3 -1
- package/lib/commonjs/screens/nationalIDBack/index.js.map +1 -1
- package/lib/commonjs/screens/uploadVideo/index.js +1 -1
- package/lib/commonjs/screens/uploadVideo/index.js.flow +109 -61
- package/lib/commonjs/screens/uploadVideo/index.js.map +1 -1
- package/lib/commonjs/screens/uploadVideo/videoStore.js +1 -1
- package/lib/commonjs/screens/uploadVideo/videoStore.js.flow +4 -4
- package/lib/commonjs/screens/uploadVideo/videoStore.js.map +1 -1
- package/lib/module/RNTimacare.js +1 -1
- package/lib/module/RNTimacare.js.map +1 -1
- package/lib/module/screens/camera/CCCDCameraScreen.js +1 -1
- package/lib/module/screens/camera/CCCDCameraScreen.js.map +1 -1
- package/lib/module/screens/nationalID/index.js +1 -1
- package/lib/module/screens/nationalID/index.js.map +1 -1
- package/lib/module/screens/nationalIDBack/index.js +1 -1
- package/lib/module/screens/nationalIDBack/index.js.map +1 -1
- package/lib/module/screens/uploadVideo/index.js +1 -1
- package/lib/module/screens/uploadVideo/index.js.map +1 -1
- package/lib/module/screens/uploadVideo/videoStore.js +1 -1
- package/lib/module/screens/uploadVideo/videoStore.js.map +1 -1
- package/lib/typescript/RNTimacare.d.ts +1 -1
- package/lib/typescript/RNTimacare.d.ts.map +1 -1
- package/lib/typescript/screens/camera/CCCDCameraScreen.d.ts.map +1 -1
- package/lib/typescript/screens/nationalID/index.d.ts.map +1 -1
- package/lib/typescript/screens/nationalIDBack/index.d.ts.map +1 -1
- package/lib/typescript/screens/uploadVideo/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/RNTimacare.tsx +2 -2
- package/src/screens/camera/CCCDCameraScreen.tsx +248 -112
- package/src/screens/nationalID/index.tsx +4 -2
- package/src/screens/nationalIDBack/index.tsx +3 -1
- package/src/screens/uploadVideo/index.tsx +109 -61
- package/src/screens/uploadVideo/videoStore.tsx +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
|
-
import { observer
|
|
3
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { observer } from 'mobx-react-lite';
|
|
3
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import {
|
|
5
5
|
Alert,
|
|
6
6
|
Platform,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { formatDDMMYYY, formatMoney } from '../../utils';
|
|
13
13
|
import { RNCamera } from 'react-native-camera';
|
|
14
14
|
import MButton from '../../components/MButton';
|
|
15
|
-
import {
|
|
15
|
+
import { IconPause, IconPlay } from '../../assets/icons';
|
|
16
16
|
import { MText } from '../../components/MText';
|
|
17
17
|
import { useNavigation } from '@react-navigation/native';
|
|
18
18
|
import videoStore from './videoStore';
|
|
@@ -21,89 +21,137 @@ import {
|
|
|
21
21
|
requestMultiple,
|
|
22
22
|
openSettings,
|
|
23
23
|
PERMISSIONS,
|
|
24
|
-
request,
|
|
25
24
|
RESULTS,
|
|
26
25
|
} from 'react-native-permissions';
|
|
27
26
|
import Loading from '../../components/Loading';
|
|
28
27
|
import MHeader from '../../components/MHeader';
|
|
29
28
|
|
|
29
|
+
const COUNTDOWN_SECONDS = 3;
|
|
30
|
+
|
|
31
|
+
const getCameraPermissions = () =>
|
|
32
|
+
Platform.OS === 'ios'
|
|
33
|
+
? [PERMISSIONS.IOS.CAMERA, PERMISSIONS.IOS.MICROPHONE]
|
|
34
|
+
: [PERMISSIONS.ANDROID.CAMERA, PERMISSIONS.ANDROID.RECORD_AUDIO];
|
|
35
|
+
|
|
30
36
|
export const Video = observer(function Video(props: any) {
|
|
31
37
|
const navigation = useNavigation();
|
|
32
38
|
const camera = useRef(null);
|
|
33
|
-
const [count, setCount] = useState(
|
|
34
|
-
const
|
|
35
|
-
const [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const content =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const requestPermissions = () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
)
|
|
39
|
+
const [count, setCount] = useState(COUNTDOWN_SECONDS);
|
|
40
|
+
const [isRecording, setIsRecording] = useState(false);
|
|
41
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
42
|
+
|
|
43
|
+
const loan = props?.route?.params?.loan;
|
|
44
|
+
const content = useMemo(() => {
|
|
45
|
+
return `Hôm nay ngày ${formatDDMMYYY(new Date())} tôi tên là ${
|
|
46
|
+
loan?.fullname || ''
|
|
47
|
+
} có thực hiện khoản vay tại Tima với số tiền là ${formatMoney(
|
|
48
|
+
loan?.loanAmount || 0
|
|
49
|
+
)}`;
|
|
50
|
+
}, [loan?.fullname, loan?.loanAmount]);
|
|
51
|
+
|
|
52
|
+
const requestPermissions = async () => {
|
|
53
|
+
const permissions = getCameraPermissions();
|
|
54
|
+
const statuses = await checkMultiple(permissions);
|
|
55
|
+
const toRequest = permissions.filter(
|
|
56
|
+
(permission) => statuses[permission] !== RESULTS.GRANTED
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (toRequest.length === 0) return true;
|
|
60
|
+
|
|
61
|
+
const requested = await requestMultiple(toRequest);
|
|
62
|
+
const values = Object.values(requested);
|
|
63
|
+
const allGranted = values.every((status) => status === RESULTS.GRANTED);
|
|
64
|
+
const anyBlocked = values.some((status) => status === RESULTS.BLOCKED);
|
|
65
|
+
|
|
66
|
+
if (!allGranted) {
|
|
67
|
+
Alert.alert(
|
|
68
|
+
'Thông báo',
|
|
69
|
+
anyBlocked
|
|
70
|
+
? 'Vui lòng bật quyền Camera và Micro trong Cài đặt để tiếp tục.'
|
|
71
|
+
: 'Vui lòng cấp quyền Camera và Micro để tiếp tục.',
|
|
72
|
+
anyBlocked
|
|
73
|
+
? [
|
|
74
|
+
{ text: 'Huỷ' },
|
|
75
|
+
{
|
|
76
|
+
text: 'Mở cài đặt',
|
|
77
|
+
onPress: () => openSettings(),
|
|
78
|
+
},
|
|
79
|
+
]
|
|
80
|
+
: [{ text: 'OK' }]
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return allGranted;
|
|
52
85
|
};
|
|
53
86
|
|
|
54
87
|
useEffect(() => {
|
|
55
88
|
requestPermissions();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
setCount(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
89
|
+
setCount(COUNTDOWN_SECONDS);
|
|
90
|
+
const id = setInterval(() => {
|
|
91
|
+
setCount((prev) => {
|
|
92
|
+
if (prev <= 1) {
|
|
93
|
+
clearInterval(id);
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
return prev - 1;
|
|
97
|
+
});
|
|
62
98
|
}, 1000);
|
|
99
|
+
return () => clearInterval(id);
|
|
63
100
|
}, []);
|
|
64
101
|
|
|
65
102
|
const stopRecording = () => {
|
|
103
|
+
if (!camera.current) return;
|
|
66
104
|
camera.current.stopRecording();
|
|
67
105
|
setIsRecording(false);
|
|
68
|
-
setIsLoading(true);
|
|
69
106
|
};
|
|
70
107
|
|
|
71
108
|
const startVideo = async () => {
|
|
72
|
-
if (!camera) {
|
|
109
|
+
if (!camera.current || isLoading || isRecording || count > 0) {
|
|
73
110
|
return;
|
|
74
111
|
}
|
|
112
|
+
const hasPermission = await requestPermissions();
|
|
113
|
+
if (!hasPermission) return;
|
|
114
|
+
|
|
75
115
|
setIsRecording(true);
|
|
76
|
-
|
|
77
|
-
|
|
116
|
+
try {
|
|
117
|
+
const data = await camera.current.recordAsync({
|
|
78
118
|
quality: RNCamera.Constants.VideoQuality['480p'],
|
|
79
119
|
videoBitrate: 1500000,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
120
|
+
...(Platform.OS === 'ios'
|
|
121
|
+
? { codec: RNCamera.Constants.VideoCodec.H264 }
|
|
122
|
+
: {}),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
setIsLoading(true);
|
|
126
|
+
const formData = new FormData();
|
|
127
|
+
formData.append('video', {
|
|
128
|
+
name: data.uri.split(/[\\/]/).pop(),
|
|
129
|
+
uri: data.uri,
|
|
130
|
+
type: 'video/*',
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
videoStore.uploadVideo(
|
|
134
|
+
loan?.id,
|
|
135
|
+
formData,
|
|
136
|
+
() => {
|
|
137
|
+
setIsLoading(false);
|
|
138
|
+
Alert.alert('Thông báo', 'Tải video lên thành công', [
|
|
139
|
+
{
|
|
140
|
+
text: 'Ok',
|
|
141
|
+
onPress: () => navigation.goBack(),
|
|
142
|
+
},
|
|
143
|
+
]);
|
|
144
|
+
},
|
|
145
|
+
() => {
|
|
146
|
+
setIsLoading(false);
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
setIsRecording(false);
|
|
151
|
+
setIsLoading(false);
|
|
152
|
+
console.error(err);
|
|
153
|
+
Alert.alert('Thông báo', 'Không thể quay video. Vui lòng thử lại.');
|
|
154
|
+
}
|
|
107
155
|
};
|
|
108
156
|
|
|
109
157
|
return (
|
|
@@ -143,7 +191,7 @@ export const Video = observer(function Video(props: any) {
|
|
|
143
191
|
<RNCamera
|
|
144
192
|
ref={camera}
|
|
145
193
|
style={styles.preview}
|
|
146
|
-
type=
|
|
194
|
+
type={RNCamera.Constants.Type.front}
|
|
147
195
|
permissionDialogTitle={'Permission to use camera'}
|
|
148
196
|
permissionDialogMessage={
|
|
149
197
|
'We need your permission to use your camera phone'
|
|
@@ -8,11 +8,9 @@ class Store {
|
|
|
8
8
|
|
|
9
9
|
@action
|
|
10
10
|
async uploadVideo(loanID, body, onSuccess?, onError) {
|
|
11
|
+
this.isLoading = true;
|
|
11
12
|
try {
|
|
12
|
-
this.isLoading = true;
|
|
13
13
|
const response = await Api.getInstance().uploadVideo(loanID, body);
|
|
14
|
-
console.log(response);
|
|
15
|
-
this.isLoading = false;
|
|
16
14
|
if (response.kind === 'ok') {
|
|
17
15
|
if (response.data.meta.errorCode === 200) {
|
|
18
16
|
if (onSuccess) onSuccess();
|
|
@@ -21,13 +19,15 @@ class Store {
|
|
|
21
19
|
if (onError) onError();
|
|
22
20
|
}
|
|
23
21
|
} else {
|
|
24
|
-
this.isLoading = false;
|
|
25
22
|
Alert.alert('Thông báo', 'Lỗi đã xảy ra. Vui lòng thực hiện lại');
|
|
26
23
|
if (onError) onError();
|
|
27
24
|
}
|
|
28
25
|
} catch (error) {
|
|
29
26
|
console.log(error);
|
|
27
|
+
Alert.alert('Thông báo', 'Lỗi đã xảy ra. Vui lòng thực hiện lại');
|
|
30
28
|
if (onError) onError();
|
|
29
|
+
} finally {
|
|
30
|
+
this.isLoading = false;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|