@fto-consult/expo-ui 8.80.0 → 8.81.1

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.
@@ -1,23 +1,10 @@
1
- import {StyleSheet} from 'react-native';
2
- import DrawerLayout from './DrawerLayout';
3
- import {isIos} from "$cplatform";
4
- import React from "$react";
5
- import PropTypes from "prop-types";
6
- import {defaultObj,isObj,isNonNullString} from "$cutils";
7
- import theme,{Colors,flattenStyle} from "$theme";
1
+ import {default as Drawer} from "./Drawer";
2
+ import Provider from "./Provider";
8
3
  import DrawerItems from './DrawerItems';
9
- import Dimensions,{isDesktopMedia,getCurrentMedia} from "$cplatform/dimensions";
10
- import {open,close} from "$epreloader";
11
- import {DRAWER_POSITIONS,DRAWER_TYPES,MINIMIZED_WIDTH,getDrawerWidth} from './utils';
12
- import Icon,{MENU_ICON} from "$ecomponents/Icon";
13
- import View from "$ecomponents/View";
14
- import {closeDrawer} from './DrawerItems/utils';
15
- import {DrawerContext} from "./Provider";
16
- import NavigationView from "./NavigationView";
17
- import { canBeMinimizedOrPermanent } from './utils';
18
- import { useSession } from './hooks';
19
4
 
5
+ export * from "./Drawer";
20
6
  export * from "./Provider";
7
+ export * from "./context";
21
8
 
22
9
  export {DrawerItems};
23
10
  export {default as DrawerItem} from "./DrawerItems/DrawerItem";
@@ -25,440 +12,7 @@ export {default as DrawerItem} from "./DrawerItems/DrawerItem";
25
12
  export * from "./utils";
26
13
  export * from "./hooks";
27
14
 
28
- const canHandleExtra = x=> true;
15
+ Drawer.Provider = Provider;
16
+ export default Drawer;
17
+ export {Provider};
29
18
 
