@umituz/react-native-design-system 4.23.105 → 4.23.106

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": "@umituz/react-native-design-system",
3
- "version": "4.23.105",
3
+ "version": "4.23.106",
4
4
  "description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, onboarding, and loading utilities",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -30,7 +30,12 @@ export async function downloadFile(url: string, dest?: string): Promise<FileOper
30
30
  } catch (e: unknown) { return { success: false, error: e instanceof Error ? e.message : String(e) }; }
31
31
  }
32
32
 
33
- export async function downloadFileWithProgress(url: string, cacheDir: string, onProgress?: DownloadProgressCallback): Promise<DownloadWithProgressResult> {
33
+ export async function downloadFileWithProgress(
34
+ url: string,
35
+ cacheDir: string,
36
+ onProgress?: DownloadProgressCallback,
37
+ signal?: AbortSignal
38
+ ): Promise<DownloadWithProgressResult> {
34
39
  try {
35
40
  const dir = new Directory(cacheDir);
36
41
  if (!dir.exists) dir.create({ intermediates: true, idempotent: true });
@@ -38,9 +43,9 @@ export async function downloadFileWithProgress(url: string, cacheDir: string, on
38
43
  const destUri = getCacheUri(url, cacheDir);
39
44
  if (new File(destUri).exists) return { success: true, uri: destUri, fromCache: true };
40
45
 
41
- const response = await fetch(url);
46
+ const response = await fetch(url, { signal });
42
47
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
43
-
48
+
44
49
  const totalBytes = parseInt(response.headers.get("content-length") || "0", 10);
45
50
  if (!response.body) return { ...(await downloadFile(url, destUri)), fromCache: false };
46
51
 
@@ -48,20 +53,29 @@ export async function downloadFileWithProgress(url: string, cacheDir: string, on
48
53
  const chunks: Uint8Array[] = [];
49
54
  let received = 0;
50
55
 
51
- while (true) {
52
- const { done, value } = await reader.read();
53
- if (done) break;
54
- chunks.push(value);
55
- received += value.length;
56
- onProgress?.({ totalBytesWritten: received, totalBytesExpectedToWrite: totalBytes || received });
57
- }
56
+ try {
57
+ while (true) {
58
+ if (signal?.aborted) {
59
+ await reader.cancel();
60
+ throw new Error("Download aborted");
61
+ }
58
62
 
59
- const all = new Uint8Array(received);
60
- let pos = 0;
61
- for (const c of chunks) { all.set(c, pos); pos += c.length; }
62
- new File(destUri).write(all);
63
+ const { done, value } = await reader.read();
64
+ if (done) break;
65
+ chunks.push(value);
66
+ received += value.length;
67
+ onProgress?.({ totalBytesWritten: received, totalBytesExpectedToWrite: totalBytes || received });
68
+ }
63
69
 
64
- return { success: true, uri: destUri, fromCache: false };
70
+ const all = new Uint8Array(received);
71
+ let pos = 0;
72
+ for (const c of chunks) { all.set(c, pos); pos += c.length; }
73
+ new File(destUri).write(all);
74
+
75
+ return { success: true, uri: destUri, fromCache: false };
76
+ } finally {
77
+ reader.releaseLock();
78
+ }
65
79
  } catch (e: unknown) { return { success: false, error: e instanceof Error ? e.message : String(e) }; }
66
80
  }
67
81
 
@@ -40,7 +40,7 @@ export function useAppInitialization(
40
40
  useEffect(() => {
41
41
  onReadyRef.current = onReady;
42
42
  onErrorRef.current = onError;
43
- });
43
+ }, [onReady, onError]);
44
44
 
45
45
  useEffect(() => {
46
46
  if (skip) {