@fto-consult/expo-ui 8.80.0 → 8.81.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.
@@ -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,409 @@
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
+ const cArgs = {...getDrawerState()}
329
+ const h = typeof header === 'function'? header(cArgs) : header;
330
+ const c = typeof content =='function'? content (cArgs) : content;
331
+ return <NavigationView
332
+ opts = {opts}
333
+ ref = {navigationViewRef}
334
+ {...{context,toggleIcon,toggleIconTooltip,header:h,content:c,isPermanent,drawerItemsProps,drawerType,drawerItems,drawerRef,setState,toggleIconProps,isLeftPosition,drawerWidth,minimizable,headerProps,isMinimized,drawerItemsContainerProps}}
335
+ />
336
+ }}
337
+ contentContainerStyle={[
338
+ {paddingBottom:30},
339
+ contentContainerStyle
340
+ ]
341
+ }>
342
+ {children}
343
+ </DrawerLayout>
344
+ </DrawerContext.Provider>
345
+ );
346
+ })
347
+
348
+ export default DrawerComponent;
349
+
350
+
351
+
352
+
353
+ const iconType = PropTypes.oneOfType([
354
+ PropTypes.node,
355
+ PropTypes.string,
356
+ ]);
357
+
358
+ DrawerComponent.propTypes = {
359
+ ...defaultObj(DrawerLayout.propTypes),
360
+ position : PropTypes.oneOf(Object.keys(DRAWER_POSITIONS)),
361
+ minimizable : PropTypes.bool,
362
+ permanent : PropTypes.bool,
363
+ minimized : PropTypes.bool,
364
+ bindResizeEvent : PropTypes.bool,
365
+ children : PropTypes.node,
366
+ onMount : PropTypes.func,
367
+ onUnmount : PropTypes.func,
368
+ onDrawerOpen : PropTypes.func,
369
+ onDrawerClose : PropTypes.func,
370
+ onDrawerSlide : PropTypes.func,
371
+ onDrawerToggle : PropTypes.func,
372
+ drawerItemsProps : PropTypes.object,
373
+ drawerItems : PropTypes.oneOfType([
374
+ PropTypes.array,
375
+ PropTypes.node,
376
+ PropTypes.element,
377
+ PropTypes.elementType,
378
+ PropTypes.func
379
+ ]),
380
+ isItemActive : PropTypes.func,///vérifie si un item est actif où pas
381
+ permanent : PropTypes.bool,
382
+ onDrawerToggle : PropTypes.func,
383
+ onDrawerToggleMinimize : PropTypes.func,
384
+ onDrawerMinimize : PropTypes.func,
385
+ children : PropTypes.oneOfType([
386
+ PropTypes.func,
387
+ PropTypes.node,
388
+ ]),
389
+ /*** le header à afficher sur le drawer */
390
+ header : PropTypes.oneOfType([
391
+ PropTypes.node,
392
+ PropTypes.func,
393
+ ]),
394
+ headerProps : PropTypes.object,//les props à passer drawerHeader
395
+ onDrawerClose : PropTypes.func,
396
+ onDrawerClose : PropTypes.func,
397
+ onDrawerOpen : PropTypes.func,
398
+ /***l'icone toggle lorsque le drawer est en mode temporaire, dont mobile */
399
+ temporaryToggleIcon : iconType,
400
+ //l'icone du button toggle lorsque le drawer est en mode permament
401
+ permanentToggleIcon : iconType,
402
+ //l'icone de toggle lorsque le drawer est en mode persistant
403
+ persistentToggleIcon : iconType,
404
+ minimizedToggleIcon : iconType, //l'icone du drawer lorsque celui si est en mode minimisté
405
+ /*** si l'icone minimisé est affiché lorsque le drawer est en mode minimisé */
406
+ withMinimizedIcon : PropTypes.bool,
407
+ }
408
+
409
+ 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
 
@@ -8,6 +8,7 @@ import {
8
8
  TouchableWithoutFeedback,
9
9
  I18nManager,
10
10
  } from 'react-native';
11
+ import { Portal } from 'react-native-paper';
11
12
  import PropTypes from "prop-types";
12
13
  import View from "$ecomponents/View";
13
14
  import {defaultStr} from "$cutils";
