@fto-consult/expo-ui 8.24.0 → 8.24.2
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/babel.config.js +1 -1
- package/bin/create-app/dependencies.js +1 -0
- package/package.json +1 -2
- package/src/App.js +1 -0
- package/src/components/Barcode/Scanner/index.js +36 -45
- package/src/components/Barcode/Scanner/index.web.js +3 -1
- package/src/uuid/deps.js +1 -0
- package/src/uuid/deps.native.js +2 -0
- package/src/uuid/index.js +1 -0
package/babel.config.js
CHANGED
@@ -13,7 +13,7 @@ module.exports = function(api,opts) {
|
|
13
13
|
}
|
14
14
|
/*** par défaut, les variables d'environnements sont stockés dans le fichier .env situé à la racine du projet, référencée par la prop base */
|
15
15
|
const alias = require("./babel.config.alias")(options);
|
16
|
-
if(!isWeb){
|
16
|
+
if(false && !isWeb){
|
17
17
|
alias.uuid = path.resolve(__dirname,"src","uuid");
|
18
18
|
}
|
19
19
|
if(typeof options.aliasMutator =="function"){
|
@@ -6,6 +6,7 @@ module.exports = {
|
|
6
6
|
"@pchmn/expo-material3-theme": "^1.3.2",
|
7
7
|
"@react-native-community/netinfo": "11.1.0",
|
8
8
|
"@react-native/assets-registry": "^0.72.0",
|
9
|
+
"react-native-get-random-values": "~1.8.0",
|
9
10
|
"@react-navigation/native": "^6.1.9",
|
10
11
|
"@react-navigation/native-stack": "^6.9.17",
|
11
12
|
"@react-navigation/stack": "^6.3.20",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fto-consult/expo-ui",
|
3
|
-
"version": "8.24.
|
3
|
+
"version": "8.24.2",
|
4
4
|
"description": "Bibliothèque de composants UI Expo,react-native",
|
5
5
|
"scripts": {
|
6
6
|
"clear-npx-cache": "npx clear-npx-cache",
|
@@ -86,7 +86,6 @@
|
|
86
86
|
"react-native-mime-types": "^2.4.0",
|
87
87
|
"react-native-paper": "^5.12.3",
|
88
88
|
"react-native-paper-dates": "^0.21.8",
|
89
|
-
"react-native-uuid": "^2.0.1",
|
90
89
|
"react-native-web": "^0.19.10",
|
91
90
|
"react-virtuoso": "^4.6.3",
|
92
91
|
"readable-stream": "^4.5.2",
|
package/src/App.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useState, useEffect,useMemo } from '$react';
|
1
|
+
import React, { useState, useEffect,useMemo,useRef } from '$react';
|
2
2
|
import { View, StyleSheet} from 'react-native';
|
3
3
|
import { CameraView, Camera } from "expo-camera/next";
|
4
4
|
import theme from "$theme";
|
@@ -10,9 +10,9 @@ import Button from "$ecomponents/Button";
|
|
10
10
|
import Dialog from "$ecomponents/Dialog";
|
11
11
|
import {DialogProvider} from "$ecomponents/Form/FormData";
|
12
12
|
|
13
|
-
export const
|
14
|
-
export const
|
15
|
-
export const
|
13
|
+
export const CameraFacing = {back:"back",front:"front"};
|
14
|
+
export const FlashModes = {off:{code:"off",label:"Inactif"},on:{code:"on",label:"Actif"},auto:{code:"auto",label:"Automatique"}}
|
15
|
+
export const CameraSettingsFields = {
|
16
16
|
enableTorch : {
|
17
17
|
type : "switch",
|
18
18
|
label : "Allumer la torche",
|
@@ -24,32 +24,28 @@ export const cameraSetingsFields = {
|
|
24
24
|
label : "Flash",
|
25
25
|
type : "select",
|
26
26
|
required : true,
|
27
|
-
items :
|
28
|
-
defaultValue :
|
27
|
+
items : FlashModes,
|
28
|
+
defaultValue : FlashModes.auto.code,
|
29
29
|
},
|
30
30
|
}
|
31
31
|
|
32
32
|
/***@see : https://docs.expo.dev/versions/latest/sdk/bar-code-scanner/ */
|
33
|
-
export default function
|
33
|
+
export default function BarCodeScanner({onScan,onGrantAccess,testID,onDenyAccess,cameraProps,onCancel,dialogProps}) {
|
34
34
|
testID = defaultStr(testID,"RN_BarCodeScanner");
|
35
35
|
const [hasPermission, setHasPermission] = useState(null);
|
36
36
|
const [visible,setVisible] = useState(true);
|
37
37
|
dialogProps = Object.assign({},dialogProps);
|
38
38
|
cameraProps = Object.assign({},cameraProps);
|
39
|
-
const barCodeScannerSettings = defaultObj(cameraProps.barCodeScannerSettings);
|
40
39
|
const getFlashMode = ()=>{
|
41
40
|
let {flash} = cameraProps;
|
42
41
|
if(isNonNullString(flash)){
|
43
42
|
flash = flash.toLowerCase().trim();
|
44
|
-
if(
|
43
|
+
if(FlashModes[flash]) return FlashModes[flash].code;
|
45
44
|
}
|
46
|
-
return
|
47
|
-
}
|
48
|
-
const isTorchEnabled = ()=>{
|
49
|
-
return !!cameraProps.enableTorch;
|
45
|
+
return FlashModes.auto.code;
|
50
46
|
}
|
51
47
|
const [cameraSetting,setCameraSetting] = useState({
|
52
|
-
enableTorch :
|
48
|
+
enableTorch : !!cameraProps.enableTorch,
|
53
49
|
flash : getFlashMode(cameraProps.flash),
|
54
50
|
});
|
55
51
|
useEffect(()=>{
|
@@ -59,44 +55,31 @@ export default function App({onScan,onGrantAccess,testID,onDenyAccess,cameraProp
|
|
59
55
|
}
|
60
56
|
},[cameraProps.flash]);
|
61
57
|
useEffect(()=>{
|
62
|
-
const enableTorch =
|
58
|
+
const enableTorch = !!cameraProps.enableTorch;
|
63
59
|
if(enableTorch !== cameraSetting.enableTorch){
|
64
60
|
setCameraSetting({...cameraSetting,enableTorch});
|
65
61
|
}
|
66
|
-
},[cameraProps.enableTorch]);
|
62
|
+
},[!!cameraProps.enableTorch]);
|
67
63
|
const prevVisible = React.usePrevious(visible);
|
68
64
|
const cancelRef = React.useRef(false);
|
69
65
|
const cancel = ()=>{
|
70
66
|
cancelRef.current = true;
|
71
67
|
setVisible(false);
|
72
68
|
}
|
73
|
-
const
|
74
|
-
let {
|
69
|
+
const sFacing = useMemo(()=>{
|
70
|
+
let {facing} = cameraProps;
|
75
71
|
if(isNonNullString(facing)){
|
76
|
-
facing = facing.toLowerCase();
|
77
|
-
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if(isNonNullString(type)){
|
82
|
-
type = type.toLowerCase().trim();
|
83
|
-
} else type = cameraTypes.back;
|
84
|
-
if(!cameraTypes[type]){
|
85
|
-
type = cameraTypes.back;
|
86
|
-
}
|
87
|
-
return type;
|
88
|
-
}
|
89
|
-
const sType = useMemo(()=>{
|
90
|
-
return getCameraType();
|
91
|
-
},[cameraProps.type,cameraProps.facing]);
|
92
|
-
const [cameraType,setCameraType] = useState(sType);
|
72
|
+
facing = facing.trim().toLowerCase();
|
73
|
+
} else return CameraFacing.back;
|
74
|
+
return CameraFacing[facing] || CameraFacing.back;
|
75
|
+
},[cameraProps.facing]);
|
76
|
+
const [facing,setFacing] = useState(sFacing);
|
93
77
|
useEffect(()=>{
|
94
|
-
|
95
|
-
|
96
|
-
setCameraType(type);
|
78
|
+
if(sFacing !== facing){
|
79
|
+
setFacing(sFacing);
|
97
80
|
}
|
98
|
-
},
|
99
|
-
const isBack =
|
81
|
+
},[sFacing]);
|
82
|
+
const isBack = facing === CameraFacing.back;
|
100
83
|
useEffect(() => {
|
101
84
|
const getCameraPermissions = async () => {
|
102
85
|
const { status } = await Camera.requestCameraPermissionsAsync();
|
@@ -104,8 +87,12 @@ export default function App({onScan,onGrantAccess,testID,onDenyAccess,cameraProp
|
|
104
87
|
};
|
105
88
|
getCameraPermissions();
|
106
89
|
}, []);
|
107
|
-
|
90
|
+
//const torchEnabledRef = useRef(cameraSetting.enableTorch);
|
91
|
+
//const prevTorchEnabled = React.usePrevious(torchEnabledRef.current);
|
108
92
|
const handleBarCodeScanned = ({ type, data,...rest }) => {
|
93
|
+
if(cameraSetting.enableTorch){
|
94
|
+
setCameraSetting({...cameraSetting,enableTorch:false});
|
95
|
+
}
|
109
96
|
if(typeof onScan =="function"){
|
110
97
|
onScan({type,data,code:data,barCode:data,...rest});
|
111
98
|
}
|
@@ -134,7 +121,7 @@ export default function App({onScan,onGrantAccess,testID,onDenyAccess,cameraProp
|
|
134
121
|
icon : "camera-flip",
|
135
122
|
tooltip : `Cliquez pour basculer à la camera ${isBack ? "frontable":"arrière"}`,
|
136
123
|
onPress : ()=>{
|
137
|
-
|
124
|
+
setFacing(isBack ? CameraFacing.front : CameraFacing.back);
|
138
125
|
}
|
139
126
|
};
|
140
127
|
return <Dialog
|
@@ -149,9 +136,10 @@ export default function App({onScan,onGrantAccess,testID,onDenyAccess,cameraProp
|
|
149
136
|
DialogProvider.open({
|
150
137
|
tile : "Options de la camera",
|
151
138
|
data : cameraSetting,
|
152
|
-
fields :
|
139
|
+
fields : CameraSettingsFields,
|
153
140
|
onSuccess : ({data})=>{
|
154
141
|
setCameraSetting(data);
|
142
|
+
DialogProvider.close();
|
155
143
|
},
|
156
144
|
})
|
157
145
|
}
|
@@ -173,9 +161,8 @@ export default function App({onScan,onGrantAccess,testID,onDenyAccess,cameraProp
|
|
173
161
|
ratio='16:9'
|
174
162
|
testID={testID+"_ScannerContent"}
|
175
163
|
{...cameraProps}
|
176
|
-
barCodeScannerSettings = {barCodeScannerSettings}
|
177
164
|
{...cameraSetting}
|
178
|
-
facing = {
|
165
|
+
facing = {facing}
|
179
166
|
style={[theme.styles.flex1,{width:"100%",height:"100%"},cameraProps.style]}
|
180
167
|
onBarcodeScanned={handleBarCodeScanned}
|
181
168
|
/>
|
@@ -210,6 +197,10 @@ const styles = StyleSheet.create({
|
|
210
197
|
flexWrap :"wrap",
|
211
198
|
}
|
212
199
|
});
|
200
|
+
|
201
|
+
/***
|
202
|
+
@see : https://docs.expo.dev/versions/latest/sdk/camera-next
|
203
|
+
*/
|
213
204
|
BarCodeScanner.propTypes = {
|
214
205
|
onScan : PropTypes.func,
|
215
206
|
onGrantAccess : PropTypes.func, //lorsque la permission est allouée
|
package/src/uuid/deps.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export default {}
|
package/src/uuid/index.js
CHANGED