30
-
31
- const DrawerComponent = React.forwardRef((props,ref)=>{
32
- let {position,permanent,onDrawerSlide,sessionName,content,
33
- drawerItemsContainerProps,contentContainerStyle,drawerItemsProps,minimizable,
34
- minimized,drawerItems,hideStatusBar,overlayColor, onDrawerMinimize,onDrawerToggleMinimize,
35
- onDrawerOpen,onDrawerClose,onDrawerToggle,header,headerProps,toggleIconProps,
36
- permanentToggleIcon,minimizedToggleIcon,temporaryToggleIcon,withMinimizedIcon,
37
- isItemActive,onPageResize,navigationViewRef,children:customChildren,testID,drawerType} = props;
38
-
39
- const children = React.useMemo(()=>customChildren,[customChildren]);
40
- testID = defaultStr(testID,"RN_DrawerComponent")
41
- const session = useSession(sessionName);
42
- sessionName = session.sessionName;
43
- const sessionValue = session.get();
44
- const drawerRef = React.useRef(null);
45
- const onSlideCallbackRef = React.useRef(null);
46
- drawerItemsContainerProps = defaultObj(drawerItemsContainerProps);
47
- position = defaultStr(position);
48
- position = DRAWER_POSITIONS[position] || (isNonNullString(sessionValue.position) && DRAWER_POSITIONS[sessionValue.position]? DRAWER_POSITIONS[sessionValue.position]:undefined) || DRAWER_POSITIONS.left
49
- const isLeftPosition = position === DRAWER_POSITIONS.left ? true : false;
50
- drawerType = defaultStr(drawerType).toLowerCase() || isNonNullString(sessionValue.drawerType) && DRAWER_TYPES[sessionValue.drawerType]? DRAWER_TYPES[sessionValue.drawerType] : "";
51
- if(!DRAWER_TYPES[drawerType]){
52
- drawerType = isIos()? DRAWER_TYPES.slide : DRAWER_TYPES.front;
53
- }
54
- overlayColor = Colors.isValid(overlayColor)?overlayColor:undefined;
55
- if(!overlayColor){
56
- overlayColor = theme.colors.backdrop;// drawerType === DRAWER_TYPES.front ? 'black' : '#00000000';
57
- }
58
- let drawerWidth = getDrawerWidth();
59
- const restP = {};
60
- const isDesktop = isDesktopMedia();
61
- const _canBeMinimizedOrPermanent = canBeMinimizedOrPermanent();
62
- permanent = _canBeMinimizedOrPermanent ? (sessionValue.permanent !== undefined ? sessionValue.permanent : permanent) : false;
63
- minimized = _canBeMinimizedOrPermanent ? (sessionValue.minimized !== undefined ? sessionValue.minimized: minimized) : false;
64
- if(permanent === undefined){
65
- permanent = canBeMinimizedOrPermanent()? true : false;
66
- }
67
- if(minimized === undefined){
68
- minimized = false;
69
- }
70
- const [state,_setState] = React.useState({
71
- minimized,
72
- permanent,
73
- });
74
- if(sessionValue.permanent ===undefined){
75
- session.set(state);
76
- }
77
- const setState = (s,s2)=>{
78
- s = typeof s =='object' && s ? s : {};
79
- s2 = typeof s2 =='object' && s2 ? s2 : {};
80
- s2 = {...state,...s,...s2};
81
- session.set(s2);
82
- return _setState(s2);
83
- }
84
-
85
- const [context] = React.useState({});
86
-
87
-
88
- const callbackRef = React.useRef(null);
89
- const callback = callbackRef.current;
90
- callbackRef.current = null;
91
- ///permet de minimiser le drawer
92
- context.minimize = (callback)=>{
93
- if(!Dimensions.isDesktopMedia() || isMinimized){
94
- return typeof callback =='function'? callback(context.getState()) : null;
95
- }
96
- callbackRef.current = callback;
97
- setState({minimized:true});
98
- }
99
- /*** permet de restaurer le drawer */
100
- context.restore = (callback)=>{
101
- if(!Dimensions.isDesktopMedia() || !context.isMinimized() || !context.isPermanent()){
102
- return typeof callback =='function'? callback(context.getState()) : null;
103
- }
104
- callbackRef.current = callback;
105
- setState({minimized:false,permanent:true});
106
- }
107
- const checkToggleBtn = (cb)=>{
108
- if(!Dimensions.isDesktopMedia() && drawerRef?.current?.isPermanent()){
109
- setState({permanent:false});
110
- if(typeof cb ==='function'){
111
- cb(getDrawerState());
112
- }
113
- return false;
114
- }
115
- return true;
116
- }
117
-
118
- context.toggleMinimized = (minimized,s2)=>{
119
- if(!checkToggleBtn()) return;
120
- if(!Dimensions.isDesktopMedia() || typeof minimized !== 'boolean' || !drawerRef.current || !drawerRef.current.isOpen()) return;
121
- if(!minimizable === false) return;
122
- let nS = {minimized};
123
- if(isObj(s2)){
124
- nS = {...s2,...nS};
125
- }
126
- setState(nS);
127
- }
128
- context.getPosition = ()=>position;
129
- context.hasLeftPositon = ()=> position === DRAWER_POSITIONS.left;
130
- context.hasRightPosition = ()=> position === DRAWER_POSITIONS.right;
131
- context.isLeftPosition = ()=> isLeftPosition;
132
- context.canToggle = x=> canHandleExtra() ? true : permanent? false : true;
133
- context.canMinimize = x => minimizable !== false && canBeMinimizedOrPermanent() ? true : false;
134
- context.togglePermanent = (x,cb)=>{
135
- if(typeof x !== "boolean") return;
136
- if(!checkToggleBtn(cb)) return;
137
- const isPerm = drawerRef?.current?.isPermanent();
138
- if(x && ! isPerm || !x && isPerm){
139
- setState({permanent:x});
140
- }
141
- if(typeof cb =="function"){
142
- cb(getDrawerState());
143
- }
144
- }
145
-
146
- let {permanent:isPermanent,minimized:isMinimized} = session.get();
147
- if(_canBeMinimizedOrPermanent && isPermanent){
148
- overlayColor = 'transparent';
149
- if(isMinimized){
150
- drawerWidth = MINIMIZED_WIDTH;
151
- }
152
- restP.drawerLockMode = "locked-open";
153
- } else {
154
- isPermanent = false;
155
- isMinimized = false;
156
- restP.drawerLockMode = "unlocked";
157
- drawerWidth = drawerWidth;
158
- }
159
- context.isMinimizable = ()=>{
160
- return minimizable !== false && canBeMinimizedOrPermanent() ? true : false;
161
- }
162
- context.isMinimized = ()=>{
163
- return minimizable !== false && canBeMinimizedOrPermanent() && isDesktopMedia() && session.get("minimized")? true : false;
164
- }
165
- const hasContext = ()=>drawerRef && isObj(drawerRef?.current) && Object.size(drawerRef?.current,true);
166
- context.canBeMinimizedOrPermanent = canBeMinimizedOrPermanent;
167
- context.isPermanent = x=>{
168
- if(!drawerRef.current || !drawerRef.current.isOpen()) return false;
169
- return canBeMinimizedOrPermanent() && session.get('permanent') ? true : false;
170
- }
171
- const prevMinimized = React.usePrevious(isMinimized);
172
- React.useEffect(()=>{
173
- if(prevMinimized === isMinimized || !Dimensions.isDesktopMedia()) return;
174
- const args = getDrawerState();
175
- if(isMinimized && onDrawerMinimize){
176
- onDrawerMinimize(args);
177
- }
178
- if(onDrawerToggleMinimize){
179
- onDrawerToggleMinimize(args);
180
- }
181
- if(typeof callback =='function'){
182
- callback(args);
183
- }
184
- session.set("minimized",isMinimized);
185
- },[isMinimized])
186
- const prevIsDesktop = React.usePrevious(isDesktop);
187
- React.useEffect(()=>{
188
- if(!drawerRef.current) return;
189
- if(isDesktopMedia() && isPermanent){
190
- drawerRef.current.openDrawer();
191
- }
192
- if(prevIsDesktop !== isDesktopMedia() && typeof onPageResize ==='function'){
193
- onPageResize(getDrawerState());
194
- }
195
- },[isDesktop])
196
- const getDrawerState = context.getState = (args)=>{
197
- const isOpen = drawerRef.current && drawerRef.current.isOpen ? drawerRef.current.isOpen () : false;
198
- return {
199
- ...session.get(),context:drawerRef.current,permanent:isPermanent,
200
- sessionName,
201
- minimized : isMinimized,
202
- permanent : isPermanent,
203
- isPermanent,
204
- isMinimized,
205
- isClosed : !isOpen, closed:!isOpen,isOpen ,opened:isOpen,status: isOpen ? 'open':'closed',
206
- ...defaultObj(args),
207
- }
208
- }
209
- const customOnToggle = (args)=>{
210
- args = getDrawerState(args);
211
- if(onDrawerToggle){
212
- onDrawerToggle(args)
213
- }
214
- if(typeof callback =='function'){
215
- callback(args);
216
- }
217
- }
218
- toggleIconProps = defaultObj(toggleIconProps);
219
- headerProps = defaultObj(headerProps);
220
-
221
- const getDrawerRef = x=> drawerRef;
222
- ///lorsque le drawer est en mode permanent, l'icone par défaut est l'icon devant le dépingler du mode permanent
223
- const backIcon = "window-close";//isLeftPosition ? "arrow-left" : "arrow-right";
224
- const chevronIcon = isLeftPosition ? "chevron-left":"chevron-right";
225
- context.temporaryToggleIcon = temporaryToggleIcon = React.isValidElement(temporaryToggleIcon)? temporaryToggleIcon : backIcon;
226
- context.permanentToggleIcon = permanentToggleIcon = React.isValidElement(permanentToggleIcon)? permanentToggleIcon : chevronIcon;
227
- context.minimizedToggleIcon = minimizedToggleIcon = React.isValidElement(minimizedToggleIcon)? minimizedToggleIcon : chevronIcon//MENU_ICON;
228
-
229
- let toggleIconTooltip = null;
230
- let toggleIcon = null, mobileToggleIconTooltip = "Cliquez pour "+(open?'Masquer':'Afficher')+ " le drawer";
231
- if(!isPermanent){
232
- toggleIconTooltip = mobileToggleIconTooltip;
233
- toggleIcon = temporaryToggleIcon;
234
- } else {
235
- if(isMinimized){
236
- toggleIconTooltip = "Cliquez pour restaurer le drawer dans son status précédent";
237
- if(withMinimizedIcon !== false){
238
- toggleIcon = minimizedToggleIcon;
239
- }
240
- } else {
241
- toggleIcon = permanentToggleIcon;
242
- toggleIconTooltip = 'Cliquer pour minimiser le drawer.\n si vous souhaitez passer le drawer en mode affichage temporaire, faite un long click (pressez le pour longtemps) sur ce bouton. ';
243
- }
244
- }
245
- return (
246
- <DrawerContext.Provider
247
- value={{
248
- ...context,
249
- context,
250
- drawerRef,
251
- session,
252
- hasContext,
253
- close : (cb,force) =>closeDrawer(drawerRef,cb,force),
254
- sessionName,
255
- isItemActive : (opts)=>{
256
- if(isItemActive){
257
- return isItemActive(opts);
258
- }
259
- return false;
260
- },getState:getDrawerState,getDrawerRef
261
- }}>
262
- <View style={styles.container} testID={`${testID}_Container`}>
263
- <DrawerLayout
264
- testID = {`${testID}_DrawerLayout`}
265
- {...restP}
266
- permanent = {isPermanent}
267
- onDrawerSlide={onDrawerSlide}
268
- onDrawerOpen = {(a)=>{
269
- if(drawerRef.current){
270
- drawerRef.current.drawerShown = true;
271
- }
272
- if(onDrawerOpen){
273
- onDrawerOpen({context:drawerRef.current})
274
- }
275
- customOnToggle({...getDrawerState(),closed:false, isClosed : false,isOpen:true,opened:true,status:'open'});
276
- }}
277
- onDrawerClose = {()=>{
278
- if(drawerRef.current){
279
- drawerRef.current.drawerShown = false;
280
- }
281
- if(typeof onSlideCallbackRef.current ==='function'){
282
- //close();
283
- onSlideCallbackRef.current();
284
- }
285
- onSlideCallbackRef.current = undefined;
286
- if(onDrawerClose){
287
- onDrawerClose({context:drawerRef.current})
288
- }
289
- customOnToggle({...getDrawerState(),isClosed : true, closed:true,isOpen : false ,opened:false,status:'closed'})
290
- }}
291
- ref={(el)=>{
292
- drawerRef.current = el;
293
- if(drawerRef.current){
294
- Object.map(context,(v,i)=>{
295
- if(drawerRef.current[i] === undefined){
296
- drawerRef.current[i] = v;
297
- }
298
- });
299
- drawerRef.current.open = drawerRef.current.openDrawer;
300
- drawerRef.current.runAfterSlide = (cb,force)=>{
301
- if(!permanent){
302
- //force !== true ? open() : false;
303
- onSlideCallbackRef.current = cb;
304
- return drawerRef.current.closeDrawer();
305
- }
306
- if(typeof cb =='function'){
307
- cb(getDrawerState());
308
- }
309
- }
310
- drawerRef.current.close = drawerRef.current.runAfterSlide;
311
- drawerRef.current.isOpen = context.isOpen = typeof drawerRef.current.isOpen =='function'? drawerRef.current.isOpen.bind(drawerRef.current) : x=> drawerRef && drawerRef.current ? drawerRef.current.drawerShown : false;
312
- drawerRef.current.isClosed = context.isClosed = x => !drawerRef.current.isOpen();
313
- context.toggle = drawerRef.current.toggleDrawer = drawerRef.current.toggle = cb =>{
314
- if(!checkToggleBtn(cb)) return;
315
- if(isPermanent || isMinimized) {
316
- if(typeof cb ==='function'){
317
- cb(getDrawerState());
318
- }
319
- return;
320
- }
321
- callbackRef.current = cb;
322
- if(drawerRef.current.isOpen()){
323
- drawerRef.current.closeDrawer();
324
- } else {
325
- drawerRef.current.openDrawer();
326
- }
327
- }
328
- drawerRef.current.getState = getDrawerState;
329
- }
330
- React.setRef(ref,drawerRef.current);
331
- }}
332
- drawerWidth={drawerWidth}
333
- keyboardDismissMode="on-drag"
334
- drawerPosition={position}
335
- drawerType={drawerType}
336
- hideStatusBar = {defaultBool(hideStatusBar,true)}
337
- overlayColor = {overlayColor}
338
- renderNavigationView={(opts)=>{
339
- const cArgs = {...getDrawerState()}
340
- const h = typeof header === 'function'? header(cArgs) : header;
341
- const c = typeof content =='function'? content (cArgs) : content;
342
- return <NavigationView
343
- opts = {opts}
344
- ref = {navigationViewRef}
345
- {...{context,toggleIcon,toggleIconTooltip,header:h,content:c,isPermanent,drawerItemsProps,drawerType,drawerItems,drawerRef,setState,toggleIconProps,isLeftPosition,drawerWidth,minimizable,headerProps,isMinimized,drawerItemsContainerProps}}
346
- />
347
- }}
348
- contentContainerStyle={[
349
- {paddingBottom:30},
350
- contentContainerStyle
351
- ]
352
- }>
353
- {children}
354
- </DrawerLayout>
355
- </View>
356
- </DrawerContext.Provider>
357
- );
358
- })
359
-
360
- export default DrawerComponent;
361
-
362
-
363
-
364
-
365
- const iconType = PropTypes.oneOfType([
366
- PropTypes.node,
367
- PropTypes.string,
368
- ]);
369
-
370
- DrawerComponent.propTypes = {
371
- ...defaultObj(DrawerLayout.propTypes),
372
- position : PropTypes.oneOf(Object.keys(DRAWER_POSITIONS)),
373
- minimizable : PropTypes.bool,
374
- permanent : PropTypes.bool,
375
- minimized : PropTypes.bool,
376
- bindResizeEvent : PropTypes.bool,
377
- children : PropTypes.node,
378
- onMount : PropTypes.func,
379
- onUnmount : PropTypes.func,
380
- onDrawerOpen : PropTypes.func,
381
- onDrawerClose : PropTypes.func,
382
- onDrawerSlide : PropTypes.func,
383
- onDrawerToggle : PropTypes.func,
384
- drawerItemsProps : PropTypes.object,
385
- drawerItems : PropTypes.oneOfType([
386
- PropTypes.array,
387
- PropTypes.node,
388
- PropTypes.element,
389
- PropTypes.elementType,
390
- PropTypes.func
391
- ]),
392
- isItemActive : PropTypes.func,///vérifie si un item est actif où pas
393
- permanent : PropTypes.bool,
394
- onDrawerToggle : PropTypes.func,
395
- onDrawerToggleMinimize : PropTypes.func,
396
- onDrawerMinimize : PropTypes.func,
397
- children : PropTypes.oneOfType([
398
- PropTypes.func,
399
- PropTypes.node,
400
- ]),
401
- /*** le header à afficher sur le drawer */
402
- header : PropTypes.oneOfType([
403
- PropTypes.node,
404
- PropTypes.func,
405
- ]),
406
- headerProps : PropTypes.object,//les props à passer drawerHeader
407
- onDrawerClose : PropTypes.func,
408
- onDrawerClose : PropTypes.func,
409
- onDrawerOpen : PropTypes.func,
410
- /***l'icone toggle lorsque le drawer est en mode temporaire, dont mobile */
411
- temporaryToggleIcon : iconType,
412
- //l'icone du button toggle lorsque le drawer est en mode permament
413
- permanentToggleIcon : iconType,
414
- //l'icone de toggle lorsque le drawer est en mode persistant
415
- persistentToggleIcon : iconType,
416
- minimizedToggleIcon : iconType, //l'icone du drawer lorsque celui si est en mode minimisté
417
- /*** si l'icone minimisé est affiché lorsque le drawer est en mode minimisé */
418
- withMinimizedIcon : PropTypes.bool,
419
- }
420
-
421
- const styles = StyleSheet.create({
422
- container: {
423
- flex: 1,
424
- },
425
- drawerContainer: {
426
- flex: 1,
427
- paddingTop : 0,// isMobileNative()? 25:0,
428
- },
429
- drawerText: {
430
- margin: 10,
431
- fontSize: 15,
432
- textAlign: 'left',
433
- },
434
- drawerHeaderContainer : {
435
- flexDirection : 'column',
436
- alignItems : 'center',
437
- justifyContent : 'flex-start',
438
- },
439
- drawerHeaderContent : {
440
- margin : 0,
441
- justifyContent : 'space-between',
442
- flexDirection : 'row',
443
- alignItems : 'center',
444
- paddingHorizontal : 10,
445
- width : '100%',
446
- },
447
- drawerHeaderContentMinimized : {
448
- textAlign : 'center',
449
- alignSelf : 'center',
450
- justifyContent : 'center',
451
- alignContent : 'center',
452
- paddingTop : 10,
453
- },
454
- drawerHeaderContainerLeft : {
455
- flexDirection : 'row',
456
- //paddingRight : 20,
457
- },
458
- drawerHeaderContainerRight : {
459
- flexDirection : 'row-reverse',
460
- //paddingLeft : 20,
461
- },
462
- });
463
-
464
- DrawerComponent.displayName = "DrawerComponent";
@@ -90,7 +90,7 @@ const FormActionComponent = React.forwardRef(({
90
90
  const formInstance = getFormInstance(formName);
91
91
  if(!formInstance || typeof formInstance.isValid != 'function' && isObj(formInstance.props)) return;
92
92
  if(formInstance.isValid()){
93
- onPress({...args,data:formInstance.getData({handleChange})})
93
+ onPress({...args,formInstance,form:formInstance,data:formInstance.getData({handleChange})})
94
94
  }
95
95
  }
96
96
  };
@@ -1,14 +1,11 @@
1
1
  import AppBar from "$ecomponents/AppBar";
2
- import { Appbar } from "react-native-paper";
3
2
  import React from "$react";
4
3
  import {MENU_ICON} from "$ecomponents/Icon";
5
4
  import {defaultObj} from "$cutils";
6
5
  import {useDrawer} from "$ecomponents/Drawer";
7
6
  import Icon from "$ecomponents/Icon";
8
7
  import {useGetComponent} from "$econtext/hooks";
9
- import {navigate as cNavigate,sanitizeName} from "$cnavigation";
10
8
  import { StackActions } from '@react-navigation/native';
11
-
12
9
  export * from "./utils";
13
10
 
14
11
  const AppBarLayout = React.forwardRef(({backActionProps,withDrawer,withNotifications,backAction,backActionRef,options,...props},ref)=>{
@@ -29,8 +26,6 @@ const AppBarLayout = React.forwardRef(({backActionProps,withDrawer,withNotificat
29
26
  goBack();
30
27
  return false;
31
28
  }
32
- const home = sanitizeName("Home");
33
- console.log(navigation," is navigation heeee ",args);
34
29
  if(typeof navigation?.dispatch =='function'){
35
30
  try {
36
31
  navigation.dispatch(StackActions.popToTop());
@@ -8,7 +8,6 @@ import Login from "$eauth/Login";
8
8
  import {navigate} from "$cnavigation";
9
9
  import theme from "$theme";
10
10
  import Logo from "$ecomponents/Logo";
11
- import appConfig from "$capp/config";
12
11
 
13
12
  const DrawerNavigator = React.forwardRef(({content,children:customChildren,state,...props},ref)=>{
14
13
  const drawerRef = React.useRef(null);