@fto-consult/expo-ui 8.81.0 → 8.81.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "8.81.0",
3
+ "version": "8.81.2",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "react-native-paper-doc": "https://github.com/callstack/react-native-paper/tree/main/docs/docs/guides",
6
6
  "scripts": {
@@ -9,7 +9,6 @@ import {renderSplitedActions} from "$ecomponents/AppBar/utils";
9
9
  import {isWeb,isNativeMobile,isTouchDevice} from "$cplatform";
10
10
  import Divider from "$ecomponents/Divider";
11
11
  import {isMobileOrTabletMedia} from "$cplatform/dimensions";
12
- import APP from "$capp/instance";
13
12
  import KeyboardAvoidingView from "$ecomponents/KeyboardAvoidingView";
14
13
  import {Elevations} from "$ecomponents/Surface";
15
14
  import {defaultStr} from "$cutils";
@@ -325,6 +325,7 @@ const DrawerComponent = React.forwardRef((props,ref)=>{
325
325
  hideStatusBar = {defaultBool(hideStatusBar,true)}
326
326
  overlayColor = {overlayColor}
327
327
  renderNavigationView={(opts)=>{
328
+ if(isPortal) return null;
328
329
  const cArgs = {...getDrawerState()}
329
330
  const h = typeof header === 'function'? header(cArgs) : header;
330
331
  const c = typeof content =='function'? content (cArgs) : content;
@@ -11,11 +11,15 @@ import {
11
11
  import { Portal } from 'react-native-paper';
12
12
  import PropTypes from "prop-types";
13
13
  import View from "$ecomponents/View";
14
- import {defaultStr} from "$cutils";
14
+ import {defaultStr,defaultObj} from "$cutils";
15
15
  import theme,{Colors} from "$theme";
16
16
  import {isMobileMedia} from "$cplatform/dimensions";
17
17
  import Preloader from "$epreloader";
18
18
  import {Elevations} from "$ecomponents/Surface";
19
+ import {HStack} from "$ecomponents/Stack";
20
+ import Divider from "$ecomponents/Divider";
21
+ import Label from "$ecomponents/Label";
22
+ import Icon from "$ecomponents/Icon";
19
23
 
20
24
  const MIN_SWIPE_DISTANCE = 3;
21
25
  const DEVICE_WIDTH = Math.max(Dimensions.get('window').width,280);
@@ -52,6 +56,7 @@ export default class DrawerLayout extends React.PureComponent {
52
56
  accessibilityViewIsModal: false,
53
57
  drawerShown,
54
58
  isPortal,
59
+ portalProps : {},
55
60
  openValue: new Animated.Value(drawerShown?1:0),
56
61
  };
57
62
  }
@@ -59,11 +64,18 @@ export default class DrawerLayout extends React.PureComponent {
59
64
  return !!this.state.isPortal;
60
65
  }
61
66
  getDrawerPosition() {
62
- const { drawerPosition } = this.props;
63
67
  const rtl = I18nManager.isRTL;
68
+ const p = this.isPortal()? this.state.portalProps : this.props;
69
+ let position = defaultStr(p?.drawerPosition,p?.position,this.props.drawerPosition).toLowerCase();
70
+ if(position !=='left' && position !=='right'){
71
+ position = 'left';
72
+ }
64
73
  return rtl
65
- ? drawerPosition === 'left' ? 'right' : 'left' // invert it
66
- : drawerPosition;
74
+ ? position === 'left' ? 'right' : 'left' // invert it
75
+ : position;
76
+ }
77
+ isPositionRight(){
78
+ return this.getDrawerPosition() === 'right';
67
79
  }
68
80
  isOpen(){
69
81
  return this.state.drawerShown;
@@ -111,34 +123,68 @@ export default class DrawerLayout extends React.PureComponent {
111
123
  getBackgroundColor(){
112
124
  return Colors.isValid(this.props.drawerBackgroundColor)? this.props.backgroundColor : theme.colors.surface;
113
125
  }
126
+ getPortalTestID(){
127
+ return defaultStr(this.state.portalProps.testID,"RN_DrawerLayoutPortal");
128
+ }
129
+ renderPortalTitle(){
130
+ if(React.isValidElement(this.state.portalProps?.title)) return this.state.portalProps?.title;
131
+ const title = this.state.portalProps?.title;
132
+ const isPositionRight = this.isPositionRight();
133
+ if(typeof title == 'string' && title || typeof title =="number"){
134
+ const titleProps = defaultObj(this.state.portalProps.titleProps);
135
+ const testID = this.getPortalTestID();
136
+ const icon = <Icon
137
+ onPress = {this.closeDrawer.bind(this)}
138
+ icon = {this.state.portalProps?.closeIcon || !this.isPositionRight() == 'left'? 'chevron-left' : 'chevron-right'}
139
+ {...defaultObj(this.state.portalProps.closeIconProps)}
140
+ />;
141
+ const titleContainerProps = defaultObj(this.state.portalProps?.titleContainerProps);
142
+ return <>
143
+ <HStack testID={testID+"_TitleContainer"} {...titleContainerProps} style={[styles.portalTitle,titleContainerProps.style]}>
144
+ {isPositionRight? icon : null}
145
+ <Label testID={testID+"_DrawerLayoutTitle"} {...titleProps} style={[styles.portalTitleText,titleProps.style]} >
146
+ {title}
147
+ </Label>
148
+ {!isPositionRight ? icon : null}
149
+ </HStack>
150
+ <Divider/>
151
+ </>;
152
+ }
153
+ return null;
154
+ }
155
+ renderPortalChildren(){
156
+ return <>
157
+ {this.renderPortalTitle()}
158
+ {React.isValidElement(this.state.portalProps?.children) ? this.state.portalProps?.children : null}
159
+ </>
160
+ }
114
161
  renderContent({testID}){
115
162
  return <View style={[styles.main]} testID={testID+"_DrawerLayoutContent"}>
116
163
  {this.props.children}
117
164
  </View>;
118
165
  }
166
+ getDrawerWidth() {
167
+ return defaultNumber(this.isPortal()? this.state.portalProps?.drawerWidth : 0,this.props.drawerWidth);
168
+ }
119
169
  render() {
120
170
  const { accessibilityViewIsModal, drawerShown, openValue } = this.state;
121
171
  const elevation = typeof this.props.elevation =='number'? this.props.elevation : 5;
122
172
  const elev = this.props.permanent && Elevations[elevation]? Elevations[elevation] : null;
123
173
  const testID = defaultStr(this.props.testID,"RN_DrawerLayoutComponent")
124
- let {
125
- drawerBackgroundColor,
126
- drawerWidth,
127
- drawerPosition,
128
- permanent,
129
- position,
174
+ let { permanent,
130
175
  navigationViewRef,
131
176
  } = this.props;
132
-
177
+ let drawerWidth = this.getDrawerWidth();
133
178
  /**
134
179
  * We need to use the "original" drawer position here
135
180
  * as RTL turns position left and right on its own
136
181
  **/
182
+ const posRight = this.isPositionRight();
137
183
  const dynamicDrawerStyles = {
138
184
  backgroundColor: this.getBackgroundColor(),
139
185
  width: drawerWidth,
140
- left: drawerPosition === 'left' ? 0 : null,
141
- right: drawerPosition === 'right' ? 0 : null,
186
+ left: !posRight ? 0 : null,
187
+ right: posRight? 0 : null,
142
188
  };
143
189
 
144
190
  /* Drawer styles */
@@ -167,11 +213,8 @@ export default class DrawerLayout extends React.PureComponent {
167
213
  });
168
214
  const animatedOverlayStyles = { opacity: overlayOpacity };
169
215
  const pointerEvents = drawerShown || permanent ? 'auto' : 'none';
170
- position = defaultStr(position).toLowerCase();
171
- if(position !=='left' && position !=='right'){
172
- position = 'left';
173
- }
174
- const posRight = position =="right"? true : false;
216
+
217
+
175
218
  if(permanent){
176
219
  dynamicDrawerStyles.position = "relative";
177
220
  }
@@ -207,7 +250,7 @@ export default class DrawerLayout extends React.PureComponent {
207
250
  animatedDrawerStyles,
208
251
  ]}
209
252
  >
210
- {this.props.renderNavigationView()}
253
+ {this.isPortal()? this.renderPortalChildren() : this.props.renderNavigationView()}
211
254
  </Animated.View>
212
255
  {!posRight && this.renderContent({testID})}
213
256
  </View>
@@ -228,27 +271,35 @@ export default class DrawerLayout extends React.PureComponent {
228
271
  }
229
272
  };
230
273
 
231
- openDrawer = (options = {}) => {
232
- this._emitStateChanged(SETTLING);
233
- Animated.spring(this.state.openValue, {
234
- toValue: 1,
235
- bounciness: 0,
236
- restSpeedThreshold: 0.1,
237
- useNativeDriver: this.props.useNativeAnimations,
238
- ...options,
239
- }).start(() => {
240
- if (this.props.onDrawerOpen) {
241
- this.props.onDrawerOpen();
242
- }
243
- this._emitStateChanged(IDLE);
244
- });
274
+ openDrawer = (options) => {
275
+ options = Object.assign({}, options);
276
+ const cb = ()=>{
277
+ this._emitStateChanged(SETTLING);
278
+ Animated.spring(this.state.openValue, {
279
+ toValue: 1,
280
+ bounciness: 0,
281
+ restSpeedThreshold: 0.1,
282
+ useNativeDriver: this.props.useNativeAnimations,
283
+ ...options,
284
+ }).start(() => {
285
+ if (this.props.onDrawerOpen) {
286
+ this.props.onDrawerOpen();
287
+ }
288
+ this._emitStateChanged(IDLE);
289
+ });
290
+ }
291
+ if(this.isPortal()){
292
+ this.setState({portalProps:options},cb)
293
+ } else {
294
+ cb();
295
+ }
245
296
  };
246
297
 
247
298
  closeDrawer = (options = {},showPreloader) => {
248
299
  if(typeof options ==='boolean'){
249
300
  showPreloader = options;
250
301
  }
251
- options = typeof options =='object' && options ? options : {};
302
+ options = Object.assign({}, options);
252
303
  if(typeof showPreloader !== 'boolean'){
253
304
  showPreloader = options.showPreloader || options.preloader;
254
305
  }
@@ -300,10 +351,9 @@ export default class DrawerLayout extends React.PureComponent {
300
351
  if (this._isLockedClosed() || this._isLockedOpen()) {
301
352
  return false;
302
353
  }
303
-
304
354
  if (this.getDrawerPosition() === 'left') {
305
355
  const overlayArea = DEVICE_WIDTH -
306
- (DEVICE_WIDTH - this.props.drawerWidth);
356
+ (DEVICE_WIDTH - this.getDrawerWidth());
307
357
 
308
358
  if (this._lastOpenValue === 1) {
309
359
  if (
@@ -323,8 +373,7 @@ export default class DrawerLayout extends React.PureComponent {
323
373
  return false;
324
374
  }
325
375
  } else {
326
- const overlayArea = DEVICE_WIDTH - this.props.drawerWidth;
327
-
376
+ const overlayArea = DEVICE_WIDTH - this.getDrawerWidth();
328
377
  if (this._lastOpenValue === 1) {
329
378
  if (
330
379
  (dx > 0 && Math.abs(dx) > Math.abs(dy) * 3) ||
@@ -426,7 +475,7 @@ export default class DrawerLayout extends React.PureComponent {
426
475
  };
427
476
 
428
477
  _getOpenValueForX(x) {
429
- const { drawerWidth } = this.props;
478
+ const drawerWidth = this.getDrawerWidth();
430
479
 
431
480
  if (this.getDrawerPosition() === 'left') {
432
481
  return x / drawerWidth;
@@ -463,15 +512,25 @@ const styles = StyleSheet.create({
463
512
  },
464
513
  portalNotVisibleContainer : {
465
514
  opacity : 0,
466
- }
515
+ },
516
+ portalTitle : {
517
+ justifyContent : 'space-between',
518
+ alignItems : 'center',
519
+ paddingHorizontal : 10,
520
+ flexWrap : 'nowrap',
521
+ },
522
+ portalTitleText : {
523
+ fontSize : 16,
524
+ fontWeight : 'bold',
525
+ },
467
526
  });
468
-
527
+ const posPropType = PropTypes.oneOf(['left', 'right']);
469
528
  DrawerLayout.propTypes = {
470
529
  isPortal : PropTypes.bool,
471
530
  children: PropTypes.any,
472
531
  drawerBackgroundColor : PropTypes.string,
473
532
  drawerLockMode: PropTypes.oneOf(['unlocked','locked-closed', 'locked-open']),
474
- drawerPosition: PropTypes.oneOf(['left', 'right']),
533
+ drawerPosition: posPropType,
475
534
  drawerWidth: PropTypes.number,
476
535
  keyboardDismissMode: PropTypes.oneOf(['none' , 'on-drag']),
477
536
  onDrawerClose: PropTypes.func,
@@ -481,6 +540,39 @@ DrawerLayout.propTypes = {
481
540
  renderNavigationView: PropTypes.any,
482
541
  statusBarBackgroundColor : PropTypes.string,
483
542
  useNativeAnimations: PropTypes.bool,
543
+ /****
544
+ * les props à passer à la fonction open du drawer, lorsqu'il s'agit du portal
545
+ *
546
+ */
547
+ portalProps : PropTypes.shape({
548
+ title : PropTypes.oneOfType([
549
+ PropTypes.string,//si title est une chaine de caractère alors il sera rendu avec le bouton close permettant de fermer le Drawer
550
+ PropTypes.node,
551
+ PropTypes.element,
552
+ PropTypes.elementType,
553
+ ]),
554
+ titleProps : PropTypes.shape({
555
+ ...defaultObj(Label.propTypes),
556
+ }),
557
+ closeIconProps : PropTypes.shape({
558
+ ...defaultObj(Icon.propTypes),
559
+ }),
560
+ icon : PropTypes.oneOfType([
561
+ PropTypes.string,
562
+ PropTypes.node,
563
+ PropTypes.element,
564
+ ]),
565
+ children : PropTypes.oneOfType([
566
+ PropTypes.node,
567
+ PropTypes.element,
568
+ ]),
569
+ drawerPosition : posPropType,
570
+ position : posPropType,
571
+ drawerWidth : PropTypes.number,
572
+ titleContainerProps : PropTypes.shape({
573
+ ...defaultObj(HStack.propTypes),
574
+ }),
575
+ }),
484
576
  }
485
577
 
486
578
  DrawerLayout.defaultProps = {