react-native-my-uploader-android 1.0.31 → 1.0.37

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.
@@ -1,18 +1,23 @@
1
1
  import React, { useState } from 'react';
2
- import { TouchableOpacity, Text, StyleSheet, ActivityIndicator,NativeModules } from 'react-native';
2
+ import {
3
+ TouchableOpacity,
4
+ Text,
5
+ StyleSheet,
6
+ ActivityIndicator,
7
+ NativeModules,
8
+ Alert,
9
+ } from 'react-native';
3
10
  import type { DownloadFileProps, DownloadResult } from '../types';
4
11
 
12
+ const { DownloadFileModule } = NativeModules;
5
13
 
6
- const { DownloadFile: NativeDownload } = NativeModules;
7
-
8
-
9
- const DownloadFile: React.FC<DownloadFileProps> = ({
14
+ export const DownloadFile: React.FC<DownloadFileProps> = ({
10
15
  files,
11
16
  multipleDownload = false,
12
17
  disabled = false,
13
18
  debug = false,
14
19
  maxSize = 0,
15
- fileTypes = ['*/*'],
20
+ fileTypes = [],
16
21
  buttonPlaceHolder = 'Dosyaları İndir',
17
22
  buttonIcon,
18
23
  ButtonStyle,
@@ -22,35 +27,102 @@ const DownloadFile: React.FC<DownloadFileProps> = ({
22
27
  }) => {
23
28
  const [isLoading, setIsLoading] = useState(false);
24
29
 
30
+ if (!DownloadFileModule) {
31
+ console.warn("DownloadFileModule bulunamadı. Native tarafın kurulduğundan emin olun.");
32
+ return null;
33
+ }
34
+
35
+ const NativeDownloadModuleWrapper = (
36
+ url: string,
37
+ options: any
38
+ ): Promise<string> => {
39
+ // 🔥 Kotlin Promise metoduyla birebir uyumlu
40
+ return DownloadFileModule.downloadFile(url, options);
41
+ };
42
+
25
43
  const handlePress = async () => {
26
44
  if (disabled || isLoading || !files.length) return;
27
45
  setIsLoading(true);
28
46
 
29
47
  const options = { debug, maxSize, fileTypes };
30
- const targetFiles = multipleDownload ? files : [files[0]];
48
+
49
+ // ✅ undefined güvenli
50
+ const targetFiles: string[] = (
51
+ multipleDownload ? files : [files[0]]
52
+ ).filter((file): file is string => typeof file === 'string' && file.trim().length > 0);
53
+
54
+ const sizeErrors: string[] = [];
55
+ const typeErrors: string[] = [];
56
+ const otherErrors: string[] = [];
57
+ const successFiles: DownloadResult['successful'] = [];
31
58
 
32
59
  try {
33
- const promises = targetFiles.map(url => NativeDownload.downloadFile(url, options));
60
+ const promises = targetFiles.map(url =>
61
+ NativeDownloadModuleWrapper(url, options)
62
+ );
63
+
34
64
  const results = await Promise.allSettled(promises);
35
-
36
- const final: DownloadResult = { successful: [], skipped: [] };
37
65
 
38
66
  results.forEach((res, index) => {
39
67
  const originalUrl = targetFiles[index] ?? "";
68
+ const fileName =
69
+ originalUrl.split('/').pop()?.split('?')[0] ||
70
+ `Dosya ${index + 1}`;
71
+
40
72
  if (res.status === 'fulfilled') {
41
- final.successful.push({ originalUrl, localUri: res.value });
42
- } else {
43
- final.skipped.push({
44
- originalUrl,
45
- reason: res.reason?.message || "Bilinmeyen Hata"
73
+ successFiles.push({
74
+ originalUrl,
75
+ localUri: res.value,
46
76
  });
77
+ } else {
78
+ const errorCode = res.reason?.code;
79
+ const errorMsg = res.reason?.message || 'Bilinmeyen hata';
80
+
81
+ if (errorCode === 'ERR_SIZE_LIMIT') {
82
+ sizeErrors.push(fileName);
83
+ } else if (errorCode === 'ERR_TYPE_MISMATCH') {
84
+ typeErrors.push(fileName);
85
+ } else {
86
+ otherErrors.push(`${fileName}: ${errorMsg}`);
87
+ }
47
88
  }
48
89
  });
49
90
 
50
- if (onSuccess) onSuccess(final);
91
+ if (sizeErrors.length > 0) {
92
+ Alert.alert(
93
+ 'Boyut Sınırı Aşıldı',
94
+ `Aşağıdaki dosyalar ${maxSize}MB sınırını aştığı için indirilemedi:\n\n${sizeErrors.join(
95
+ '\n'
96
+ )}`
97
+ );
98
+ }
99
+
100
+ if (typeErrors.length > 0) {
101
+ Alert.alert(
102
+ 'Desteklenmeyen Dosya Tipi',
103
+ `Sadece şu formatlar izin verilmektedir: [${fileTypes.join(
104
+ ', '
105
+ )}]\n\nUygun olmayan dosyalar:\n\n${typeErrors.join('\n')}`
106
+ );
107
+ }
108
+
109
+ if (otherErrors.length > 0 && debug) {
110
+ Alert.alert('İndirme Hatası', otherErrors.join('\n'));
111
+ }
112
+
113
+ const finalResult: DownloadResult = {
114
+ successful: successFiles,
115
+ skipped: [...sizeErrors, ...typeErrors, ...otherErrors].map(
116
+ name => ({
117
+ originalUrl: name,
118
+ reason: 'Failed',
119
+ })
120
+ ),
121
+ };
122
+
123
+ onSuccess?.(finalResult);
51
124
  } catch (e) {
52
- if (onError) onError(e);
53
- else console.error(e);
125
+ onError?.(e);
54
126
  } finally {
55
127
  setIsLoading(false);
56
128
  }
@@ -65,7 +137,11 @@ const DownloadFile: React.FC<DownloadFileProps> = ({
65
137
  {isLoading ? (
66
138
  <ActivityIndicator color="#FFF" />
67
139
  ) : (
68
- buttonIcon ? buttonIcon : <Text style={[styles.text, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
140
+ buttonIcon || (
141
+ <Text style={[styles.text, ButtonTextStyle]}>
142
+ {buttonPlaceHolder}
143
+ </Text>
144
+ )
69
145
  )}
70
146
  </TouchableOpacity>
71
147
  );
@@ -78,8 +154,12 @@ const styles = StyleSheet.create({
78
154
  borderRadius: 8,
79
155
  alignItems: 'center',
80
156
  },
81
- text: { color: '#000', fontWeight: 'bold' },
82
- disabled: { backgroundColor: '#AAA' }
157
+ text: {
158
+ color: '#000',
159
+ fontWeight: 'bold',
160
+ },
161
+ disabled: {
162
+ backgroundColor: '#AAA',
163
+ },
83
164
  });
84
165
 
85
- export default DownloadFile;
package/src/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import type { DocumentPickerOptions, MyUploaderProps, FileInfo } from './types';
2
+ import type { DocumentPickerOptions, MyUploaderProps, FileInfo, DownloadFileProps } from './types';
3
3
  // import type { DownloadFileProps } from './types';
4
4
 
5
5
  export * from './types';
@@ -9,7 +9,7 @@ export * from './types';
9
9
 
10
10
  // pickFile Fonksiyon Tanımı
11
11
  export declare function pickFile(options?: DocumentPickerOptions): Promise<FileInfo[]>;
12
-
12
+ export declare const DownloadFile :React.FC<DownloadFileProps>;
13
13
  export declare const MyUploader: React.FC<MyUploaderProps>;
14
14
 
15
15
  // Varsayılan dışa aktarım (İsteğe bağlı, genellikle ana bileşen verilir)
package/src/index.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import MyUploader,{pickFile} from "./components/MyUploader";
2
- // import DownloadFile from "./components/DownloadFile";
3
-
4
- // 2. Diğerlerini NAMED olarak dışa aktar (import { DownloadFile, pickFile } ... için)
5
- // export { DownloadFile, pickFile };
2
+ import {DownloadFile} from "./components/DownloadFile";
6
3
 
7
4
 
8
5
  // Sadece bu paketle ilgili olanları dışa aktar
9
- export { MyUploader, pickFile };
6
+ export { MyUploader, pickFile ,DownloadFile };
10
7
  export * from './types';
11
8
 
12
9
  // Varsayılan dışa aktarım olarak da ana bileşeni verelim
package/src/types.ts CHANGED
@@ -72,10 +72,10 @@
72
72
  import type { ViewStyle, TextStyle } from 'react-native';
73
73
 
74
74
  export interface FileInfo {
75
- uri: string;
76
- name: string;
77
- type: string;
78
- size: number;
75
+ fileUri: string;
76
+ fileName: string;
77
+ fileType: string;
78
+ fileSize: number;
79
79
  base64?: string | null;
80
80
  }
81
81