@umituz/react-native-design-system 4.25.51 → 4.25.53
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.25.
|
|
3
|
+
"version": "4.25.53",
|
|
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",
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Utilities for handling media files (base64, downloads, file operations)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
declare function atob(data: string): string;
|
|
6
|
+
import { base64ToTempFile } from "../../../filesystem/infrastructure/utils/blob.utils";
|
|
7
|
+
import { downloadFile } from "../../../filesystem/infrastructure/services/download.service";
|
|
9
8
|
|
|
10
9
|
interface FileWithType {
|
|
11
10
|
readonly type: string;
|
|
@@ -49,60 +48,23 @@ export const toDataUrl = (str: string): string => {
|
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
/**
|
|
52
|
-
* Save base64 image to file system
|
|
51
|
+
* Save base64 image to file system using internal filesystem service
|
|
53
52
|
*/
|
|
54
53
|
export const saveBase64ToFile = async (base64Data: string): Promise<string> => {
|
|
55
|
-
|
|
56
|
-
const filename = `media_${timestamp}.jpg`;
|
|
57
|
-
const file = new ExpoFile(Paths.cache, filename);
|
|
58
|
-
|
|
59
|
-
const pureBase64 = base64Data.replace(/^data:image\/\w+;base64,/, "");
|
|
60
|
-
const binaryString = atob(pureBase64);
|
|
61
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
62
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
63
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
file.write(bytes);
|
|
67
|
-
return file.uri;
|
|
54
|
+
return base64ToTempFile(base64Data);
|
|
68
55
|
};
|
|
69
56
|
|
|
70
57
|
/**
|
|
71
|
-
* Download media from URL to local file
|
|
58
|
+
* Download media from URL to local file using internal filesystem service
|
|
72
59
|
*/
|
|
73
|
-
export const downloadMediaToFile = async (url: string,
|
|
74
|
-
const
|
|
75
|
-
const extension = isVideo ? "mp4" : "jpg";
|
|
76
|
-
const filename = `media_${timestamp}.${extension}`;
|
|
77
|
-
const file = new ExpoFile(Paths.cache, filename);
|
|
78
|
-
|
|
79
|
-
// Create abort controller for timeout
|
|
80
|
-
const controller = new AbortController();
|
|
81
|
-
const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const response = await fetch(url, { signal: controller.signal });
|
|
85
|
-
clearTimeout(timeoutId);
|
|
86
|
-
|
|
87
|
-
if (!response.ok) {
|
|
88
|
-
throw new Error(`Failed to download media: ${response.statusText}`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
92
|
-
const bytes = new Uint8Array(arrayBuffer);
|
|
93
|
-
file.write(bytes);
|
|
94
|
-
|
|
95
|
-
return file.uri;
|
|
96
|
-
} catch (error) {
|
|
97
|
-
// Clear timeout if error occurs
|
|
98
|
-
clearTimeout(timeoutId);
|
|
60
|
+
export const downloadMediaToFile = async (url: string, _isVideo: boolean): Promise<string> => {
|
|
61
|
+
const result = await downloadFile(url);
|
|
99
62
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
throw error;
|
|
63
|
+
if (!result.success || !result.uri) {
|
|
64
|
+
throw new Error(`Failed to download media: ${result.error ?? "Unknown error"}`);
|
|
105
65
|
}
|
|
66
|
+
|
|
67
|
+
return result.uri;
|
|
106
68
|
};
|
|
107
69
|
|
|
108
70
|
export interface SaveToGalleryResult {
|
|
@@ -112,7 +74,6 @@ export interface SaveToGalleryResult {
|
|
|
112
74
|
|
|
113
75
|
/**
|
|
114
76
|
* Save image to device gallery
|
|
115
|
-
* Downloads from URL if needed, then saves to media library
|
|
116
77
|
*/
|
|
117
78
|
export const saveImageToGallery = async (uri: string): Promise<SaveToGalleryResult> => {
|
|
118
79
|
try {
|
|
@@ -124,7 +85,6 @@ export const saveImageToGallery = async (uri: string): Promise<SaveToGalleryResu
|
|
|
124
85
|
return { success: false, error: "Permission denied" };
|
|
125
86
|
}
|
|
126
87
|
|
|
127
|
-
// Download if URL, otherwise use local path
|
|
128
88
|
const localUri = uri.startsWith("http") ? await downloadMediaToFile(uri, false) : uri;
|
|
129
89
|
await MediaLibrary.saveToLibraryAsync(localUri);
|
|
130
90
|
|