@fto-consult/expo-ui 8.81.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.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fto-consult/expo-ui",
|
3
|
-
"version": "8.81.
|
3
|
+
"version": "8.81.1",
|
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
|
-
?
|
66
|
-
:
|
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,67 @@ 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
|
+
return <>
|
142
|
+
<HStack style={[styles.portalTitle]} testID={testID+"_TitleContainer"}>
|
143
|
+
{isPositionRight? icon : null}
|
144
|
+
<Label {...titleProps} style={[styles.portalTitleText]} testID={testID+"_DrawerLayoutTitle"}>
|
145
|
+
{title}
|
146
|
+
</Label>
|
147
|
+
{!isPositionRight ? icon : null}
|
148
|
+
</HStack>
|
149
|
+
<Divider/>
|
150
|
+
</>;
|
151
|
+
}
|
152
|
+
return null;
|
153
|
+
}
|
154
|
+
renderPortalChildren(){
|
155
|
+
return <>
|
156
|
+
{this.renderPortalTitle()}
|
157
|
+
{React.isValidElement(this.state.portalProps?.children) ? this.state.portalProps?.children : null}
|
158
|
+
</>
|
159
|
+
}
|
114
160
|
renderContent({testID}){
|
115
161
|
return <View style={[styles.main]} testID={testID+"_DrawerLayoutContent"}>
|
116
162
|
{this.props.children}
|
117
163
|
</View>;
|
118
164
|
}
|
165
|
+
getDrawerWidth() {
|
166
|
+
return defaultNumber(this.isPortal()? this.state.portalProps?.drawerWidth : 0,this.props.drawerWidth);
|
167
|
+
}
|
119
168
|
render() {
|
120
169
|
const { accessibilityViewIsModal, drawerShown, openValue } = this.state;
|
121
170
|
const elevation = typeof this.props.elevation =='number'? this.props.elevation : 5;
|
122
171
|
const elev = this.props.permanent && Elevations[elevation]? Elevations[elevation] : null;
|
123
172
|
const testID = defaultStr(this.props.testID,"RN_DrawerLayoutComponent")
|
124
|
-
let {
|
125
|
-
drawerBackgroundColor,
|
126
|
-
drawerWidth,
|
127
|
-
drawerPosition,
|
128
|
-
permanent,
|
129
|
-
position,
|
173
|
+
let { permanent,
|
130
174
|
navigationViewRef,
|
131
175
|
} = this.props;
|
132
|
-
|
176
|
+
let drawerWidth = this.getDrawerWidth();
|
133
177
|
/**
|
134
178
|
* We need to use the "original" drawer position here
|
135
179
|
* as RTL turns position left and right on its own
|
136
180
|
**/
|
181
|
+
const posRight = this.isPositionRight();
|
137
182
|
const dynamicDrawerStyles = {
|
138
183
|
backgroundColor: this.getBackgroundColor(),
|
139
184
|
width: drawerWidth,
|
140
|
-
left:
|
141
|
-
right:
|
185
|
+
left: !posRight ? 0 : null,
|
186
|
+
right: posRight? 0 : null,
|
142
187
|
};
|
143
188
|
|
144
189
|
/* Drawer styles */
|
@@ -167,11 +212,8 @@ export default class DrawerLayout extends React.PureComponent {
|
|
167
212
|
});
|
168
213
|
const animatedOverlayStyles = { opacity: overlayOpacity };
|
169
214
|
const pointerEvents = drawerShown || permanent ? 'auto' : 'none';
|
170
|
-
|
171
|
-
|
172
|
-
position = 'left';
|
173
|
-
}
|
174
|
-
const posRight = position =="right"? true : false;
|
215
|
+
|
216
|
+
|
175
217
|
if(permanent){
|
176
218
|
dynamicDrawerStyles.position = "relative";
|
177
219
|
}
|
@@ -207,7 +249,7 @@ export default class DrawerLayout extends React.PureComponent {
|
|
207
249
|
animatedDrawerStyles,
|
208
250
|
]}
|
209
251
|
>
|
210
|
-
{this.props.renderNavigationView()}
|
252
|
+
{this.isPortal()? this.renderPortalChildren() : this.props.renderNavigationView()}
|
211
253
|
</Animated.View>
|
212
254
|
{!posRight && this.renderContent({testID})}
|
213
255
|
</View>
|
@@ -228,27 +270,35 @@ export default class DrawerLayout extends React.PureComponent {
|
|
228
270
|
}
|
229
271
|
};
|
230
272
|
|
231
|
-
openDrawer = (options
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
273
|
+
openDrawer = (options) => {
|
274
|
+
options = Object.assign({}, options);
|
275
|
+
const cb = ()=>{
|
276
|
+
this._emitStateChanged(SETTLING);
|
277
|
+
Animated.spring(this.state.openValue, {
|
278
|
+
toValue: 1,
|
279
|
+
bounciness: 0,
|
280
|
+
restSpeedThreshold: 0.1,
|
281
|
+
useNativeDriver: this.props.useNativeAnimations,
|
282
|
+
...options,
|
283
|
+
}).start(() => {
|
284
|
+
if (this.props.onDrawerOpen) {
|
285
|
+
this.props.onDrawerOpen();
|
286
|
+
}
|
287
|
+
this._emitStateChanged(IDLE);
|
288
|
+
});
|
289
|
+
}
|
290
|
+
if(this.isPortal()){
|
291
|
+
this.setState({portalProps:options},cb)
|
292
|
+
} else {
|
293
|
+
cb();
|
294
|
+
}
|
245
295
|
};
|
246
296
|
|
247
297
|
closeDrawer = (options = {},showPreloader) => {
|
248
298
|
if(typeof options ==='boolean'){
|
249
299
|
showPreloader = options;
|
250
300
|
}
|
251
|
-
options =
|
301
|
+
options = Object.assign({}, options);
|
252
302
|
if(typeof showPreloader !== 'boolean'){
|
253
303
|
showPreloader = options.showPreloader || options.preloader;
|
254
304
|
}
|
@@ -300,10 +350,9 @@ export default class DrawerLayout extends React.PureComponent {
|
|
300
350
|
if (this._isLockedClosed() || this._isLockedOpen()) {
|
301
351
|
return false;
|
302
352
|
}
|
303
|
-
|
304
353
|
if (this.getDrawerPosition() === 'left') {
|
305
354
|
const overlayArea = DEVICE_WIDTH -
|
306
|
-
(DEVICE_WIDTH - this.
|
355
|
+
(DEVICE_WIDTH - this.getDrawerWidth());
|
307
356
|
|
308
357
|
if (this._lastOpenValue === 1) {
|
309
358
|
if (
|
@@ -323,8 +372,7 @@ export default class DrawerLayout extends React.PureComponent {
|
|
323
372
|
return false;
|
324
373
|
}
|
325
374
|
} else {
|
326
|
-
const overlayArea = DEVICE_WIDTH - this.
|
327
|
-
|
375
|
+
const overlayArea = DEVICE_WIDTH - this.getDrawerWidth();
|
328
376
|
if (this._lastOpenValue === 1) {
|
329
377
|
if (
|
330
378
|
(dx > 0 && Math.abs(dx) > Math.abs(dy) * 3) ||
|
@@ -426,7 +474,7 @@ export default class DrawerLayout extends React.PureComponent {
|
|
426
474
|
};
|
427
475
|
|
428
476
|
_getOpenValueForX(x) {
|
429
|
-
const
|
477
|
+
const drawerWidth = this.getDrawerWidth();
|
430
478
|
|
431
479
|
if (this.getDrawerPosition() === 'left') {
|
432
480
|
return x / drawerWidth;
|
@@ -463,15 +511,20 @@ const styles = StyleSheet.create({
|
|
463
511
|
},
|
464
512
|
portalNotVisibleContainer : {
|
465
513
|
opacity : 0,
|
514
|
+
},
|
515
|
+
portalTitle : {
|
516
|
+
justifyContent : 'space-between',
|
517
|
+
alignItems : 'center',
|
518
|
+
paddingHorizontal : 10,
|
466
519
|
}
|
467
520
|
});
|
468
|
-
|
521
|
+
const posPropType = PropTypes.oneOf(['left', 'right']);
|
469
522
|
DrawerLayout.propTypes = {
|
470
523
|
isPortal : PropTypes.bool,
|
471
524
|
children: PropTypes.any,
|
472
525
|
drawerBackgroundColor : PropTypes.string,
|
473
526
|
drawerLockMode: PropTypes.oneOf(['unlocked','locked-closed', 'locked-open']),
|
474
|
-
drawerPosition:
|
527
|
+
drawerPosition: posPropType,
|
475
528
|
drawerWidth: PropTypes.number,
|
476
529
|
keyboardDismissMode: PropTypes.oneOf(['none' , 'on-drag']),
|
477
530
|
onDrawerClose: PropTypes.func,
|
@@ -481,6 +534,36 @@ DrawerLayout.propTypes = {
|
|
481
534
|
renderNavigationView: PropTypes.any,
|
482
535
|
statusBarBackgroundColor : PropTypes.string,
|
483
536
|
useNativeAnimations: PropTypes.bool,
|
537
|
+
/****
|
538
|
+
* les props à passer à la fonction open du drawer, lorsqu'il s'agit du portal
|
539
|
+
*
|
540
|
+
*/
|
541
|
+
portalProps : PropTypes.shape({
|
542
|
+
title : PropTypes.oneOfType([
|
543
|
+
PropTypes.string,//si title est une chaine de caractère alors il sera rendu avec le bouton close permettant de fermer le Drawer
|
544
|
+
PropTypes.node,
|
545
|
+
PropTypes.element,
|
546
|
+
PropTypes.elementType,
|
547
|
+
]),
|
548
|
+
titleProps : PropTypes.shape({
|
549
|
+
...defaultObj(Label.propTypes),
|
550
|
+
}),
|
551
|
+
closeIconProps : PropTypes.shape({
|
552
|
+
...defaultObj(Icon.propTypes),
|
553
|
+
}),
|
554
|
+
icon : PropTypes.oneOfType([
|
555
|
+
PropTypes.string,
|
556
|
+
PropTypes.node,
|
557
|
+
PropTypes.element,
|
558
|
+
]),
|
559
|
+
children : PropTypes.oneOfType([
|
560
|
+
PropTypes.node,
|
561
|
+
PropTypes.element,
|
562
|
+
]),
|
563
|
+
drawerPosition : posPropType,
|
564
|
+
position : posPropType,
|
565
|
+
drawerWidth : PropTypes.number,
|
566
|
+
}),
|
484
567
|
}
|
485
568
|
|
486
569
|
DrawerLayout.defaultProps = {
|