@akbeniwal/react-native-hooks 1.0.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.
Files changed (70) hide show
  1. package/README.md +235 -0
  2. package/dist/hooks/useAfterInteractions.d.ts +10 -0
  3. package/dist/hooks/useAfterInteractions.d.ts.map +1 -0
  4. package/dist/hooks/useAfterInteractions.js +28 -0
  5. package/dist/hooks/useAfterInteractions.js.map +1 -0
  6. package/dist/hooks/useAppState.d.ts +17 -0
  7. package/dist/hooks/useAppState.d.ts.map +1 -0
  8. package/dist/hooks/useAppState.js +36 -0
  9. package/dist/hooks/useAppState.js.map +1 -0
  10. package/dist/hooks/useBackHandler.d.ts +7 -0
  11. package/dist/hooks/useBackHandler.d.ts.map +1 -0
  12. package/dist/hooks/useBackHandler.js +21 -0
  13. package/dist/hooks/useBackHandler.js.map +1 -0
  14. package/dist/hooks/useClipboard.d.ts +19 -0
  15. package/dist/hooks/useClipboard.d.ts.map +1 -0
  16. package/dist/hooks/useClipboard.js +44 -0
  17. package/dist/hooks/useClipboard.js.map +1 -0
  18. package/dist/hooks/useCountdown.d.ts +24 -0
  19. package/dist/hooks/useCountdown.d.ts.map +1 -0
  20. package/dist/hooks/useCountdown.js +67 -0
  21. package/dist/hooks/useCountdown.js.map +1 -0
  22. package/dist/hooks/useDebounce.d.ts +12 -0
  23. package/dist/hooks/useDebounce.d.ts.map +1 -0
  24. package/dist/hooks/useDebounce.js +29 -0
  25. package/dist/hooks/useDebounce.js.map +1 -0
  26. package/dist/hooks/useDeviceOrientation.d.ts +10 -0
  27. package/dist/hooks/useDeviceOrientation.d.ts.map +1 -0
  28. package/dist/hooks/useDeviceOrientation.js +33 -0
  29. package/dist/hooks/useDeviceOrientation.js.map +1 -0
  30. package/dist/hooks/useDoubleTapToExit.d.ts +17 -0
  31. package/dist/hooks/useDoubleTapToExit.d.ts.map +1 -0
  32. package/dist/hooks/useDoubleTapToExit.js +40 -0
  33. package/dist/hooks/useDoubleTapToExit.js.map +1 -0
  34. package/dist/hooks/useInterval.d.ts +10 -0
  35. package/dist/hooks/useInterval.d.ts.map +1 -0
  36. package/dist/hooks/useInterval.js +27 -0
  37. package/dist/hooks/useInterval.js.map +1 -0
  38. package/dist/hooks/useKeyboard.d.ts +23 -0
  39. package/dist/hooks/useKeyboard.d.ts.map +1 -0
  40. package/dist/hooks/useKeyboard.js +46 -0
  41. package/dist/hooks/useKeyboard.js.map +1 -0
  42. package/dist/hooks/useLayout.d.ts +19 -0
  43. package/dist/hooks/useLayout.d.ts.map +1 -0
  44. package/dist/hooks/useLayout.js +29 -0
  45. package/dist/hooks/useLayout.js.map +1 -0
  46. package/dist/hooks/useNetworkStatus.d.ts +45 -0
  47. package/dist/hooks/useNetworkStatus.d.ts.map +1 -0
  48. package/dist/hooks/useNetworkStatus.js +184 -0
  49. package/dist/hooks/useNetworkStatus.js.map +1 -0
  50. package/dist/hooks/usePrevious.d.ts +9 -0
  51. package/dist/hooks/usePrevious.d.ts.map +1 -0
  52. package/dist/hooks/usePrevious.js +16 -0
  53. package/dist/hooks/usePrevious.js.map +1 -0
  54. package/dist/hooks/useThrottle.d.ts +12 -0
  55. package/dist/hooks/useThrottle.d.ts.map +1 -0
  56. package/dist/hooks/useThrottle.js +47 -0
  57. package/dist/hooks/useThrottle.js.map +1 -0
  58. package/dist/hooks/useTimeout.d.ts +10 -0
  59. package/dist/hooks/useTimeout.d.ts.map +1 -0
  60. package/dist/hooks/useTimeout.js +27 -0
  61. package/dist/hooks/useTimeout.js.map +1 -0
  62. package/dist/hooks/useToggle.d.ts +19 -0
  63. package/dist/hooks/useToggle.d.ts.map +1 -0
  64. package/dist/hooks/useToggle.js +38 -0
  65. package/dist/hooks/useToggle.js.map +1 -0
  66. package/dist/index.d.ts +17 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +17 -0
  69. package/dist/index.js.map +1 -0
  70. package/package.json +52 -0
