@fto-consult/expo-ui 6.86.1 → 6.87.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "6.86.1",
3
+ "version": "6.87.0",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "main",
6
6
  "scripts": {
@@ -1,11 +1,10 @@
1
-
2
-
3
1
  import Dimensions from "$cplatform/dimensions";
4
2
  import useStableMemo from "$react/useStableMemo";
5
3
  import { useWindowDimensions } from "$cdimensions";
6
- import {isObj,isNonNullString} from "$cutils";
4
+ import {isObj,isNonNullString,extendObj} from "$cutils";
7
5
  import { StyleSheet } from "react-native";
8
6
  import { createContext,useContext as useReactContext } from "react";
7
+ import _useSWR from "$swr";
9
8
 
10
9
  export const ExpoUIContext = createContext(null);
11
10
 
@@ -17,6 +16,30 @@ export const useContext = useExpoUI;
17
16
 
18
17
  export const useApp = useContext;
19
18
 
19
+ export const useSWR = (path,options)=>{
20
+ const {swrConfig} = useExpoUI();
21
+ const host = `${defaultStr(process.env.API_HOST).trim().rtrim("/")}/${path}`;
22
+ const isLocalHost = host.includes("127.0.0.1") || host.includes("localhost");
23
+ return _useSWR(path,{
24
+ checkOnline : !isLocalHost,
25
+ ...Object.assign({},options),
26
+ swrOptions : {
27
+ provider: () => new Map(),
28
+ ...swrConfig,
29
+ isOnline() {
30
+ if(isLocalHost) return true;
31
+ return swrConfig.isOnline();
32
+ },
33
+ initReconnect(cb) {
34
+ if(isLocalHost) return cb();
35
+ return swrConfig.initReconnect(cb);
36
+ },
37
+ ...extendObj({},options,options?.swrOptions)
38
+ }
39
+ })
40
+ }
41
+
42
+
20
43
  /**** retourne un composant définit dans la props
21
44
  components de la fonction registerApp appelée pour l'initialisation de l'application
22
45
  @param {string} componentName : le nom du composant que l'on veut recupérer