@fto-consult/expo-ui 6.4.5 → 6.5.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.
package/babel.config.alias.js
CHANGED
|
@@ -69,6 +69,8 @@ module.exports = (opts)=>{
|
|
|
69
69
|
if(typeof opts.mutator =='function'){
|
|
70
70
|
opts.mutator(r);
|
|
71
71
|
}
|
|
72
|
+
r.$eutils = path.resolve(expo,"utils");
|
|
73
|
+
r.$ehooks = path.resolve(expo,"hooks");
|
|
72
74
|
///le chemin racine du projet expo-ui
|
|
73
75
|
r["$expo-ui-root-path"] = r["$expo-ui-root"]= path.resolve(expo,"..");
|
|
74
76
|
|
package/package.json
CHANGED
|
@@ -64,6 +64,7 @@ const AvatarComponent = React.forwardRef((props,ref)=>{
|
|
|
64
64
|
const c = <Component
|
|
65
65
|
{...rest}
|
|
66
66
|
{...cProps}
|
|
67
|
+
containerProps = {containerProps}
|
|
67
68
|
ref={ref}
|
|
68
69
|
onPress = {!handleOnPress && onPress ? onPress : undefined}
|
|
69
70
|
title = {onPress?null : defaultVal(toolip,title)}
|
|
@@ -71,7 +72,7 @@ const AvatarComponent = React.forwardRef((props,ref)=>{
|
|
|
71
72
|
style = {style}
|
|
72
73
|
size= {size}
|
|
73
74
|
/>;
|
|
74
|
-
return onPress && handleOnPress ? <Tooltip title={title} toolip={toolip} Component = {Pressable} testID={testID+"_Container"}
|
|
75
|
+
return onPress && handleOnPress ? <Tooltip title={title} toolip={toolip} Component = {Pressable} testID={testID+"_Container"} onPress={onPress}>{c}</Tooltip> : c;
|
|
75
76
|
});
|
|
76
77
|
|
|
77
78
|
AvatarComponent.displayName = "AvatarComponent";
|
|
@@ -41,7 +41,7 @@ const DialogComponent = React.forwardRef((props,ref)=>{
|
|
|
41
41
|
onCancelButtonPress,no,yes,
|
|
42
42
|
onDismiss:customOnDismiss,backAction,onShow,backActionProps,
|
|
43
43
|
fullScreen:customFullScreen,appBarProps,contentProps,actionsProps,
|
|
44
|
-
title,subtitle,onMount,onUnmount,
|
|
44
|
+
title,subtitle,onMount,onUnmount,
|
|
45
45
|
titleProps,
|
|
46
46
|
visible,
|
|
47
47
|
scrollViewProps,withScrollView,
|
|
@@ -146,11 +146,6 @@ const DialogComponent = React.forwardRef((props,ref)=>{
|
|
|
146
146
|
const {height} = Dimensions.get("window");
|
|
147
147
|
return Math.max((height>600?(50):70)*height/100,MIN_HEIGHT);
|
|
148
148
|
}
|
|
149
|
-
const modalStyle = React.useMediaQueryUpdateStyle({
|
|
150
|
-
mediaQueryUpdateStyle : (args)=>{
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
149
|
const onModalShown = (a)=>{
|
|
155
150
|
if(onShow){
|
|
156
151
|
onShow(a);
|
|
@@ -197,7 +192,7 @@ const DialogComponent = React.forwardRef((props,ref)=>{
|
|
|
197
192
|
dismissable = {isDimissable}
|
|
198
193
|
onShow = {onModalShown}
|
|
199
194
|
visible={visible}
|
|
200
|
-
style = {[styles.modal,modalProps.style
|
|
195
|
+
style = {[styles.modal,modalProps.style]}
|
|
201
196
|
ref={modalRef}
|
|
202
197
|
testID = {testID}
|
|
203
198
|
contentContainerProps = {contentContainerProps}
|
|
@@ -3,10 +3,11 @@ import PropTypes from "prop-types";
|
|
|
3
3
|
import React from "$react";
|
|
4
4
|
import {isMobileNative} from "$cplatform";
|
|
5
5
|
import {debounce,isNumber} from "$cutils";
|
|
6
|
+
import {useMediaQueryUpdateStyle} from "$ehooks";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
const ViewComponent = React.forwardRef(({mediaQueryUpdateNativeProps,onRender,onLayoutTimeout,onLayout,autoHeight,autoWidth,elevation,...props},ref)=>{
|
|
9
|
-
const style =
|
|
10
|
+
const style = useMediaQueryUpdateStyle(props);
|
|
10
11
|
const autoSize = autoHeight||autoWidth ? true : false;
|
|
11
12
|
const [state,setState] = autoSize ? React.useState({}) : [{}];
|
|
12
13
|
const {width,height} = state;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
|
|
2
|
+
import Dimensions from "$cplatform/dimensions";
|
|
3
|
+
import useStableMemo from "$react/useStableMemo";
|
|
4
|
+
import { useWindowDimensions } from "$cdimensions";
|
|
5
|
+
import {isObj} from "$cutils";
|
|
6
|
+
import { StyleSheet } from "react-native";
|
|
7
|
+
import React from "$react";
|
|
8
|
+
|
|
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
|
+
|
|
43
|
+
/*** permet d'attacher un lister sur la modification des props de manière responsive
|
|
44
|
+
* @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
|
+
*/
|
|
46
|
+
export const getMediaQueryPropsSubscription = (updatePropsWithMediaQuery,hostRef,timeout)=>{
|
|
47
|
+
const cb = mediaQueryUpdateNativePropsCallback(updatePropsWithMediaQuery,hostRef,timeout);
|
|
48
|
+
if(!cb) return null;
|
|
49
|
+
return Dimensions.addEventListener("change",cb);
|
|
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);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/*** met à jour dynamiquemnet les propriétés style d'un objet en fonction du changement de la taille de l'objet
|
|
67
|
+
* @param {useCurrentMedia} {boolean} si true, alors les propriétés sont mis à jour uniquement si le current media change
|
|
68
|
+
@param {mediaQueryUpdateStyle}, la fonction permettant d'obtenir les propriétés css du composant à retourner
|
|
69
|
+
@return {object}, le flatten style des propriétés css associés aux props du composant react l'object
|
|
70
|
+
*/
|
|
71
|
+
export function useMediaQueryUpdateStyle({useCurrentMedia,target,mediaQueryUpdateStyle,...props}){
|
|
72
|
+
if(typeof mediaQueryUpdateStyle !=='function') return props.style;
|
|
73
|
+
const dimensions = useWindowDimensions();
|
|
74
|
+
const handleProps = dimensions && useCurrentMedia === true ? Dimensions.getCurrentMedia() : dimensions;
|
|
75
|
+
return useStableMemo(()=>{
|
|
76
|
+
const args = Dimensions.getDimensionsProps();
|
|
77
|
+
args.props = props,
|
|
78
|
+
args.target = target;
|
|
79
|
+
const nStyle = mediaQueryUpdateStyle(args);
|
|
80
|
+
if(isObj(nStyle) || Array.isArray(nStyle)) return StyleSheet.flatten([props.style,nStyle]);
|
|
81
|
+
return StyleSheet.flatten(props.style)||{};
|
|
82
|
+
},[handleProps,useCurrentMedia,dimensions,props.style]);
|
|
83
|
+
}
|