@@ -37,6 +38,7 @@ export default class DrawerLayout extends React.PureComponent {
37
38
 
38
39
  constructor(props) {
39
40
  super(props);
41
+ const isPortal = !! props.isPortal;
40
42
  this._panResponder = PanResponder.create({
41
43
  onMoveShouldSetPanResponder: this._shouldSetPanResponder,
42
44
  onPanResponderGrant: this._panResponderGrant,
@@ -45,14 +47,17 @@ export default class DrawerLayout extends React.PureComponent {
45
47
  onPanResponderRelease: this._panResponderRelease,
46
48
  onPanResponderTerminate: () => {},
47
49
  });
48
- const drawerShown = props.permanent? true : false;
50
+ const drawerShown = !isPortal && props.permanent? true : false;
49
51
  this.state = {
50
52
  accessibilityViewIsModal: false,
51
53
  drawerShown,
54
+ isPortal,
52
55
  openValue: new Animated.Value(drawerShown?1:0),
53
56
  };
54
57
  }
55
-
58
+ isPortal(){
59
+ return !!this.state.isPortal;
60
+ }
56
61
  getDrawerPosition() {
57
62
  const { drawerPosition } = this.props;
58
63
  const rtl = I18nManager.isRTL;
@@ -170,39 +175,43 @@ export default class DrawerLayout extends React.PureComponent {
170
175
  if(permanent){
171
176
  dynamicDrawerStyles.position = "relative";
172
177
  }
178
+ const Wrapper = this.isPortal()? Portal : React.Fragment;
179
+ const canRender = this.isPortal()? this.state.drawerShown : true;
173
180
  return (
174
- <View
175
- testID = {testID}
176
- style={{ flex: 1, backgroundColor: 'transparent',flexDirection:permanent?'row':'column'}}
177
- {...this._panResponder.panHandlers}
178
- >
179
- {!permanent && <TouchableWithoutFeedback
180
- style={{pointerEvents}}
181
- testID = {testID+"_TouchableWithoutFeedBack"}
182
- onPress={this._onOverlayClick}
181
+ <Wrapper>
182
+ <View
183
+ testID = {testID}
184
+ style={[{ flex: canRender && 1 || 0, backgroundColor: 'transparent',flexDirection:permanent?'row':'column'},canRender?styles.portalVisibleContainer:styles.portalNotVisibleContainer]}
185
+ {...this._panResponder.panHandlers}
183
186
  >
187
+ {!permanent && <TouchableWithoutFeedback
188
+ style={{pointerEvents}}
189
+ testID = {testID+"_TouchableWithoutFeedBack"}
190
+ onPress={this._onOverlayClick}
191
+ >
192
+ <Animated.View
193
+ testID={testID+"_Backdrow"}
194
+ ref = {this._backdropRef}
195
+ style={[styles.overlay,{backgroundColor:theme.colors.backdrop},{pointerEvents}, animatedOverlayStyles]}
196
+ />
197
+ </TouchableWithoutFeedback>}
198
+ {posRight && this.renderContent({testID})}
184
199
  <Animated.View
185
- testID={testID+"_Backdrow"}
186
- ref = {this._backdropRef}
187
- style={[styles.overlay,{backgroundColor:theme.colors.backdrop},{pointerEvents}, animatedOverlayStyles]}
188
- />
189
- </TouchableWithoutFeedback>}
190
- {posRight && this.renderContent({testID})}
191
- <Animated.View
192
- testID={testID+"_NavigationViewContainer"}
193
- ref={React.mergeRefs(navigationViewRef,this._navigationViewRef)}
194
- accessibilityViewIsModal={accessibilityViewIsModal}
195
- style={[
196
- styles.drawer,
197
- dynamicDrawerStyles,
198
- elev,
199
- animatedDrawerStyles,
200
- ]}
201
- >
202
- {this.props.renderNavigationView()}
203
- </Animated.View>
204
- {!posRight && this.renderContent({testID})}
205
- </View>
200
+ testID={testID+"_NavigationViewContainer"}
201
+ ref={React.mergeRefs(navigationViewRef,this._navigationViewRef)}
202
+ accessibilityViewIsModal={accessibilityViewIsModal}
203
+ style={[
204
+ styles.drawer,
205
+ dynamicDrawerStyles,
206
+ elev,
207
+ animatedDrawerStyles,
208
+ ]}
209
+ >
210
+ {this.props.renderNavigationView()}
211
+ </Animated.View>
212
+ {!posRight && this.renderContent({testID})}
213
+ </View>
214
+ </Wrapper>
206
215
  );
207
216
  }
208
217
 
@@ -449,10 +458,17 @@ const styles = StyleSheet.create({
449
458
  right: 0,
450
459
  zIndex: 1000,
451
460
  },
461
+ portalVisibleContainer : {
462
+ ...StyleSheet.absoluteFill,
463
+ },
464
+ portalNotVisibleContainer : {
465
+ opacity : 0,
466
+ }
452
467
  });
453
468
 
454
469
  DrawerLayout.propTypes = {
455
- children: PropTypes.any.isRequired,
470
+ isPortal : PropTypes.bool,
471
+ children: PropTypes.any,
456
472
  drawerBackgroundColor : PropTypes.string,
457
473
  drawerLockMode: PropTypes.oneOf(['unlocked','locked-closed', 'locked-open']),
458
474
  drawerPosition: PropTypes.oneOf(['left', 'right']),
@@ -71,7 +71,7 @@ const DrawerNavigationViewComponent = React.forwardRef((props,ref)=>{
71
71
  <DrawerItems
72
72
  drawerRef = {drawerRef}
73
73
  {...defaultObj(drawerItemsProps)}
74
- items = {drawerItems}
74
+ items = {drawerItems || []}
75
75
  drawerType = {drawerType}
76
76
  isDrawerOpen = {drawerRef.current?.isOpen() || false}
77
77
  minimized = {isMinimized}
@@ -1,6 +1,73 @@
1
+ import Drawer from "./Drawer";
1
2
  import React from "$react";
2
- export const DrawerContext = React.createContext(null);
3
+ import {View,StyleSheet} from "react-native";
4
+ let drawerRef = null;
3
5
 
4
- export const useDrawer = ()=>{
5
- return React.useContext(DrawerContext) || {hasContext:x=>false};
6
- }
6
+ export const createProviderRef = (cb)=>{
7
+ const ref = React.useRef(null);
8
+ React.useEffect(()=>{
9
+ if(typeof cb =='function'){
10
+ cb(ref.current);
11
+ } else if(cb !== false) {
12
+ drawerRef = ref.current;
13
+ }
14
+ },[ref.current])
15
+ return ref;
16
+ };
17
+
18
+ export const getProviderRef = ()=> drawerRef;
19
+
20
+ export const open = (props,innerProviderRef)=>{
21
+ innerProviderRef = innerProviderRef || getProviderRef();
22
+ if(!innerProviderRef) return false;
23
+ if(innerProviderRef.current && innerProviderRef.current.open){
24
+ innerProviderRef = innerProviderRef.current;
25
+ }
26
+ if(innerProviderRef && typeof innerProviderRef.open =='function') {
27
+ return innerProviderRef.open(props);
28
+ }
29
+ return false;
30
+ }
31
+
32
+ export const close = (props,innerProviderRef)=>{
33
+ innerProviderRef = innerProviderRef || getProviderRef();
34
+ if(!innerProviderRef) return false;
35
+ if(innerProviderRef.current && innerProviderRef.current.open){
36
+ innerProviderRef = innerProviderRef.current;
37
+ }
38
+ if(innerProviderRef && typeof innerProviderRef.close =='function') return innerProviderRef.close(props);
39
+ return false;
40
+ }
41
+
42
+ const Provider = React.forwardRef((props,innerRef)=>{
43
+ return <Drawer
44
+ ref = {innerRef || createProviderRef()}
45
+ position="right"
46
+ sessionName = {sessionName}
47
+ {...props}
48
+ permanent={false}
49
+ isPortal
50
+ />
51
+ });
52
+
53
+ const sessionName = "custom-drawer-provider-right";
54
+
55
+ Provider.displayName = "DrawerProviderComponent";
56
+
57
+ export default Provider;
58
+
59
+ Provider.open = open;
60
+
61
+ Provider.close = close;
62
+
63
+ Provider.sessionName = sessionName;
64
+
65
+ const styles = StyleSheet.create({
66
+ visible : {
67
+ opacity : 1,
68
+ ...StyleSheet.absoluteFill,
69
+ },
70
+ notVisible : {
71
+ opacity : 0,
72
+ }
73
+ })
@@ -0,0 +1,6 @@
1
+ import React from "$react";
2
+ export const DrawerContext = React.createContext(null);
3
+
4
+ export const useDrawer = ()=>{
5
+ return React.useContext(DrawerContext) || {hasContext:x=>false};
6
+ }