package/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # react-native-hooks ⚡
2
+
3
+ A high-performance, lightweight, and type-safe collection of **16 custom React Native hooks** optimized for performance, memory-leak prevention, and smooth 60fps UX.
4
+
5
+ ---
6
+
7
+ ## Key Features 🌟
8
+
9
+ * **Zero-Dependency `useNetworkStatus`**: Monitor internet reachability, ping latency, connection quality, and measure download speed in Mbps without bloating your bundle size.
10
+ * **Android-Specific Back Button Hooks**: Custom hooks for back-press events and standard "Double-Tap to Exit" Toast notifications.
11
+ * **Optimized Performance**: Internal callbacks are isolated inside `useRef` to prevent system listeners (keyboard, dimensions, back-handlers, app-states) from registering and tearing down repeatedly.
12
+ * **TypeScript Ready**: Fully typed out-of-the-box with auto-generated declaration maps.
13
+ * **Cross-Platform**: Support for Android, iOS, and React Native Web.
14
+
15
+ ---
16
+
17
+ ## Installation 📦
18
+
19
+ ```bash
20
+ npm install react-native-hooks
21
+ # or
22
+ yarn add react-native-hooks
23
+ ```
24
+
25
+ ---
26
+
27
+ ## Table of Hooks 📚
28
+
29
+ | Hook | Purpose | Platform |
30
+ | :--- | :--- | :--- |
31
+ | [`useAppState`](#useappstate) | Tracks active/inactive/background app focus states with callbacks. | iOS, Android, Web |
32
+ | [`useBackHandler`](#usebackhandler) | Android physical/virtual hardware back button press. | Android |
33
+ | [`useClipboard`](#useclipboard) | Reads & writes to the system clipboard with copied feedback callback. | iOS, Android, Web |
34
+ | [`useCountdown`](#usecountdown) | Full-featured countdown timer with pause, reset, and tick callbacks. | iOS, Android, Web |
35
+ | [`useDebounce`](#usedebounce) | Debounces state values with optional change triggers. | iOS, Android, Web |
36
+ | [`useKeyboard`](#usekeyboard) | Tracks virtual keyboard display status and dynamic height. | iOS, Android |
37
+ | [`useNetworkStatus`](#usenetworkstatus) | Monitors internet connection, latency, speed test in Mbps, and offline alerts. | iOS, Android, Web |
38
+ | [`usePrevious`](#useprevious) | Accesses the value of a state/prop from the previous render. | iOS, Android, Web |
39
+ | [`useThrottle`](#usethrottle) | Throttles state update changes. | iOS, Android, Web |
40
+ | [`useToggle`](#usetoggle) | Simple state toggle with `onChange`, `onTrue`, and `onFalse` callbacks. | iOS, Android, Web |
41
+ | [`useAfterInteractions`](#useafterinteractions) | Defers execution of tasks until layout transition animations finish. | iOS, Android |
42
+ | [`useLayout`](#uselayout) | Measures dynamic sizing and screen positions of views. | iOS, Android, Web |
43
+ | [`useDoubleTapToExit`](#usedoubletaptoexit) | Prompts and exits app only on double-pressing Android back button. | Android |
44
+ | [`useDeviceOrientation`](#usedeviceorientation) | Tracks rotation and current orientation status (`PORTRAIT` / `LANDSCAPE`). | iOS, Android, Web |
45
+ | [`useInterval`](#useinterval) | Declarative version of `setInterval` (prevents stale state closures). | iOS, Android, Web |
46
+ | [`useTimeout`](#usetimeout) | Declarative version of `setTimeout` (cleans up automatically on unmount). | iOS, Android, Web |
47
+
48
+ ---
49
+
50
+ ## Quick Usage Reference 💡
51
+
52
+ ### useAppState
53
+ ```tsx
54
+ import { useAppState } from 'react-native-hooks';
55
+
56
+ const appState = useAppState({
57
+ onForeground: () => console.log('App entered foreground!'),
58
+ onBackground: () => console.log('App entered background!'),
59
+ });
60
+ ```
61
+
62
+ ### useBackHandler
63
+ ```tsx
64
+ import { useBackHandler } from 'react-native-hooks';
65
+
66
+ useBackHandler(() => {
67
+ // Return true to prevent default back action
68
+ if (hasUnsavedChanges) {
69
+ showExitAlert();
70
+ return true;
71
+ }
72
+ return false;
73
+ });
74
+ ```
75
+
76
+ ### useClipboard
77
+ ```tsx
78
+ import { useClipboard } from 'react-native-hooks';
79
+
80
+ const [clipboardData, setString] = useClipboard({
81
+ onCopy: (text) => console.log(`Copied "${text}" to clipboard!`),
82
+ });
83
+ ```
84
+
85
+ ### useCountdown
86
+ ```tsx
87
+ import { useCountdown } from 'react-native-hooks';
88
+
89
+ const { seconds, isActive, start, pause, reset } = useCountdown({
90
+ initialSeconds: 60,
91
+ onExpire: () => alert('OTP expired!'),
92
+ onTick: (secs) => console.log(`${secs} seconds remaining`),
93
+ });
94
+ ```
95
+
96
+ ### useDebounce
97
+ ```tsx
98
+ import { useDebounce } from 'react-native-hooks';
99
+
100
+ const [searchQuery, setSearchQuery] = useState('');
101
+ const debouncedQuery = useDebounce(searchQuery, 500, (value) => {
102
+ fetchSearchResults(value);
103
+ });
104
+ ```
105
+
106
+ ### useKeyboard
107
+ ```tsx
108
+ import { useKeyboard } from 'react-native-hooks';
109
+
110
+ const { keyboardShown, keyboardHeight } = useKeyboard({
111
+ onShow: (height) => console.log(`Keyboard visible with height: ${height}`),
112
+ onHide: () => console.log('Keyboard hidden'),
113
+ });
114
+ ```
115
+
116
+ ### useNetworkStatus
117
+ ```tsx
118
+ import { useNetworkStatus } from 'react-native-hooks';
119
+
120
+ const {
121
+ isConnected,
122
+ isInternetReachable,
123
+ latencyMs,
124
+ connectionQuality,
125
+ internetSpeed,
126
+ isTestingSpeed,
127
+ runSpeedTest
128
+ } = useNetworkStatus({
129
+ pingIntervalMs: 30000, // Ping Google every 30 seconds
130
+ onOnline: () => console.log('Back online! syncing database...'),
131
+ onOffline: () => console.log('Network connection lost!'),
132
+ });
133
+ ```
134
+
135
+ ### usePrevious
136
+ ```tsx
137
+ import { usePrevious } from 'react-native-hooks';
138
+
139
+ const [count, setCount] = useState(0);
140
+ const prevCount = usePrevious(count); // returns count from previous render
141
+ ```
142
+
143
+ ### useThrottle
144
+ ```tsx
145
+ import { useThrottle } from 'react-native-hooks';
146
+
147
+ const throttledScrollY = useThrottle(scrollY, 100);
148
+ ```
149
+
150
+ ### useToggle
151
+ ```tsx
152
+ import { useToggle } from 'react-native-hooks';
153
+
154
+ const [isModalOpen, toggleModal] = useToggle(false, {
155
+ onTrue: () => console.log('Modal Opened'),
156
+ onFalse: () => console.log('Modal Closed'),
157
+ });
158
+ ```
159
+
160
+ ### useAfterInteractions
161
+ ```tsx
162
+ import { useAfterInteractions } from 'react-native-hooks';
163
+
164
+ const interactionsFinished = useAfterInteractions(() => {
165
+ loadExpensiveChartData();
166
+ });
167
+ ```
168
+
169
+ ### useLayout
170
+ ```tsx
171
+ import { useLayout } from 'react-native-hooks';
172
+ import { View } from 'react-native';
173
+
174
+ const [layout, onLayout] = useLayout({
175
+ onChange: (metrics) => console.log('New layout:', metrics),
176
+ });
177
+
178
+ return <View onLayout={onLayout} />;
179
+ ```
180
+
181
+ ### useDoubleTapToExit
182
+ ```tsx
183
+ import { useDoubleTapToExit } from 'react-native-hooks';
184
+
185
+ // Setup on Android
186
+ useDoubleTapToExit('Press back button again to exit the app.');
187
+ ```
188
+
189
+ ### useDeviceOrientation
190
+ ```tsx
191
+ import { useDeviceOrientation } from 'react-native-hooks';
192
+
193
+ const orientation = useDeviceOrientation((currentOrientation) => {
194
+ console.log('Orientation changed to:', currentOrientation);
195
+ });
196
+ ```
197
+
198
+ ### useInterval
199
+ ```tsx
200
+ import { useInterval } from 'react-native-hooks';
201
+
202
+ useInterval(() => {
203
+ // Increments or processes state safely without stale closures
204
+ tickCounter();
205
+ }, isPaused ? null : 1000);
206
+ ```
207
+
208
+ ### useTimeout
209
+ ```tsx
210
+ import { useTimeout } from 'react-native-hooks';
211
+
212
+ useTimeout(() => {
213
+ dismissBanner();
214
+ }, 5000);
215
+ ```
216
+
217
+ ---
218
+
219
+ ## Development & Building 🛠️
220
+
221
+ ```bash
222
+ # Build the typescript files into JavaScript and TypeScript Definitions (under /dist)
223
+ yarn build
224
+ ```
225
+
226
+ ## Author 👤
227
+
228
+ **Abhishek Beniwal**
229
+ - GitHub: [@AKBeniwal1700](https://github.com/AKBeniwal1700)
230
+
231
+ ---
232
+
233
+ ## License 📄
234
+
235
+ This project is licensed under the MIT License.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A custom React Native hook that defers execution of intensive tasks or rendering
3
+ * until after navigation transitions or animations have completed.
4
+ * Helps in achieving 60fps / lag-free screen navigation transitions.
5
+ *
6
+ * @param callback Optional callback triggered immediately when transitions/animations complete
7
+ * @returns A boolean indicating if transition interactions have completed
8
+ */
9
+ export declare function useAfterInteractions(callback?: () => void): boolean;
10
+ //# sourceMappingURL=useAfterInteractions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAfterInteractions.d.ts","sourceRoot":"","sources":["../../src/hooks/useAfterInteractions.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAoBnE"}
@@ -0,0 +1,28 @@
1
+ import { useEffect, useState, useRef } from 'react';
2
+ import { InteractionManager } from 'react-native';
3
+ /**
4
+ * A custom React Native hook that defers execution of intensive tasks or rendering
5
+ * until after navigation transitions or animations have completed.
6
+ * Helps in achieving 60fps / lag-free screen navigation transitions.
7
+ *
8
+ * @param callback Optional callback triggered immediately when transitions/animations complete
9
+ * @returns A boolean indicating if transition interactions have completed
10
+ */
11
+ export function useAfterInteractions(callback) {
12
+ const [areInteractionsComplete, setComplete] = useState(false);
13
+ const callbackRef = useRef(callback);
14
+ callbackRef.current = callback;
15
+ useEffect(() => {
16
+ const task = InteractionManager.runAfterInteractions(() => {
17
+ setComplete(true);
18
+ if (callbackRef.current) {
19
+ callbackRef.current();
20
+ }
21
+ });
22
+ return () => {
23
+ task.cancel();
24
+ };
25
+ }, []);
26
+ return areInteractionsComplete;
27
+ }
28
+ //# sourceMappingURL=useAfterInteractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAfterInteractions.js","sourceRoot":"","sources":["../../src/hooks/useAfterInteractions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAqB;IACxD,MAAM,CAAC,uBAAuB,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAExE,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,IAAI,GAAG,kBAAkB,CAAC,oBAAoB,CAAC,GAAG,EAAE;YACxD,WAAW,CAAC,IAAI,CAAC,CAAC;YAClB,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;gBACxB,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,uBAAuB,CAAC;AACjC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { AppStateStatus } from 'react-native';
2
+ export interface UseAppStateOptions {
3
+ /** Callback triggered whenever the AppState changes */
4
+ onChange?: (status: AppStateStatus) => void;
5
+ /** Callback triggered when the application enters the foreground (active) */
6
+ onForeground?: () => void;
7
+ /** Callback triggered when the application enters the background or becomes inactive */
8
+ onBackground?: () => void;
9
+ }
10
+ /**
11
+ * A custom React Native hook to track the application's current AppState.
12
+ *
13
+ * @param options Callback options for AppState transitions
14
+ * @returns The current AppStateStatus ('active' | 'background' | 'inactive')
15
+ */
16
+ export declare function useAppState(options?: UseAppStateOptions): AppStateStatus;
17
+ //# sourceMappingURL=useAppState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAppState.d.ts","sourceRoot":"","sources":["../../src/hooks/useAppState.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,cAAc,EAAE,MAAM,cAAc,CAAC;AAExD,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC5C,6EAA6E;IAC7E,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,wFAAwF;IACxF,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,cAAc,CAkCxE"}
@@ -0,0 +1,36 @@
1
+ import { useEffect, useState, useRef } from 'react';
2
+ import { AppState } from 'react-native';
3
+ /**
4
+ * A custom React Native hook to track the application's current AppState.
5
+ *
6
+ * @param options Callback options for AppState transitions
7
+ * @returns The current AppStateStatus ('active' | 'background' | 'inactive')
8
+ */
9
+ export function useAppState(options) {
10
+ const [appState, setAppState] = useState(AppState.currentState);
11
+ // Store options in refs to prevent unnecessary re-subscriptions on options reference changes.
12
+ const optionsRef = useRef(options);
13
+ optionsRef.current = options;
14
+ useEffect(() => {
15
+ const subscription = AppState.addEventListener('change', (nextAppState) => {
16
+ const currentOptions = optionsRef.current;
17
+ const prevAppState = appState;
18
+ setAppState(nextAppState);
19
+ if (currentOptions?.onChange) {
20
+ currentOptions.onChange(nextAppState);
21
+ }
22
+ if (nextAppState === 'active' && prevAppState !== 'active') {
23
+ currentOptions?.onForeground?.();
24
+ }
25
+ else if ((nextAppState === 'background' || nextAppState === 'inactive') &&
26
+ prevAppState === 'active') {
27
+ currentOptions?.onBackground?.();
28
+ }
29
+ });
30
+ return () => {
31
+ subscription.remove();
32
+ };
33
+ }, [appState]);
34
+ return appState;
35
+ }
36
+ //# sourceMappingURL=useAppState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAppState.js","sourceRoot":"","sources":["../../src/hooks/useAppState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAkB,MAAM,cAAc,CAAC;AAWxD;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAA4B;IACtD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAiB,QAAQ,CAAC,YAAY,CAAC,CAAC;IAEhF,8FAA8F;IAC9F,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,YAAY,EAAE,EAAE;YACxE,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC;YAC1C,MAAM,YAAY,GAAG,QAAQ,CAAC;YAE9B,WAAW,CAAC,YAAY,CAAC,CAAC;YAE1B,IAAI,cAAc,EAAE,QAAQ,EAAE,CAAC;gBAC7B,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;YAED,IAAI,YAAY,KAAK,QAAQ,IAAI,YAAY,KAAK,QAAQ,EAAE,CAAC;gBAC3D,cAAc,EAAE,YAAY,EAAE,EAAE,CAAC;YACnC,CAAC;iBAAM,IACL,CAAC,YAAY,KAAK,YAAY,IAAI,YAAY,KAAK,UAAU,CAAC;gBAC9D,YAAY,KAAK,QAAQ,EACzB,CAAC;gBACD,cAAc,EAAE,YAAY,EAAE,EAAE,CAAC;YACnC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A custom React Native hook to handle Android hardware back button presses.
3
+ *
4
+ * @param handler Callback function. Returning `true` from this handler prevents the default back button behavior (e.g., exiting the app). Returning `false` allows the default behavior to proceed.
5
+ */
6
+ export declare function useBackHandler(handler: () => boolean): void;
7
+ //# sourceMappingURL=useBackHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBackHandler.d.ts","sourceRoot":"","sources":["../../src/hooks/useBackHandler.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAe3D"}
@@ -0,0 +1,21 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { BackHandler } from 'react-native';
3
+ /**
4
+ * A custom React Native hook to handle Android hardware back button presses.
5
+ *
6
+ * @param handler Callback function. Returning `true` from this handler prevents the default back button behavior (e.g., exiting the app). Returning `false` allows the default behavior to proceed.
7
+ */
8
+ export function useBackHandler(handler) {
9
+ const handlerRef = useRef(handler);
10
+ handlerRef.current = handler;
11
+ useEffect(() => {
12
+ const onBackPress = () => {
13
+ return handlerRef.current();
14
+ };
15
+ const subscription = BackHandler.addEventListener('hardwareBackPress', onBackPress);
16
+ return () => {
17
+ subscription.remove();
18
+ };
19
+ }, []);
20
+ }
21
+ //# sourceMappingURL=useBackHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBackHandler.js","sourceRoot":"","sources":["../../src/hooks/useBackHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAsB;IACnD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,OAAO,UAAU,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC,CAAC;QAEF,MAAM,YAAY,GAAG,WAAW,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;QAEpF,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
@@ -0,0 +1,19 @@
1
+ export interface UseClipboardOptions {
2
+ /** Callback triggered when text is successfully copied to the system clipboard via setString */
3
+ onCopy?: (text: string) => void;
4
+ }
5
+ /**
6
+ * A custom React Native hook to interact with the system clipboard.
7
+ *
8
+ * @param options Configurable options, including an onCopy callback
9
+ * @returns A read-only tuple containing:
10
+ * - `clipboardData`: The current string content of the clipboard.
11
+ * - `setString`: A memoized function to write content to the clipboard.
12
+ * - `getString`: A memoized function to manually refresh and fetch content from the clipboard.
13
+ */
14
+ export declare function useClipboard(options?: UseClipboardOptions): readonly [
15
+ string,
16
+ (text: string) => void,
17
+ () => Promise<string>
18
+ ];
19
+ //# sourceMappingURL=useClipboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClipboard.d.ts","sourceRoot":"","sources":["../../src/hooks/useClipboard.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,mBAAmB;IAClC,gGAAgG;IAChG,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS;IACpE,MAAM;IACN,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;IACtB,MAAM,OAAO,CAAC,MAAM,CAAC;CACtB,CAkCA"}
@@ -0,0 +1,44 @@
1
+ import { useState, useCallback, useEffect, useRef } from 'react';
2
+ import Clipboard from '@react-native-clipboard/clipboard';
3
+ /**
4
+ * A custom React Native hook to interact with the system clipboard.
5
+ *
6
+ * @param options Configurable options, including an onCopy callback
7
+ * @returns A read-only tuple containing:
8
+ * - `clipboardData`: The current string content of the clipboard.
9
+ * - `setString`: A memoized function to write content to the clipboard.
10
+ * - `getString`: A memoized function to manually refresh and fetch content from the clipboard.
11
+ */
12
+ export function useClipboard(options) {
13
+ const [clipboardData, setClipboardData] = useState('');
14
+ const optionsRef = useRef(options);
15
+ optionsRef.current = options;
16
+ const getString = useCallback(async () => {
17
+ try {
18
+ const text = await Clipboard.getString();
19
+ setClipboardData(text);
20
+ return text;
21
+ }
22
+ catch (error) {
23
+ console.warn('Failed to retrieve content from system clipboard:', error);
24
+ return '';
25
+ }
26
+ }, []);
27
+ const setString = useCallback((text) => {
28
+ try {
29
+ Clipboard.setString(text);
30
+ setClipboardData(text);
31
+ if (optionsRef.current?.onCopy) {
32
+ optionsRef.current.onCopy(text);
33
+ }
34
+ }
35
+ catch (error) {
36
+ console.warn('Failed to set content to system clipboard:', error);
37
+ }
38
+ }, []);
39
+ useEffect(() => {
40
+ getString();
41
+ }, [getString]);
42
+ return [clipboardData, setString, getString];
43
+ }
44
+ //# sourceMappingURL=useClipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClipboard.js","sourceRoot":"","sources":["../../src/hooks/useClipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,SAAS,MAAM,mCAAmC,CAAC;AAO1D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,OAA6B;IAKxD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAS,EAAE,CAAC,CAAC;IAE/D,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,IAAqB,EAAE;QACxD,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,SAAS,EAAE,CAAC;YACzC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,mDAAmD,EAAE,KAAK,CAAC,CAAC;YACzE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,IAAY,EAAQ,EAAE;QACnD,IAAI,CAAC;YACH,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC1B,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;gBAC/B,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,EAAE,CAAC;IACd,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CAAC,aAAa,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AACxD,CAAC"}
@@ -0,0 +1,24 @@
1
+ export interface UseCountdownOptions {
2
+ /** The starting countdown time in seconds */
3
+ initialSeconds: number;
4
+ /** The countdown tick interval in milliseconds (defaults to 1000ms) */
5
+ intervalMs?: number;
6
+ /** Callback triggered when the countdown reaches 0 */
7
+ onExpire?: () => void;
8
+ /** Callback triggered on every tick, receiving the seconds remaining */
9
+ onTick?: (secondsRemaining: number) => void;
10
+ }
11
+ /**
12
+ * A custom React Native hook to manage a countdown timer.
13
+ *
14
+ * @param options Countdown configuration options
15
+ * @returns Object containing countdown state and control functions
16
+ */
17
+ export declare function useCountdown({ initialSeconds, intervalMs, onExpire, onTick, }: UseCountdownOptions): {
18
+ seconds: number;
19
+ isActive: boolean;
20
+ start: () => void;
21
+ pause: () => void;
22
+ reset: (newInitialSeconds?: number) => void;
23
+ };
24
+ //# sourceMappingURL=useCountdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCountdown.d.ts","sourceRoot":"","sources":["../../src/hooks/useCountdown.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,wEAAwE;IACxE,MAAM,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EAC3B,cAAc,EACd,UAAiB,EACjB,QAAQ,EACR,MAAM,GACP,EAAE,mBAAmB;;;iBAWU,IAAI;iBAIJ,IAAI;gCASX,MAAM,KAAG,IAAI;EA6CrC"}
@@ -0,0 +1,67 @@
1
+ import { useState, useEffect, useRef, useCallback } from 'react';
2
+ /**
3
+ * A custom React Native hook to manage a countdown timer.
4
+ *
5
+ * @param options Countdown configuration options
6
+ * @returns Object containing countdown state and control functions
7
+ */
8
+ export function useCountdown({ initialSeconds, intervalMs = 1000, onExpire, onTick, }) {
9
+ const [seconds, setSeconds] = useState(initialSeconds);
10
+ const [isActive, setIsActive] = useState(false);
11
+ const timerRef = useRef(null);
12
+ // Store callbacks in refs to prevent timer re-creation when callbacks change.
13
+ const onExpireRef = useRef(onExpire);
14
+ const onTickRef = useRef(onTick);
15
+ onExpireRef.current = onExpire;
16
+ onTickRef.current = onTick;
17
+ const start = useCallback(() => {
18
+ setIsActive(true);
19
+ }, []);
20
+ const pause = useCallback(() => {
21
+ setIsActive(false);
22
+ if (timerRef.current) {
23
+ clearInterval(timerRef.current);
24
+ timerRef.current = null;
25
+ }
26
+ }, []);
27
+ const reset = useCallback((newInitialSeconds) => {
28
+ setIsActive(false);
29
+ if (timerRef.current) {
30
+ clearInterval(timerRef.current);
31
+ timerRef.current = null;
32
+ }
33
+ setSeconds(newInitialSeconds !== undefined ? newInitialSeconds : initialSeconds);
34
+ }, [initialSeconds]);
35
+ useEffect(() => {
36
+ if (!isActive)
37
+ return;
38
+ timerRef.current = setInterval(() => {
39
+ setSeconds((prev) => {
40
+ if (prev <= 1) {
41
+ setIsActive(false);
42
+ if (timerRef.current) {
43
+ clearInterval(timerRef.current);
44
+ timerRef.current = null;
45
+ }
46
+ if (onExpireRef.current) {
47
+ onExpireRef.current();
48
+ }
49
+ return 0;
50
+ }
51
+ const nextVal = prev - 1;
52
+ if (onTickRef.current) {
53
+ onTickRef.current(nextVal);
54
+ }
55
+ return nextVal;
56
+ });
57
+ }, intervalMs);
58
+ return () => {
59
+ if (timerRef.current) {
60
+ clearInterval(timerRef.current);
61
+ timerRef.current = null;
62
+ }
63
+ };
64
+ }, [isActive, intervalMs]);
65
+ return { seconds, isActive, start, pause, reset };
66
+ }
67
+ //# sourceMappingURL=useCountdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCountdown.js","sourceRoot":"","sources":["../../src/hooks/useCountdown.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A custom React Native hook to debounce a state value change.
3
+ * Optionally triggers an onChange callback when the debounced value updates.
4
+ *
5
+ * @template T The type of the value to debounce
6
+ * @param value The value to be debounced
7
+ * @param delay The delay in milliseconds
8
+ * @param onChange Optional callback triggered with the new debounced value
9
+ * @returns The debounced value
10
+ */
11
+ export declare function useDebounce<T>(value: T, delay: number, onChange?: (value: T) => void): T;
12
+ //# sourceMappingURL=useDebounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.d.ts","sourceRoot":"","sources":["../../src/hooks/useDebounce.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAC5B,CAAC,CAoBH"}
@@ -0,0 +1,29 @@
1
+ import { useState, useEffect, useRef } from 'react';
2
+ /**
3
+ * A custom React Native hook to debounce a state value change.
4
+ * Optionally triggers an onChange callback when the debounced value updates.
5
+ *
6
+ * @template T The type of the value to debounce
7
+ * @param value The value to be debounced
8
+ * @param delay The delay in milliseconds
9
+ * @param onChange Optional callback triggered with the new debounced value
10
+ * @returns The debounced value
11
+ */
12
+ export function useDebounce(value, delay, onChange) {
13
+ const [debouncedValue, setDebouncedValue] = useState(value);
14
+ const onChangeRef = useRef(onChange);
15
+ onChangeRef.current = onChange;
16
+ useEffect(() => {
17
+ const handler = setTimeout(() => {
18
+ setDebouncedValue(value);
19
+ if (onChangeRef.current) {
20
+ onChangeRef.current(value);
21
+ }
22
+ }, delay);
23
+ return () => {
24
+ clearTimeout(handler);
25
+ };
26
+ }, [value, delay]);
27
+ return debouncedValue;
28
+ }
29
+ //# sourceMappingURL=useDebounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../../src/hooks/useDebounce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CACzB,KAAQ,EACR,KAAa,EACb,QAA6B;IAE7B,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAI,KAAK,CAAC,CAAC;IAE/D,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,iBAAiB,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;gBACxB,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;QAEV,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export type Orientation = 'PORTRAIT' | 'LANDSCAPE';
2
+ /**
3
+ * A custom React Native hook that monitors and returns the device orientation dynamically.
4
+ * Updates on device rotation or dimension changes, and optionally fires an onChange callback.
5
+ *
6
+ * @param onChange Optional callback triggered when the orientation changes, receiving the new orientation
7
+ * @returns The current orientation status ('PORTRAIT' | 'LANDSCAPE')
8
+ */
9
+ export declare function useDeviceOrientation(onChange?: (orientation: Orientation) => void): Orientation;
10
+ //# sourceMappingURL=useDeviceOrientation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDeviceOrientation.d.ts","sourceRoot":"","sources":["../../src/hooks/useDeviceOrientation.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,GAC5C,WAAW,CA8Bb"}