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