@umituz/react-native-design-system 4.23.128 → 4.24.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": "@umituz/react-native-design-system",
3
- "version": "4.23.128",
3
+ "version": "4.24.0",
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",
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Gallery Download Service
3
+ * Single Responsibility: Download remote media to local storage
4
+ */
5
+
6
+ import { FileSystemService } from "../filesystem";
7
+ import { validateImageUri, getFileExtension } from "../image";
8
+ import { timezoneService } from "../timezone";
9
+ import type { DownloadMediaResult } from "./types";
10
+
11
+ const generateFilename = (uri: string, prefix: string): string => {
12
+ const extension = getFileExtension(uri) || "jpg";
13
+ const timestamp = timezoneService.formatDateToString(new Date());
14
+ const randomId = Math.random().toString(36).substring(2, 10);
15
+ return `${prefix}_${timestamp}_${randomId}.${extension}`;
16
+ };
17
+
18
+ class GalleryDownloadService {
19
+ async downloadMedia(
20
+ mediaUri: string,
21
+ prefix: string = "media",
22
+ ): Promise<DownloadMediaResult> {
23
+ try {
24
+ const validationResult = validateImageUri(mediaUri, "Media");
25
+ if (!validationResult.isValid) {
26
+ return {
27
+ success: false,
28
+ error: validationResult.error || "Invalid media file",
29
+ };
30
+ }
31
+
32
+ const filename = generateFilename(mediaUri, prefix);
33
+ const documentDir = FileSystemService.getDocumentDirectory();
34
+ const fileUri = `${documentDir}${filename}`;
35
+
36
+ const downloadResult = await FileSystemService.downloadFile(
37
+ mediaUri,
38
+ fileUri,
39
+ );
40
+
41
+ if (!downloadResult.success || !downloadResult.uri) {
42
+ return {
43
+ success: false,
44
+ error: downloadResult.error || "Download failed",
45
+ };
46
+ }
47
+
48
+ return {
49
+ success: true,
50
+ localUri: downloadResult.uri,
51
+ };
52
+ } catch (error) {
53
+ return {
54
+ success: false,
55
+ error: error instanceof Error ? error.message : "Download failed",
56
+ };
57
+ }
58
+ }
59
+
60
+ isRemoteUrl(uri: string): boolean {
61
+ return uri.startsWith("http://") || uri.startsWith("https://");
62
+ }
63
+
64
+ async cleanupFile(fileUri: string): Promise<void> {
65
+ await FileSystemService.deleteFile(fileUri);
66
+ }
67
+ }
68
+
69
+ export const galleryDownloadService = new GalleryDownloadService();
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Gallery Save Service
3
+ * Single Responsibility: Save media to device gallery
4
+ */
5
+
6
+ import * as MediaLibrary from "expo-media-library";
7
+ import { validateImageUri } from "../image";
8
+ import { galleryDownloadService } from "./gallery-download.service";
9
+ import type { SaveMediaResult } from "./types";
10
+
11
+ const requestMediaPermissions = async (): Promise<boolean> => {
12
+ try {
13
+ const { status } = await MediaLibrary.requestPermissionsAsync();
14
+ return status === "granted";
15
+ } catch {
16
+ return false;
17
+ }
18
+ };
19
+
20
+ class GallerySaveService {
21
+ async saveToGallery(
22
+ mediaUri: string,
23
+ prefix?: string,
24
+ ): Promise<SaveMediaResult> {
25
+ try {
26
+ const validationResult = validateImageUri(mediaUri, "Media");
27
+ if (!validationResult.isValid) {
28
+ return {
29
+ success: false,
30
+ error: validationResult.error || "Invalid media file",
31
+ };
32
+ }
33
+
34
+ const hasPermission = await requestMediaPermissions();
35
+ if (!hasPermission) {
36
+ return {
37
+ success: false,
38
+ error: "Media library permission denied",
39
+ };
40
+ }
41
+
42
+ let localUri = mediaUri;
43
+ const isRemote = galleryDownloadService.isRemoteUrl(mediaUri);
44
+
45
+ if (isRemote) {
46
+ const downloadResult = await galleryDownloadService.downloadMedia(
47
+ mediaUri,
48
+ prefix,
49
+ );
50
+
51
+ if (!downloadResult.success || !downloadResult.localUri) {
52
+ return {
53
+ success: false,
54
+ error: downloadResult.error || "Download failed",
55
+ };
56
+ }
57
+
58
+ localUri = downloadResult.localUri;
59
+ }
60
+
61
+ const asset = await MediaLibrary.createAssetAsync(localUri);
62
+
63
+ if (isRemote && localUri) {
64
+ await galleryDownloadService.cleanupFile(localUri);
65
+ }
66
+
67
+ return {
68
+ success: true,
69
+ fileUri: asset.uri,
70
+ };
71
+ } catch (error) {
72
+ return {
73
+ success: false,
74
+ error: error instanceof Error ? error.message : "Save failed",
75
+ };
76
+ }
77
+ }
78
+ }
79
+
80
+ export const gallerySaveService = new GallerySaveService();
@@ -0,0 +1,3 @@
1
+ export { gallerySaveService } from "./gallery-save.service";
2
+ export { galleryDownloadService } from "./gallery-download.service";
3
+ export type { SaveMediaResult, DownloadMediaResult } from "./types";
@@ -0,0 +1,11 @@
1
+ export interface SaveMediaResult {
2
+ success: boolean;
3
+ fileUri?: string;
4
+ error?: string;
5
+ }
6
+
7
+ export interface DownloadMediaResult {
8
+ success: boolean;
9
+ localUri?: string;
10
+ error?: string;
11
+ }
package/src/index.ts CHANGED
@@ -147,3 +147,8 @@ export * from "./loading";
147
147
  // INIT EXPORTS
148
148
  // =============================================================================
149
149
  export * from "./init";
150
+
151
+ // =============================================================================
152
+ // GALLERY EXPORTS
153
+ // =============================================================================
154
+ export * from "./gallery";