react-simplikit 0.0.53 → 0.2.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/CHANGELOG.md +126 -0
- package/README.md +2 -42
- package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +1 -0
- package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +1 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +1 -0
- package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +1 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +1 -0
- package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +1 -0
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs +24 -6
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.d.cts +17 -7
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.d.mts +17 -7
- package/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs +24 -6
- package/dist/hooks/useDoubleClick/useDoubleClick.cjs +0 -4
- package/dist/hooks/useDoubleClick/useDoubleClick.d.cts +0 -4
- package/dist/hooks/useDoubleClick/useDoubleClick.d.mts +0 -4
- package/dist/hooks/useDoubleClick/useDoubleClick.mjs +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.cjs +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.d.cts +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.d.mts +0 -4
- package/dist/hooks/useGeolocation/useGeolocation.mjs +0 -4
- package/dist/hooks/useImpressionRef/useImpressionRef.cjs +7 -5
- package/dist/hooks/useImpressionRef/useImpressionRef.d.cts +0 -4
- package/dist/hooks/useImpressionRef/useImpressionRef.d.mts +0 -4
- package/dist/hooks/useImpressionRef/useImpressionRef.mjs +7 -5
- package/dist/hooks/useInputState/useInputState.cjs +9 -3
- package/dist/hooks/useInputState/useInputState.d.cts +11 -4
- package/dist/hooks/useInputState/useInputState.d.mts +11 -4
- package/dist/hooks/useInputState/useInputState.mjs +9 -3
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -5
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.d.cts +1 -5
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.d.mts +1 -5
- package/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs +1 -5
- package/dist/hooks/useList/useList.cjs +11 -8
- package/dist/hooks/useList/useList.d.cts +12 -9
- package/dist/hooks/useList/useList.d.mts +12 -9
- package/dist/hooks/useList/useList.mjs +11 -8
- package/dist/hooks/useLoading/useLoading.cjs +3 -5
- package/dist/hooks/useLoading/useLoading.d.cts +2 -5
- package/dist/hooks/useLoading/useLoading.d.mts +2 -5
- package/dist/hooks/useLoading/useLoading.mjs +3 -5
- package/dist/hooks/useLongPress/useLongPress.cjs +0 -4
- package/dist/hooks/useLongPress/useLongPress.d.cts +0 -4
- package/dist/hooks/useLongPress/useLongPress.d.mts +0 -4
- package/dist/hooks/useLongPress/useLongPress.mjs +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.cts +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.mts +0 -4
- package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs +0 -4
- package/dist/hooks/usePreservedReference/usePreservedReference.cjs +1 -0
- package/dist/hooks/usePreservedReference/usePreservedReference.mjs +1 -0
- package/dist/hooks/useRefEffect/useRefEffect.cjs +1 -0
- package/dist/hooks/useRefEffect/useRefEffect.mjs +1 -0
- package/dist/hooks/useSet/useSet.cjs +11 -2
- package/dist/hooks/useSet/useSet.d.cts +11 -2
- package/dist/hooks/useSet/useSet.d.mts +11 -2
- package/dist/hooks/useSet/useSet.mjs +11 -2
- package/dist/hooks/useStorageState/useStorageState.cjs +1 -0
- package/dist/hooks/useStorageState/useStorageState.d.cts +0 -4
- package/dist/hooks/useStorageState/useStorageState.d.mts +0 -4
- package/dist/hooks/useStorageState/useStorageState.mjs +1 -0
- package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +16 -9
- package/dist/hooks/useThrottledCallback/useThrottledCallback.d.cts +18 -11
- package/dist/hooks/useThrottledCallback/useThrottledCallback.d.mts +18 -11
- package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +16 -9
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs +2 -4
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.d.cts +2 -4
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.d.mts +2 -4
- package/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs +2 -4
- package/dist/index.cjs +34 -0
- package/dist/index.d.cts +19 -1
- package/dist/index.d.mts +19 -1
- package/dist/index.mjs +18 -1
- package/dist/mobile/hooks/useAvoidKeyboard/index.d.cts +3 -0
- package/dist/mobile/hooks/useAvoidKeyboard/index.d.mts +3 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.cjs +75 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.d.cts +89 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.d.mts +89 -0
- package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.mjs +75 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.cjs +47 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.d.cts +37 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.d.mts +37 -0
- package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.mjs +47 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.cjs +41 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.d.cts +41 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.d.mts +41 -0
- package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.mjs +41 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.cjs +88 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.d.cts +77 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.d.mts +77 -0
- package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.mjs +88 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.cjs +75 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.d.cts +64 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.d.mts +64 -0
- package/dist/mobile/hooks/usePageVisibility/usePageVisibility.mjs +75 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.cjs +74 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.d.cts +55 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.d.mts +55 -0
- package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.mjs +74 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.cjs +79 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.d.cts +40 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.d.mts +40 -0
- package/dist/mobile/hooks/useScrollDirection/useScrollDirection.mjs +79 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.cjs +77 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.d.cts +89 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.d.mts +89 -0
- package/dist/mobile/hooks/useVisualViewport/useVisualViewport.mjs +77 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.cjs +55 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.d.cts +22 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.d.mts +22 -0
- package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.mjs +55 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.cjs +49 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.d.cts +23 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.d.mts +23 -0
- package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.mjs +49 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.cjs +35 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.d.cts +28 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.d.mts +28 -0
- package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.mjs +35 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.cjs +58 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.d.cts +44 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.d.mts +44 -0
- package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.mjs +58 -0
- package/dist/mobile/utils/isAndroid/isAndroid.cjs +32 -0
- package/dist/mobile/utils/isAndroid/isAndroid.d.cts +27 -0
- package/dist/mobile/utils/isAndroid/isAndroid.d.mts +27 -0
- package/dist/mobile/utils/isAndroid/isAndroid.mjs +32 -0
- package/dist/mobile/utils/isIOS/isIOS.cjs +37 -0
- package/dist/mobile/utils/isIOS/isIOS.d.cts +30 -0
- package/dist/mobile/utils/isIOS/isIOS.d.mts +30 -0
- package/dist/mobile/utils/isIOS/isIOS.mjs +37 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.cjs +28 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.d.cts +25 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.d.mts +25 -0
- package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.mjs +28 -0
- package/dist/mobile/utils/isServer/isServer.cjs +24 -0
- package/dist/mobile/utils/isServer/isServer.d.cts +22 -0
- package/dist/mobile/utils/isServer/isServer.d.mts +22 -0
- package/dist/mobile/utils/isServer/isServer.mjs +24 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.cjs +71 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.d.cts +64 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.d.mts +64 -0
- package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.mjs +71 -0
- package/dist/utils/buildContext/buildContext.cjs +1 -0
- package/dist/utils/buildContext/buildContext.mjs +1 -0
- package/dist/utils/mergeProps/mergeProps.cjs +1 -1
- package/dist/utils/mergeProps/mergeProps.d.cts +1 -1
- package/dist/utils/mergeProps/mergeProps.d.mts +1 -1
- package/dist/utils/mergeProps/mergeProps.mjs +1 -1
- package/dist/utils/mergeRefs/mergeRefs.cjs +1 -1
- package/dist/utils/mergeRefs/mergeRefs.d.cts +1 -1
- package/dist/utils/mergeRefs/mergeRefs.d.mts +1 -1
- package/dist/utils/mergeRefs/mergeRefs.mjs +1 -1
- package/package.json +22 -10
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mobile/hooks/useNetworkStatus/useNetworkStatus.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Effective connection type based on Network Information API
|
|
5
|
+
* @see https://wicg.github.io/netinfo/#effective-connection-types
|
|
6
|
+
*/
|
|
7
|
+
type EffectiveConnectionType = 'slow-2g' | '2g' | '3g' | '4g';
|
|
8
|
+
/**
|
|
9
|
+
* Physical connection type
|
|
10
|
+
* @see https://wicg.github.io/netinfo/#dom-connectiontype
|
|
11
|
+
*/
|
|
12
|
+
type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi' | 'wimax';
|
|
13
|
+
/**
|
|
14
|
+
* Network status information from Network Information API
|
|
15
|
+
*/
|
|
16
|
+
type NetworkStatus = {
|
|
17
|
+
/** Effective connection type (4g, 3g, 2g, slow-2g) - undefined if API not supported */
|
|
18
|
+
effectiveType?: EffectiveConnectionType;
|
|
19
|
+
/** Physical connection type (wifi, cellular, etc.) - undefined if API not supported */
|
|
20
|
+
type?: ConnectionType;
|
|
21
|
+
/** Downlink speed in Mbps - undefined if API not supported */
|
|
22
|
+
downlink?: number;
|
|
23
|
+
/** Round-trip time in milliseconds - undefined if API not supported */
|
|
24
|
+
rtt?: number;
|
|
25
|
+
/** User's data saver preference - undefined if API not supported */
|
|
26
|
+
saveData?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @description
|
|
30
|
+
* `useNetworkStatus` is a React hook that provides access to the Network Information API.
|
|
31
|
+
* It provides raw network connection data. Returns undefined for all properties
|
|
32
|
+
* if the API is not supported (e.g., Safari, Firefox).
|
|
33
|
+
*
|
|
34
|
+
* **Browser Support**:
|
|
35
|
+
* - Chrome/Edge (Android): Full support
|
|
36
|
+
* - Chrome/Edge (Desktop): Partial support (effectiveType, downlink, rtt, saveData)
|
|
37
|
+
* - Firefox: Not supported
|
|
38
|
+
* - Safari: Not supported
|
|
39
|
+
*
|
|
40
|
+
* @returns {NetworkStatus} Network status information
|
|
41
|
+
* - `effectiveType` - Connection quality: 'slow-2g' | '2g' | '3g' | '4g'
|
|
42
|
+
* - `type` - Physical connection: 'wifi' | 'cellular' | 'ethernet' | etc.
|
|
43
|
+
* - `downlink` - Downlink speed in Mbps
|
|
44
|
+
* - `rtt` - Round-trip time in milliseconds
|
|
45
|
+
* - `saveData` - User's data saver preference
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* function AdaptiveImage() {
|
|
49
|
+
* const { effectiveType, saveData } = useNetworkStatus();
|
|
50
|
+
*
|
|
51
|
+
* // Determine quality based on your app's needs
|
|
52
|
+
* const useHighQuality = effectiveType === '4g' && !saveData;
|
|
53
|
+
*
|
|
54
|
+
* return (
|
|
55
|
+
* <img
|
|
56
|
+
* src={useHighQuality ? 'high-res.jpg' : 'low-res.jpg'}
|
|
57
|
+
* alt="Content"
|
|
58
|
+
* />
|
|
59
|
+
* );
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* function VideoPlayer() {
|
|
64
|
+
* const { type, downlink } = useNetworkStatus();
|
|
65
|
+
*
|
|
66
|
+
* // Custom logic: only autoplay on wifi with good bandwidth
|
|
67
|
+
* const shouldAutoplay = type === 'wifi' && (downlink ?? 0) > 5;
|
|
68
|
+
*
|
|
69
|
+
* return <video src="video.mp4" autoPlay={shouldAutoplay} />;
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* @see https://wicg.github.io/netinfo/
|
|
73
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
|
|
74
|
+
*/
|
|
75
|
+
declare function useNetworkStatus(): NetworkStatus;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { ConnectionType, EffectiveConnectionType, NetworkStatus, useNetworkStatus };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mobile/hooks/useNetworkStatus/useNetworkStatus.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Effective connection type based on Network Information API
|
|
5
|
+
* @see https://wicg.github.io/netinfo/#effective-connection-types
|
|
6
|
+
*/
|
|
7
|
+
type EffectiveConnectionType = 'slow-2g' | '2g' | '3g' | '4g';
|
|
8
|
+
/**
|
|
9
|
+
* Physical connection type
|
|
10
|
+
* @see https://wicg.github.io/netinfo/#dom-connectiontype
|
|
11
|
+
*/
|
|
12
|
+
type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi' | 'wimax';
|
|
13
|
+
/**
|
|
14
|
+
* Network status information from Network Information API
|
|
15
|
+
*/
|
|
16
|
+
type NetworkStatus = {
|
|
17
|
+
/** Effective connection type (4g, 3g, 2g, slow-2g) - undefined if API not supported */
|
|
18
|
+
effectiveType?: EffectiveConnectionType;
|
|
19
|
+
/** Physical connection type (wifi, cellular, etc.) - undefined if API not supported */
|
|
20
|
+
type?: ConnectionType;
|
|
21
|
+
/** Downlink speed in Mbps - undefined if API not supported */
|
|
22
|
+
downlink?: number;
|
|
23
|
+
/** Round-trip time in milliseconds - undefined if API not supported */
|
|
24
|
+
rtt?: number;
|
|
25
|
+
/** User's data saver preference - undefined if API not supported */
|
|
26
|
+
saveData?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @description
|
|
30
|
+
* `useNetworkStatus` is a React hook that provides access to the Network Information API.
|
|
31
|
+
* It provides raw network connection data. Returns undefined for all properties
|
|
32
|
+
* if the API is not supported (e.g., Safari, Firefox).
|
|
33
|
+
*
|
|
34
|
+
* **Browser Support**:
|
|
35
|
+
* - Chrome/Edge (Android): Full support
|
|
36
|
+
* - Chrome/Edge (Desktop): Partial support (effectiveType, downlink, rtt, saveData)
|
|
37
|
+
* - Firefox: Not supported
|
|
38
|
+
* - Safari: Not supported
|
|
39
|
+
*
|
|
40
|
+
* @returns {NetworkStatus} Network status information
|
|
41
|
+
* - `effectiveType` - Connection quality: 'slow-2g' | '2g' | '3g' | '4g'
|
|
42
|
+
* - `type` - Physical connection: 'wifi' | 'cellular' | 'ethernet' | etc.
|
|
43
|
+
* - `downlink` - Downlink speed in Mbps
|
|
44
|
+
* - `rtt` - Round-trip time in milliseconds
|
|
45
|
+
* - `saveData` - User's data saver preference
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* function AdaptiveImage() {
|
|
49
|
+
* const { effectiveType, saveData } = useNetworkStatus();
|
|
50
|
+
*
|
|
51
|
+
* // Determine quality based on your app's needs
|
|
52
|
+
* const useHighQuality = effectiveType === '4g' && !saveData;
|
|
53
|
+
*
|
|
54
|
+
* return (
|
|
55
|
+
* <img
|
|
56
|
+
* src={useHighQuality ? 'high-res.jpg' : 'low-res.jpg'}
|
|
57
|
+
* alt="Content"
|
|
58
|
+
* />
|
|
59
|
+
* );
|
|
60
|
+
* }
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* function VideoPlayer() {
|
|
64
|
+
* const { type, downlink } = useNetworkStatus();
|
|
65
|
+
*
|
|
66
|
+
* // Custom logic: only autoplay on wifi with good bandwidth
|
|
67
|
+
* const shouldAutoplay = type === 'wifi' && (downlink ?? 0) > 5;
|
|
68
|
+
*
|
|
69
|
+
* return <video src="video.mp4" autoPlay={shouldAutoplay} />;
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* @see https://wicg.github.io/netinfo/
|
|
73
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
|
|
74
|
+
*/
|
|
75
|
+
declare function useNetworkStatus(): NetworkStatus;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { ConnectionType, EffectiveConnectionType, NetworkStatus, useNetworkStatus };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isServer } from "../../utils/isServer/isServer.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
//#region src/mobile/hooks/useNetworkStatus/useNetworkStatus.ts
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* `useNetworkStatus` is a React hook that provides access to the Network Information API.
|
|
8
|
+
* It provides raw network connection data. Returns undefined for all properties
|
|
9
|
+
* if the API is not supported (e.g., Safari, Firefox).
|
|
10
|
+
*
|
|
11
|
+
* **Browser Support**:
|
|
12
|
+
* - Chrome/Edge (Android): Full support
|
|
13
|
+
* - Chrome/Edge (Desktop): Partial support (effectiveType, downlink, rtt, saveData)
|
|
14
|
+
* - Firefox: Not supported
|
|
15
|
+
* - Safari: Not supported
|
|
16
|
+
*
|
|
17
|
+
* @returns {NetworkStatus} Network status information
|
|
18
|
+
* - `effectiveType` - Connection quality: 'slow-2g' | '2g' | '3g' | '4g'
|
|
19
|
+
* - `type` - Physical connection: 'wifi' | 'cellular' | 'ethernet' | etc.
|
|
20
|
+
* - `downlink` - Downlink speed in Mbps
|
|
21
|
+
* - `rtt` - Round-trip time in milliseconds
|
|
22
|
+
* - `saveData` - User's data saver preference
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* function AdaptiveImage() {
|
|
26
|
+
* const { effectiveType, saveData } = useNetworkStatus();
|
|
27
|
+
*
|
|
28
|
+
* // Determine quality based on your app's needs
|
|
29
|
+
* const useHighQuality = effectiveType === '4g' && !saveData;
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <img
|
|
33
|
+
* src={useHighQuality ? 'high-res.jpg' : 'low-res.jpg'}
|
|
34
|
+
* alt="Content"
|
|
35
|
+
* />
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* function VideoPlayer() {
|
|
41
|
+
* const { type, downlink } = useNetworkStatus();
|
|
42
|
+
*
|
|
43
|
+
* // Custom logic: only autoplay on wifi with good bandwidth
|
|
44
|
+
* const shouldAutoplay = type === 'wifi' && (downlink ?? 0) > 5;
|
|
45
|
+
*
|
|
46
|
+
* return <video src="video.mp4" autoPlay={shouldAutoplay} />;
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* @see https://wicg.github.io/netinfo/
|
|
50
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
|
|
51
|
+
*/
|
|
52
|
+
function useNetworkStatus() {
|
|
53
|
+
const [networkStatus, setNetworkStatus] = useState(getNetworkStatus);
|
|
54
|
+
useEffect(function subscribeToNetworkChanges() {
|
|
55
|
+
if (isServer()) return;
|
|
56
|
+
const connection = getNavigatorConnection();
|
|
57
|
+
if (connection == null) return;
|
|
58
|
+
function updateNetworkStatus() {
|
|
59
|
+
setNetworkStatus(getNetworkStatus());
|
|
60
|
+
}
|
|
61
|
+
connection.addEventListener("change", updateNetworkStatus);
|
|
62
|
+
return function cleanup() {
|
|
63
|
+
connection.removeEventListener("change", updateNetworkStatus);
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
return networkStatus;
|
|
67
|
+
}
|
|
68
|
+
function getNavigatorConnection() {
|
|
69
|
+
if (isServer() || !("connection" in navigator)) return null;
|
|
70
|
+
try {
|
|
71
|
+
return navigator.connection ?? null;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function getNetworkStatus() {
|
|
77
|
+
const connection = getNavigatorConnection();
|
|
78
|
+
if (connection == null) return {};
|
|
79
|
+
return {
|
|
80
|
+
effectiveType: connection.effectiveType,
|
|
81
|
+
type: connection.type,
|
|
82
|
+
downlink: connection.downlink,
|
|
83
|
+
rtt: connection.rtt,
|
|
84
|
+
saveData: connection.saveData
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { useNetworkStatus };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_isServer = require("../../utils/isServer/isServer.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
//#region src/mobile/hooks/usePageVisibility/usePageVisibility.ts
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* `usePageVisibility` is a React hook that detects page visibility changes.
|
|
8
|
+
* It monitors when the user switches tabs or minimizes the browser using the Page Visibility API.
|
|
9
|
+
* Useful for pausing/resuming animations, videos, or background tasks.
|
|
10
|
+
*
|
|
11
|
+
* **SSR Behavior**: Returns `{ isVisible: true, visibilityState: 'visible' }` during server-side rendering.
|
|
12
|
+
*
|
|
13
|
+
* @see `useVisibilityEvent` runs a callback on each change instead of returning state.
|
|
14
|
+
*
|
|
15
|
+
* @returns {PageVisibility} Page visibility information
|
|
16
|
+
* - `isVisible` - True if page is currently visible to the user
|
|
17
|
+
* - `visibilityState` - Current visibility state: 'visible' | 'hidden'
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* function VideoPlayer() {
|
|
21
|
+
* const { isVisible } = usePageVisibility();
|
|
22
|
+
* const videoRef = useRef<HTMLVideoElement>(null);
|
|
23
|
+
*
|
|
24
|
+
* useEffect(() => {
|
|
25
|
+
* if (!videoRef.current) return;
|
|
26
|
+
*
|
|
27
|
+
* // Pause video when tab is hidden
|
|
28
|
+
* if (!isVisible) {
|
|
29
|
+
* videoRef.current.pause();
|
|
30
|
+
* }
|
|
31
|
+
* }, [isVisible]);
|
|
32
|
+
*
|
|
33
|
+
* return <video ref={videoRef} src="video.mp4" />;
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* function Analytics() {
|
|
38
|
+
* const { isVisible, visibilityState } = usePageVisibility();
|
|
39
|
+
*
|
|
40
|
+
* useEffect(() => {
|
|
41
|
+
* if (visibilityState === 'hidden') {
|
|
42
|
+
* // Track when user leaves the page
|
|
43
|
+
* analytics.track('page_hidden');
|
|
44
|
+
* }
|
|
45
|
+
* }, [visibilityState]);
|
|
46
|
+
*
|
|
47
|
+
* return null;
|
|
48
|
+
* }
|
|
49
|
+
*/
|
|
50
|
+
function usePageVisibility() {
|
|
51
|
+
const [pageVisibility, setPageVisibility] = (0, react.useState)(() => getPageVisibility());
|
|
52
|
+
(0, react.useEffect)(function handleVisibilityChange() {
|
|
53
|
+
function updateVisibility() {
|
|
54
|
+
setPageVisibility(() => getPageVisibility());
|
|
55
|
+
}
|
|
56
|
+
document.addEventListener("visibilitychange", updateVisibility);
|
|
57
|
+
return function cleanup() {
|
|
58
|
+
document.removeEventListener("visibilitychange", updateVisibility);
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
return pageVisibility;
|
|
62
|
+
}
|
|
63
|
+
function getPageVisibility() {
|
|
64
|
+
if (require_isServer.isServer()) return {
|
|
65
|
+
isVisible: true,
|
|
66
|
+
visibilityState: "visible"
|
|
67
|
+
};
|
|
68
|
+
const visibilityState = document.visibilityState;
|
|
69
|
+
return {
|
|
70
|
+
isVisible: visibilityState === "visible",
|
|
71
|
+
visibilityState
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.usePageVisibility = usePageVisibility;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mobile/hooks/usePageVisibility/usePageVisibility.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Page visibility state derived from browser's DocumentVisibilityState.
|
|
5
|
+
* Excludes 'prerender' as it is deprecated and not used in modern browsers.
|
|
6
|
+
*/
|
|
7
|
+
type VisibilityState = Exclude<DocumentVisibilityState, 'prerender'>;
|
|
8
|
+
/**
|
|
9
|
+
* Page visibility information
|
|
10
|
+
*/
|
|
11
|
+
type PageVisibility = {
|
|
12
|
+
/** True if page is currently visible */
|
|
13
|
+
isVisible: boolean;
|
|
14
|
+
/** Current visibility state: 'visible' | 'hidden' */
|
|
15
|
+
visibilityState: VisibilityState;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @description
|
|
19
|
+
* `usePageVisibility` is a React hook that detects page visibility changes.
|
|
20
|
+
* It monitors when the user switches tabs or minimizes the browser using the Page Visibility API.
|
|
21
|
+
* Useful for pausing/resuming animations, videos, or background tasks.
|
|
22
|
+
*
|
|
23
|
+
* **SSR Behavior**: Returns `{ isVisible: true, visibilityState: 'visible' }` during server-side rendering.
|
|
24
|
+
*
|
|
25
|
+
* @see `useVisibilityEvent` runs a callback on each change instead of returning state.
|
|
26
|
+
*
|
|
27
|
+
* @returns {PageVisibility} Page visibility information
|
|
28
|
+
* - `isVisible` - True if page is currently visible to the user
|
|
29
|
+
* - `visibilityState` - Current visibility state: 'visible' | 'hidden'
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* function VideoPlayer() {
|
|
33
|
+
* const { isVisible } = usePageVisibility();
|
|
34
|
+
* const videoRef = useRef<HTMLVideoElement>(null);
|
|
35
|
+
*
|
|
36
|
+
* useEffect(() => {
|
|
37
|
+
* if (!videoRef.current) return;
|
|
38
|
+
*
|
|
39
|
+
* // Pause video when tab is hidden
|
|
40
|
+
* if (!isVisible) {
|
|
41
|
+
* videoRef.current.pause();
|
|
42
|
+
* }
|
|
43
|
+
* }, [isVisible]);
|
|
44
|
+
*
|
|
45
|
+
* return <video ref={videoRef} src="video.mp4" />;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* function Analytics() {
|
|
50
|
+
* const { isVisible, visibilityState } = usePageVisibility();
|
|
51
|
+
*
|
|
52
|
+
* useEffect(() => {
|
|
53
|
+
* if (visibilityState === 'hidden') {
|
|
54
|
+
* // Track when user leaves the page
|
|
55
|
+
* analytics.track('page_hidden');
|
|
56
|
+
* }
|
|
57
|
+
* }, [visibilityState]);
|
|
58
|
+
*
|
|
59
|
+
* return null;
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
62
|
+
declare function usePageVisibility(): PageVisibility;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { PageVisibility, VisibilityState, usePageVisibility };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mobile/hooks/usePageVisibility/usePageVisibility.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Page visibility state derived from browser's DocumentVisibilityState.
|
|
5
|
+
* Excludes 'prerender' as it is deprecated and not used in modern browsers.
|
|
6
|
+
*/
|
|
7
|
+
type VisibilityState = Exclude<DocumentVisibilityState, 'prerender'>;
|
|
8
|
+
/**
|
|
9
|
+
* Page visibility information
|
|
10
|
+
*/
|
|
11
|
+
type PageVisibility = {
|
|
12
|
+
/** True if page is currently visible */
|
|
13
|
+
isVisible: boolean;
|
|
14
|
+
/** Current visibility state: 'visible' | 'hidden' */
|
|
15
|
+
visibilityState: VisibilityState;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @description
|
|
19
|
+
* `usePageVisibility` is a React hook that detects page visibility changes.
|
|
20
|
+
* It monitors when the user switches tabs or minimizes the browser using the Page Visibility API.
|
|
21
|
+
* Useful for pausing/resuming animations, videos, or background tasks.
|
|
22
|
+
*
|
|
23
|
+
* **SSR Behavior**: Returns `{ isVisible: true, visibilityState: 'visible' }` during server-side rendering.
|
|
24
|
+
*
|
|
25
|
+
* @see `useVisibilityEvent` runs a callback on each change instead of returning state.
|
|
26
|
+
*
|
|
27
|
+
* @returns {PageVisibility} Page visibility information
|
|
28
|
+
* - `isVisible` - True if page is currently visible to the user
|
|
29
|
+
* - `visibilityState` - Current visibility state: 'visible' | 'hidden'
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* function VideoPlayer() {
|
|
33
|
+
* const { isVisible } = usePageVisibility();
|
|
34
|
+
* const videoRef = useRef<HTMLVideoElement>(null);
|
|
35
|
+
*
|
|
36
|
+
* useEffect(() => {
|
|
37
|
+
* if (!videoRef.current) return;
|
|
38
|
+
*
|
|
39
|
+
* // Pause video when tab is hidden
|
|
40
|
+
* if (!isVisible) {
|
|
41
|
+
* videoRef.current.pause();
|
|
42
|
+
* }
|
|
43
|
+
* }, [isVisible]);
|
|
44
|
+
*
|
|
45
|
+
* return <video ref={videoRef} src="video.mp4" />;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* function Analytics() {
|
|
50
|
+
* const { isVisible, visibilityState } = usePageVisibility();
|
|
51
|
+
*
|
|
52
|
+
* useEffect(() => {
|
|
53
|
+
* if (visibilityState === 'hidden') {
|
|
54
|
+
* // Track when user leaves the page
|
|
55
|
+
* analytics.track('page_hidden');
|
|
56
|
+
* }
|
|
57
|
+
* }, [visibilityState]);
|
|
58
|
+
*
|
|
59
|
+
* return null;
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
62
|
+
declare function usePageVisibility(): PageVisibility;
|
|
63
|
+
//#endregion
|
|
64
|
+
export { PageVisibility, VisibilityState, usePageVisibility };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { isServer } from "../../utils/isServer/isServer.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
//#region src/mobile/hooks/usePageVisibility/usePageVisibility.ts
|
|
5
|
+
/**
|
|
6
|
+
* @description
|
|
7
|
+
* `usePageVisibility` is a React hook that detects page visibility changes.
|
|
8
|
+
* It monitors when the user switches tabs or minimizes the browser using the Page Visibility API.
|
|
9
|
+
* Useful for pausing/resuming animations, videos, or background tasks.
|
|
10
|
+
*
|
|
11
|
+
* **SSR Behavior**: Returns `{ isVisible: true, visibilityState: 'visible' }` during server-side rendering.
|
|
12
|
+
*
|
|
13
|
+
* @see `useVisibilityEvent` runs a callback on each change instead of returning state.
|
|
14
|
+
*
|
|
15
|
+
* @returns {PageVisibility} Page visibility information
|
|
16
|
+
* - `isVisible` - True if page is currently visible to the user
|
|
17
|
+
* - `visibilityState` - Current visibility state: 'visible' | 'hidden'
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* function VideoPlayer() {
|
|
21
|
+
* const { isVisible } = usePageVisibility();
|
|
22
|
+
* const videoRef = useRef<HTMLVideoElement>(null);
|
|
23
|
+
*
|
|
24
|
+
* useEffect(() => {
|
|
25
|
+
* if (!videoRef.current) return;
|
|
26
|
+
*
|
|
27
|
+
* // Pause video when tab is hidden
|
|
28
|
+
* if (!isVisible) {
|
|
29
|
+
* videoRef.current.pause();
|
|
30
|
+
* }
|
|
31
|
+
* }, [isVisible]);
|
|
32
|
+
*
|
|
33
|
+
* return <video ref={videoRef} src="video.mp4" />;
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* function Analytics() {
|
|
38
|
+
* const { isVisible, visibilityState } = usePageVisibility();
|
|
39
|
+
*
|
|
40
|
+
* useEffect(() => {
|
|
41
|
+
* if (visibilityState === 'hidden') {
|
|
42
|
+
* // Track when user leaves the page
|
|
43
|
+
* analytics.track('page_hidden');
|
|
44
|
+
* }
|
|
45
|
+
* }, [visibilityState]);
|
|
46
|
+
*
|
|
47
|
+
* return null;
|
|
48
|
+
* }
|
|
49
|
+
*/
|
|
50
|
+
function usePageVisibility() {
|
|
51
|
+
const [pageVisibility, setPageVisibility] = useState(() => getPageVisibility());
|
|
52
|
+
useEffect(function handleVisibilityChange() {
|
|
53
|
+
function updateVisibility() {
|
|
54
|
+
setPageVisibility(() => getPageVisibility());
|
|
55
|
+
}
|
|
56
|
+
document.addEventListener("visibilitychange", updateVisibility);
|
|
57
|
+
return function cleanup() {
|
|
58
|
+
document.removeEventListener("visibilitychange", updateVisibility);
|
|
59
|
+
};
|
|
60
|
+
}, []);
|
|
61
|
+
return pageVisibility;
|
|
62
|
+
}
|
|
63
|
+
function getPageVisibility() {
|
|
64
|
+
if (isServer()) return {
|
|
65
|
+
isVisible: true,
|
|
66
|
+
visibilityState: "visible"
|
|
67
|
+
};
|
|
68
|
+
const visibilityState = document.visibilityState;
|
|
69
|
+
return {
|
|
70
|
+
isVisible: visibilityState === "visible",
|
|
71
|
+
visibilityState
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { usePageVisibility };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_isServer = require("../../utils/isServer/isServer.cjs");
|
|
3
|
+
const require_getSafeAreaInset = require("../../utils/getSafeAreaInset/getSafeAreaInset.cjs");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
//#region src/mobile/hooks/useSafeAreaInset/useSafeAreaInset.ts
|
|
6
|
+
/**
|
|
7
|
+
* @description
|
|
8
|
+
* `useSafeAreaInset` is a React hook that tracks safe area inset changes.
|
|
9
|
+
* It returns the safe area insets that automatically update when the screen
|
|
10
|
+
* orientation changes (e.g., portrait to landscape).
|
|
11
|
+
*
|
|
12
|
+
* Safe area insets account for device-specific UI elements:
|
|
13
|
+
* - **top**: Notch, Dynamic Island, or status bar
|
|
14
|
+
* - **bottom**: Home indicator on Face ID devices
|
|
15
|
+
* - **left/right**: Rounded corners in landscape mode
|
|
16
|
+
*
|
|
17
|
+
* @returns {SafeAreaInset} An object containing safe area insets for all four sides.
|
|
18
|
+
* - top `number` - Top safe area inset in pixels. Accounts for the notch, Dynamic Island, or status bar;
|
|
19
|
+
* - bottom `number` - Bottom safe area inset in pixels. Accounts for the home indicator on Face ID devices;
|
|
20
|
+
* - left `number` - Left safe area inset in pixels. Accounts for rounded corners in landscape mode;
|
|
21
|
+
* - right `number` - Right safe area inset in pixels. Accounts for rounded corners in landscape mode;
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* function MyComponent() {
|
|
25
|
+
* const safeArea = useSafeAreaInset();
|
|
26
|
+
*
|
|
27
|
+
* return (
|
|
28
|
+
* <div style={{
|
|
29
|
+
* paddingTop: safeArea.top,
|
|
30
|
+
* paddingBottom: safeArea.bottom,
|
|
31
|
+
* paddingLeft: safeArea.left,
|
|
32
|
+
* paddingRight: safeArea.right,
|
|
33
|
+
* }}>
|
|
34
|
+
* Content that respects safe areas
|
|
35
|
+
* </div>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Automatically updates when screen rotates
|
|
41
|
+
* function RotationAwareHeader() {
|
|
42
|
+
* const { top, left, right } = useSafeAreaInset();
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <header style={{
|
|
46
|
+
* paddingTop: top,
|
|
47
|
+
* paddingLeft: left,
|
|
48
|
+
* paddingRight: right,
|
|
49
|
+
* }}>
|
|
50
|
+
* Header content
|
|
51
|
+
* </header>
|
|
52
|
+
* );
|
|
53
|
+
* }
|
|
54
|
+
*/
|
|
55
|
+
function useSafeAreaInset() {
|
|
56
|
+
const [inset, setInset] = (0, react.useState)(() => require_getSafeAreaInset.getSafeAreaInset());
|
|
57
|
+
const updateInset = (0, react.useCallback)(() => {
|
|
58
|
+
(0, react.startTransition)(() => {
|
|
59
|
+
setInset(require_getSafeAreaInset.getSafeAreaInset());
|
|
60
|
+
});
|
|
61
|
+
}, []);
|
|
62
|
+
(0, react.useEffect)(function handleOrientationChange() {
|
|
63
|
+
if (require_isServer.isServer()) return;
|
|
64
|
+
window.addEventListener("resize", updateInset);
|
|
65
|
+
window.addEventListener("orientationchange", updateInset);
|
|
66
|
+
return function cleanup() {
|
|
67
|
+
window.removeEventListener("resize", updateInset);
|
|
68
|
+
window.removeEventListener("orientationchange", updateInset);
|
|
69
|
+
};
|
|
70
|
+
}, [updateInset]);
|
|
71
|
+
return inset;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.useSafeAreaInset = useSafeAreaInset;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
import { SafeAreaInset } from "../../utils/getSafeAreaInset/getSafeAreaInset.cjs";
|
|
3
|
+
//#region src/mobile/hooks/useSafeAreaInset/useSafeAreaInset.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* `useSafeAreaInset` is a React hook that tracks safe area inset changes.
|
|
7
|
+
* It returns the safe area insets that automatically update when the screen
|
|
8
|
+
* orientation changes (e.g., portrait to landscape).
|
|
9
|
+
*
|
|
10
|
+
* Safe area insets account for device-specific UI elements:
|
|
11
|
+
* - **top**: Notch, Dynamic Island, or status bar
|
|
12
|
+
* - **bottom**: Home indicator on Face ID devices
|
|
13
|
+
* - **left/right**: Rounded corners in landscape mode
|
|
14
|
+
*
|
|
15
|
+
* @returns {SafeAreaInset} An object containing safe area insets for all four sides.
|
|
16
|
+
* - top `number` - Top safe area inset in pixels. Accounts for the notch, Dynamic Island, or status bar;
|
|
17
|
+
* - bottom `number` - Bottom safe area inset in pixels. Accounts for the home indicator on Face ID devices;
|
|
18
|
+
* - left `number` - Left safe area inset in pixels. Accounts for rounded corners in landscape mode;
|
|
19
|
+
* - right `number` - Right safe area inset in pixels. Accounts for rounded corners in landscape mode;
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* function MyComponent() {
|
|
23
|
+
* const safeArea = useSafeAreaInset();
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <div style={{
|
|
27
|
+
* paddingTop: safeArea.top,
|
|
28
|
+
* paddingBottom: safeArea.bottom,
|
|
29
|
+
* paddingLeft: safeArea.left,
|
|
30
|
+
* paddingRight: safeArea.right,
|
|
31
|
+
* }}>
|
|
32
|
+
* Content that respects safe areas
|
|
33
|
+
* </div>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Automatically updates when screen rotates
|
|
39
|
+
* function RotationAwareHeader() {
|
|
40
|
+
* const { top, left, right } = useSafeAreaInset();
|
|
41
|
+
*
|
|
42
|
+
* return (
|
|
43
|
+
* <header style={{
|
|
44
|
+
* paddingTop: top,
|
|
45
|
+
* paddingLeft: left,
|
|
46
|
+
* paddingRight: right,
|
|
47
|
+
* }}>
|
|
48
|
+
* Header content
|
|
49
|
+
* </header>
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
declare function useSafeAreaInset(): SafeAreaInset;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { useSafeAreaInset };
|