@fto-consult/expo-ui 6.5.0 → 6.5.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 +2 -2
- package/src/auth/Login.js +4 -10
- package/src/components/Dialog/DropdownAlert/index.js +5 -15
- package/src/components/Form/Fields/Field.js +22 -28
- package/src/components/Form/FormData/DialogProvider.js +3 -3
- package/src/components/Grid/Cell.js +11 -11
- package/src/components/TextField/index.js +4 -4
- package/src/components/View/index.js +2 -3
- package/src/hooks/index.js +11 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fto-consult/expo-ui",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.2",
|
|
4
4
|
"description": "Bibliothèque de composants UI Expo,react-native",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@emotion/native": "^11.11.0",
|
|
63
63
|
"@expo/html-elements": "^0.5.1",
|
|
64
64
|
"@expo/vector-icons": "^13.0.0",
|
|
65
|
-
"@fto-consult/common": "^3.
|
|
65
|
+
"@fto-consult/common": "^3.21.0",
|
|
66
66
|
"@gorhom/portal": "^1.0.14",
|
|
67
67
|
"@pchmn/expo-material3-theme": "^1.3.1",
|
|
68
68
|
"@react-native-async-storage/async-storage": "1.18.2",
|
package/src/auth/Login.js
CHANGED
|
@@ -199,22 +199,16 @@ export default function LoginComponent(props){
|
|
|
199
199
|
});
|
|
200
200
|
const withScrollView = typeof customWithScrollView =='boolean'? customWithScrollView : true;
|
|
201
201
|
const Wrapper = withPortal ? ScreenWithoutAuthContainer : withScrollView ? ScrollView: View;
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
if(typeof contentProps.updateMediaQueryStyle =='function'){
|
|
205
|
-
return contentProps.updateMediaQueryStyle({style})
|
|
206
|
-
}
|
|
207
|
-
return {style};
|
|
202
|
+
const mediaQueryUpdateStyle = (a)=>{
|
|
203
|
+
return StyleSheet.flatten([updateMediaQueryStyle(),contentProps.style]);
|
|
208
204
|
};
|
|
209
205
|
const wrapperProps = withPortal ? {appBarProps,authRequired:false,title:loginTitle,withScrollView} : { style:styles.wrapper};
|
|
210
|
-
const sH = React.isComponent(HeaderTopContent)? <HeaderTopContent
|
|
211
|
-
mediaQueryUpdateNativeProps = {mQueryUpdateProps}
|
|
212
|
-
/> : React.isValidElement(HeaderTopContent)? HeaderTopContent : null;
|
|
206
|
+
const sH = React.isComponent(HeaderTopContent)? <HeaderTopContent mediaQueryUpdateStyle = {mediaQueryUpdateStyle} /> : React.isValidElement(HeaderTopContent)? HeaderTopContent : null;
|
|
213
207
|
return <Wrapper testID = {testID+"_Wrapper" }{...wrapperProps}>
|
|
214
208
|
<DialogProvider ref={dialogProviderRef}/>
|
|
215
209
|
{sH}
|
|
216
210
|
<Surface {...containerProps} {...defaultObj(loginProps?.containerProps)} style={[styles.container,{backgroundColor},containerProps.style,loginProps?.containerProps?.style]} testID={testID}>
|
|
217
|
-
<Surface elevation = {0} {...contentProps}
|
|
211
|
+
<Surface elevation = {0} {...contentProps} mediaQueryUpdateStyle = {mediaQueryUpdateStyle} {...contentProps} testID={testID+"_Content"} style={[styles.content,{backgroundColor},contentProps.style]}>
|
|
218
212
|
<FormData
|
|
219
213
|
formName = {formName}
|
|
220
214
|
testID = {testID+"_FormData"}
|
|
@@ -672,9 +672,11 @@ export default class DropdownAlert extends Component {
|
|
|
672
672
|
accessibilityLabel={accessibilityLabel}
|
|
673
673
|
accessible={accessible}>
|
|
674
674
|
<View style={style} testID={testID+"_ContentContainer"}>
|
|
675
|
-
<View testID={testID+"_ContentWrapper"} style={[contentContainerStyle
|
|
676
|
-
|
|
677
|
-
return
|
|
675
|
+
<View testID={testID+"_ContentWrapper"} style={[contentContainerStyle]}
|
|
676
|
+
mediaQueryUpdateStyle={({isMobile,isTablet,width,...rest})=>{
|
|
677
|
+
return {
|
|
678
|
+
maxWidth : isMobile ? (90*width)/100 : isTablet? Math.max((70*width/100),350) : 500
|
|
679
|
+
}
|
|
678
680
|
}}
|
|
679
681
|
>
|
|
680
682
|
{this._renderImage(imageSrc, imageStyle)}
|
|
@@ -690,16 +692,4 @@ export default class DropdownAlert extends Component {
|
|
|
690
692
|
</Portal>
|
|
691
693
|
);
|
|
692
694
|
}
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
const getContainerStyle = (args)=>{
|
|
696
|
-
if(!isObj(args)){
|
|
697
|
-
args = {isMobile : isMobileMedia(),isTablet : isTabletMedia()};
|
|
698
|
-
}
|
|
699
|
-
const {width} = Dimensions.get("window");
|
|
700
|
-
return {
|
|
701
|
-
style : {
|
|
702
|
-
maxWidth : args.isMobile ? (90*width)/100 : args.isTablet? Math.max((70*width/100),350) : 500
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
695
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import KeyboardEventHandler from "../KeyboardEventHandler";
|
|
3
|
+
import { addMediaQueryUpdateStyeSubscription } from "$ehooks";
|
|
4
|
+
import Dimensions from "$cdimensions";
|
|
3
5
|
const {getActions,getFormFields,Forms} = require("../utils")
|
|
4
6
|
import TextField,{parseDecimal} from "$ecomponents/TextField";
|
|
5
7
|
import Icon from "$ecomponents/Icon";
|
|
@@ -219,10 +221,10 @@ export default class Field extends AppComponent {
|
|
|
219
221
|
this.state.validatingValue = this.validatingValue = defaultVal(this.props.defaultValue);
|
|
220
222
|
this.keybaordEvents = [...Object.keys(defaultKeyboardEvents),...this.keybaordEvents]
|
|
221
223
|
this.state.isMobile = isMobileMedia();
|
|
222
|
-
this.state.textFieldMode = theme.textFieldMode;
|
|
223
224
|
this.state.isReadOnlyOrDisabled = false;
|
|
224
225
|
this.state.isFieldEditable = true;
|
|
225
226
|
this.state.isFieldVisible = typeof this.props.visible =='boolean'? this.props.visible : true;
|
|
227
|
+
this.state.wrapperStyle = this.getMediaQueryUpdateStyle();
|
|
226
228
|
}
|
|
227
229
|
validatorBeforeValidate({value,validRule,validParams,event,...rest}){
|
|
228
230
|
let _result = undefined;
|
|
@@ -610,18 +612,11 @@ export default class Field extends AppComponent {
|
|
|
610
612
|
}
|
|
611
613
|
return ob;
|
|
612
614
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if(typeof this.props.updateNativePropsOnUpdate ==='function'){
|
|
616
|
-
this.props.updateNativePropsOnUpdate({
|
|
617
|
-
target : this.wrapperRef,
|
|
618
|
-
props : this.props,
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
}
|
|
615
|
+
|
|
616
|
+
|
|
622
617
|
componentDidMount (validate){
|
|
623
618
|
super.componentDidMount();
|
|
624
|
-
this.
|
|
619
|
+
this.mediaQueryUpdateStyleSubscription = addMediaQueryUpdateStyeSubscription(this.doUpdateMediaQueryStyle.bind(this));
|
|
625
620
|
if(this.canValidate !== false){
|
|
626
621
|
Forms.trigger("registerField",this.getName(),this.getFormName(),this);
|
|
627
622
|
}
|
|
@@ -632,8 +627,8 @@ export default class Field extends AppComponent {
|
|
|
632
627
|
this._fieldRef = undefined;
|
|
633
628
|
this.offAll();
|
|
634
629
|
this.clearEvents();
|
|
635
|
-
if(this.
|
|
636
|
-
this.
|
|
630
|
+
if(this.mediaQueryUpdateStyleSubscription && this.mediaQueryUpdateStyleSubscription?.remove){
|
|
631
|
+
this.mediaQueryUpdateStyleSubscription.remove();
|
|
637
632
|
}
|
|
638
633
|
if(this.canValidate !== false){
|
|
639
634
|
Forms.trigger("unregisterField",this.getName(),this.getFormName());
|
|
@@ -642,20 +637,17 @@ export default class Field extends AppComponent {
|
|
|
642
637
|
isHtml(){
|
|
643
638
|
return false;
|
|
644
639
|
}
|
|
645
|
-
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
if(this.props.responsive === false && !hasTextFieldModeChanged) return;
|
|
654
|
-
if((hasTextFieldModeChanged)){
|
|
655
|
-
this.setState({isMobile,textFieldMode:theme.textFieldMode});
|
|
656
|
-
return null;
|
|
640
|
+
doUpdateMediaQueryStyle(args){
|
|
641
|
+
const wrapperStyle = this.getMediaQueryUpdateStyle(args);
|
|
642
|
+
this.setState({isMobile:args.isMobile,wrapperStyle});
|
|
643
|
+
}
|
|
644
|
+
getMediaQueryUpdateStyle(args){
|
|
645
|
+
if(this.props.responsive === false) return null;
|
|
646
|
+
if(!isObj(args)){
|
|
647
|
+
args = Dimensions.getDimensionsProps();
|
|
657
648
|
}
|
|
658
|
-
|
|
649
|
+
const style2 = typeof this.props.mediaQueryUpdateStyle =='function'? this.props.mediaQueryUpdateStyle(args) : null;
|
|
650
|
+
return StyleSheet.flatten([grid.col(this.props.windowWidth),style2]);
|
|
659
651
|
}
|
|
660
652
|
onKeyEvent(key,event){
|
|
661
653
|
let form = this.getForm();
|
|
@@ -1032,11 +1024,13 @@ export default class Field extends AppComponent {
|
|
|
1032
1024
|
rest.height = height;
|
|
1033
1025
|
}
|
|
1034
1026
|
}
|
|
1035
|
-
return <KeyboardEventHandler formFieldName={this.getName()} testID={'RN_FormFieldContainer_'+this.getName()} innerRef={this.wrapperRef}
|
|
1027
|
+
return <KeyboardEventHandler formFieldName={this.getName()} testID={'RN_FormFieldContainer_'+this.getName()} innerRef={this.wrapperRef}
|
|
1028
|
+
{...wrapperProps}
|
|
1036
1029
|
handleKeys={this.keybaordEvents}
|
|
1037
1030
|
onKeyEvent = {this.onKeyEvent.bind(this)}
|
|
1038
1031
|
isDisabled = {rest.disabled}
|
|
1039
|
-
|
|
1032
|
+
mediaQueryUpdateStyle={null}
|
|
1033
|
+
style = {[this.state.wrapperStyle,wrapperProps.style,visibleStyle]}
|
|
1040
1034
|
>
|
|
1041
1035
|
{(kProps)=>{
|
|
1042
1036
|
return this._render({...rest,...kProps},this.setRef.bind(this))
|
|
@@ -42,10 +42,10 @@ const FormDataDialogProvider = React.forwardRef((props,innerRef)=>{
|
|
|
42
42
|
if(state.visible){
|
|
43
43
|
formProps.fieldProps = defaultObj(formProps.fieldProps);
|
|
44
44
|
formProps.fieldProps.windowWidth = !isMobile ? MAX_WIDTH : undefined;
|
|
45
|
-
formProps.fieldProps.
|
|
46
|
-
if(!
|
|
45
|
+
formProps.fieldProps.mediaQueryUpdateStyle = ({target})=>{
|
|
46
|
+
if(!formRef.current || !formRef.current.dialogRef || !formRef.current.dialogRef.current || !formRef.current.dialogRef.current.isFullScreen) return;
|
|
47
47
|
const f = formRef.current.dialogRef.current.isFullScreen();
|
|
48
|
-
|
|
48
|
+
return f ? grid.col() : {width:'100%'};
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
return <Dialog
|
|
@@ -4,7 +4,7 @@ import React from '$react';
|
|
|
4
4
|
import {Pressable, StyleSheet} from 'react-native';
|
|
5
5
|
import Dimensions from "$cplatform/dimensions";
|
|
6
6
|
import View from "$ecomponents/View";
|
|
7
|
-
import {defaultStr} from "$cutils";
|
|
7
|
+
import {defaultStr,isObj} from "$cutils";
|
|
8
8
|
import PropTypes from "prop-types";
|
|
9
9
|
import {medias} from "$theme/grid";
|
|
10
10
|
import theme from "$theme";
|
|
@@ -66,14 +66,11 @@ export const getSizeStyle = (props)=>{
|
|
|
66
66
|
}
|
|
67
67
|
paddingMultiplicator = typeof paddingMultiplicator =='number'? paddingMultiplicator : 1.8;
|
|
68
68
|
marginMultiplicator = typeof marginMultiplicator =="number"? marginMultiplicator : 0;
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
style : {paddingRight:gutter*paddingMultiplicator,marginVertical:gutter,width : (((size)/totalSize)*100)+"%"}
|
|
72
|
-
}
|
|
69
|
+
return {paddingRight:gutter*paddingMultiplicator,marginVertical:gutter,width : (((size)/totalSize)*100)+"%"}
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
const GridCellComponent = React.forwardRef((p,ref)=>{
|
|
76
|
-
const {style,size,children,phoneSize,withSurface,elevation:cElev,
|
|
73
|
+
const {style,size,children,phoneSize,withSurface,elevation:cElev,mediaQueryUpdateStyle,contentProps:cProps,tabletSize,desktopSize,smallPhoneSize,onPress,activeOpacity,onLongPress,flex:customFlex,onPressIn,onPressOut,...props} = p;
|
|
77
74
|
const testID = defaultStr(props.testID,"RN_Grid.CellComponent");
|
|
78
75
|
const contentProps = defaultObj(cProps);
|
|
79
76
|
const C = onPress || onLongPress || onPressIn || onPressOut ? Pressable : View;
|
|
@@ -82,13 +79,16 @@ const GridCellComponent = React.forwardRef((p,ref)=>{
|
|
|
82
79
|
return <View
|
|
83
80
|
{...props}
|
|
84
81
|
testID={testID}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
mediaQueryUpdateStyle = {(args)=>{
|
|
83
|
+
const style2 = getSizeStyle(p);
|
|
84
|
+
const style = typeof mediaQueryUpdateStyle =='function' && mediaQueryUpdateStyle(args) || undefined;
|
|
85
|
+
if(isObj(style) || Array.isArray(style)){
|
|
86
|
+
return StyleSheet.flatten([style2,styles]);
|
|
87
|
+
}
|
|
88
|
+
return style2;
|
|
89
89
|
}}
|
|
90
90
|
ref={ref}
|
|
91
|
-
style = {[styles.container,customFlex !== undefined && {flex:customFlex},
|
|
91
|
+
style = {[styles.container,customFlex !== undefined && {flex:customFlex},style]}
|
|
92
92
|
>
|
|
93
93
|
<C testID={testID+"_Content"} activeOpacity={activeOpacity} {...contentProps}
|
|
94
94
|
|
|
@@ -229,7 +229,7 @@ const TextFieldComponent = React.forwardRef((componentProps,inputRef)=>{
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
selectionColor = Colors.isValid(selectionColor)? selectionColor : theme.colors.secondaryOnSurface;
|
|
232
|
-
const flattenStyle = StyleSheet.flatten([styles.input,styles.textInput,props.style,styles.w100,style,upperStyle]);
|
|
232
|
+
const flattenStyle = StyleSheet.flatten([{pointerEvents},styles.input,styles.textInput,props.style,styles.w100,style,upperStyle]);
|
|
233
233
|
fontSize = defaultNumber(fontSize,flattenStyle.fontSize,FONT_SIZE);
|
|
234
234
|
labelProps = defaultObj(labelProps);
|
|
235
235
|
const alphaColor = isShadowMode || isNormalMode ? theme.colors.text : Colors.setAlpha(theme.colors.text,theme.ALPHA);
|
|
@@ -296,6 +296,7 @@ const TextFieldComponent = React.forwardRef((componentProps,inputRef)=>{
|
|
|
296
296
|
const withAutoHeight = typeof autoHeight === 'boolean'? autoHeight : false;
|
|
297
297
|
const height = withAutoHeight || multiline ? undefined : tHeight;
|
|
298
298
|
const inputStyle2 = withAutoHeight || multiline ? {minHeight : heightRef.current} : null;
|
|
299
|
+
const containerStyle = StyleSheet.flatten(containerProps.style) || {};
|
|
299
300
|
const inputProps= {
|
|
300
301
|
caretHidden : false,
|
|
301
302
|
ellipsizeMode : "head",
|
|
@@ -358,7 +359,6 @@ const TextFieldComponent = React.forwardRef((componentProps,inputRef)=>{
|
|
|
358
359
|
isShadowMode && styles.inputShadowMode,
|
|
359
360
|
multiline && {paddingTop : isFlatMode? 12 : 7},
|
|
360
361
|
],
|
|
361
|
-
pointerEvents,
|
|
362
362
|
secureTextEntry,
|
|
363
363
|
inputMode,
|
|
364
364
|
autoCapitalize : upper?(isAndroid?'characters':"none"):autoCapitalize,
|
|
@@ -399,7 +399,7 @@ const TextFieldComponent = React.forwardRef((componentProps,inputRef)=>{
|
|
|
399
399
|
let hasRight = React.isValidElement(right),hasLeft = React.isValidElement(left);
|
|
400
400
|
enableCopy = enableCopy ? true : false;
|
|
401
401
|
fieldToCopy = defaultStr(fieldToCopy).toLowerCase().trim();
|
|
402
|
-
if(isEditable || isFilter || defaultStr(
|
|
402
|
+
if(isEditable || isFilter || defaultStr(containerStyle.pointerEvents).toLowerCase().contains("none")){
|
|
403
403
|
enableCopy = false;
|
|
404
404
|
}
|
|
405
405
|
if(enableCopy){
|
|
@@ -530,7 +530,7 @@ const TextFieldComponent = React.forwardRef((componentProps,inputRef)=>{
|
|
|
530
530
|
{label}
|
|
531
531
|
</Label> : null}
|
|
532
532
|
<>
|
|
533
|
-
<Surface testID={testID+"_ContentContainer"}
|
|
533
|
+
<Surface testID={testID+"_ContentContainer"} {...contentContainerProps} elevation={elevation} style={[styles.contentContainer,{pointerEvents},!left? styles.paddingLeft:null,styles.row,contentContainerStyle,contentContainerProps.style]}>
|
|
534
534
|
{left ? (<View testID={testID+"_Left"} {...leftContainerProps} style={[styles.AdornmentContainer,styles.leftAdornment,leftContainerProps.style,disabledStyle]}>
|
|
535
535
|
{left}
|
|
536
536
|
</View>) : null}
|
|
@@ -6,7 +6,7 @@ import {debounce,isNumber} from "$cutils";
|
|
|
6
6
|
import {useMediaQueryUpdateStyle} from "$ehooks";
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
const ViewComponent = React.forwardRef(({
|
|
9
|
+
const ViewComponent = React.forwardRef(({onRender,onLayoutTimeout,onLayout,autoHeight,autoWidth,elevation,...props},ref)=>{
|
|
10
10
|
const style = useMediaQueryUpdateStyle(props);
|
|
11
11
|
const autoSize = autoHeight||autoWidth ? true : false;
|
|
12
12
|
const [state,setState] = autoSize ? React.useState({}) : [{}];
|
|
@@ -33,7 +33,7 @@ const ViewComponent = React.forwardRef(({mediaQueryUpdateNativeProps,onRender,on
|
|
|
33
33
|
]
|
|
34
34
|
]}
|
|
35
35
|
onLayout = {isMobileNative()? onL : debounce(onL,typeof onLayoutTimeout =='number'? onLayoutTimeout : 100)}
|
|
36
|
-
ref={
|
|
36
|
+
ref={ref}
|
|
37
37
|
/>
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -42,7 +42,6 @@ export default ViewComponent;
|
|
|
42
42
|
ViewComponent.displayName = "ViewComponent";
|
|
43
43
|
|
|
44
44
|
ViewComponent.propTypes = {
|
|
45
|
-
mediaQueryUpdateNativeProps : PropTypes.func,
|
|
46
45
|
mediaQueryUpdateStyle : PropTypes.func,
|
|
47
46
|
autoWidth : PropTypes.bool,//si la taille de la vue est calculée automatiquement
|
|
48
47
|
autoHeight : PropTypes.bool,//si la taille de
|
package/src/hooks/index.js
CHANGED
|
@@ -4,63 +4,21 @@ import useStableMemo from "$react/useStableMemo";
|
|
|
4
4
|
import { useWindowDimensions } from "$cdimensions";
|
|
5
5
|
import {isObj} from "$cutils";
|
|
6
6
|
import { StyleSheet } from "react-native";
|
|
7
|
-
import React from "$react";
|
|
8
7
|
|
|
9
|
-
export const updateNativePropsOnDimensionsChanged = (hostRef,updateNativePropsCallback,dimensions)=>{
|
|
10
|
-
console.log("will set native propsss ",hostRef?.current?.setNativeProps," is native props",hostRef.current)
|
|
11
|
-
if(!hostRef || !hostRef.current|| typeof hostRef.current.setNativeProps !=='function') return null;
|
|
12
|
-
const args = Dimensions.getDimensionsProps(dimensions);
|
|
13
|
-
args.target = hostRef.current;
|
|
14
|
-
if(typeof updateNativePropsCallback !== 'function') return args;
|
|
15
|
-
const nProps = updateNativePropsCallback(args,hostRef);
|
|
16
|
-
if(!isObj(nProps) || !Object.size(nProps,true)) return null;
|
|
17
|
-
return hostRef.current.setNativeProps(nProps);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**** permet de récupérer la fonction à attacher par défaut au listener DimensionChange, pour la mise à jour automatique des props à l'aide de la fonction setNativeProps
|
|
21
|
-
* * @param updatePropsWithMediaQuery{function}, la fonction permettant de mettre à jour les props lorsque la taille de l'écran change
|
|
22
|
-
* @pram hostRef{func||object}, la référence de l'objet qu'on utilisera pour mettre à jour les props avec la méthode setNativeProps de react-native
|
|
23
|
-
* @param timeout {number}, le délai d'attente à passer à la fonction debounce, pour pouvoir appeler la fonction de mise à jour des props lorsque la taile de l'écran change
|
|
24
|
-
* @return {function||null} la fonction à attacher au listener
|
|
25
|
-
*/
|
|
26
|
-
export const mediaQueryUpdateNativePropsCallback = (updatePropsWithMediaQuery,hostRef,timeout)=>{
|
|
27
|
-
if(typeof updatePropsWithMediaQuery !=='function') return null;
|
|
28
|
-
if(typeof hostRef ==='number'){
|
|
29
|
-
const t = timeout;
|
|
30
|
-
timeout = t;
|
|
31
|
-
hostRef = typeof t =='function' || isObj(t)? t : undefined;
|
|
32
|
-
}
|
|
33
|
-
let options = {};
|
|
34
|
-
if(typeof timeout =='object' && timeout){
|
|
35
|
-
options = timeout;
|
|
36
|
-
}
|
|
37
|
-
timeout = typeof timeout =='number'? timeout : typeof options.timeout =='number'? options.timeout : 200;
|
|
38
|
-
return debounce((dimensions)=>{
|
|
39
|
-
return updateNativePropsOnDimensionsChanged(hostRef,updatePropsWithMediaQuery,dimensions);
|
|
40
|
-
},timeout);
|
|
41
|
-
}
|
|
42
8
|
|
|
43
|
-
/*** permet d'attacher un lister sur la modification des props de manière responsive
|
|
9
|
+
/*** permet d'attacher un lister sur la modification des props de manière responsive :
|
|
10
|
+
permet de récupérer la fonction à attacher par défaut au listener DimensionChange, pour la mise à jour automatique de la propriété style
|
|
11
|
+
* @param mediaQueryUpdateStyleCb{function}, la fonction permettant de mettre à jour les props lorsque la taille de l'écran change
|
|
12
|
+
* @param timeout {number}, le délai d'attente à passer à la fonction debounce, pour pouvoir appeler la fonction de mise à jour des props lorsque la taile de l'écran change
|
|
44
13
|
* @return {object{remove:function}||null} l'objet null ou ayan la fonction remove permettant de suprimer le listerner lorsque le composant est démonté
|
|
45
14
|
*/
|
|
46
|
-
export const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* @parm {function}, la fonction de rappel à utiliser pour définir les props à passer à la référence
|
|
54
|
-
* @param {ref}, la référence de l'objet dom auquel on écoutera le changement d'évènement
|
|
55
|
-
* @parm timeout, le délai d'attente lorsque la dimension de l'écran change
|
|
56
|
-
*/
|
|
57
|
-
export const useMediaQueryUpdateNativeProps = (updatePropsWithMediaQuery,ref,timeout)=>{
|
|
58
|
-
const hostRef = React.useRef(null);
|
|
59
|
-
React.useEffect(()=>{
|
|
60
|
-
const subscription = getMediaQueryPropsSubscription(updatePropsWithMediaQuery,hostRef,timeout);
|
|
61
|
-
return () => subscription?.remove();
|
|
62
|
-
},[]);
|
|
63
|
-
return React.useMergeRefs(hostRef,ref);
|
|
15
|
+
export const addMediaQueryUpdateStyeSubscription = (mediaQueryUpdateStyleCb,timeout)=>{
|
|
16
|
+
if(typeof mediaQueryUpdateStyleCb !='function') return null;
|
|
17
|
+
const options = isObj(timeout)? timeout : {};
|
|
18
|
+
timeout = typeof timeout =='number'? timeout : typeof options.timeout =='number'? options.timeout : 200;
|
|
19
|
+
return Dimensions.addEventListener("change",debounce((dimensions)=>{
|
|
20
|
+
return mediaQueryUpdateStyleCb(Dimensions.getDimensionsProps(dimensions));
|
|
21
|
+
},timeout));
|
|
64
22
|
}
|
|
65
23
|
|
|
66
24
|
/*** met à jour dynamiquemnet les propriétés style d'un objet en fonction du changement de la taille de l'objet
|