react-native-my-uploader-android 1.0.28 → 1.0.29
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/android/src/main/java/com/myuploaderandroid/DownloadFileModule.kt +91 -58
- package/android/src/main/java/com/myuploaderandroid/MyUploaderModule.kt +71 -87
- package/lib/commonjs/NativeModules.js +16 -0
- package/lib/commonjs/NativeModules.js.map +1 -0
- package/lib/commonjs/components/DownloadFile.js +37 -49
- package/lib/commonjs/components/DownloadFile.js.map +1 -1
- package/lib/commonjs/components/MyUploader.js +54 -80
- package/lib/commonjs/components/MyUploader.js.map +1 -1
- package/lib/commonjs/index.d.js.map +1 -1
- package/lib/commonjs/index.js +4 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/NativeModules.js +10 -0
- package/lib/module/NativeModules.js.map +1 -0
- package/lib/module/components/DownloadFile.js +38 -50
- package/lib/module/components/DownloadFile.js.map +1 -1
- package/lib/module/components/MyUploader.js +52 -79
- package/lib/module/components/MyUploader.js.map +1 -1
- package/lib/module/index.d.js +6 -0
- package/lib/module/index.d.js.map +1 -1
- package/lib/module/index.js +7 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/package.json +1 -1
- package/src/NativeModules.ts +9 -0
- package/src/components/DownloadFile.tsx +38 -62
- package/src/components/MyUploader.tsx +59 -90
- package/src/index.d.ts +13 -4
- package/src/index.ts +11 -6
- package/src/types.ts +96 -41
- package/android/src/main/java/com/myuploader/MyUploaderModule.kt +0 -173
- package/android/src/main/java/com/myuploader/MyUploaderPackage.kt +0 -16
- package/lib/commonjs/NativeMyUploader.js +0 -15
- package/lib/commonjs/NativeMyUploader.js.map +0 -1
- package/lib/module/NativeMyUploader.js +0 -9
- package/lib/module/NativeMyUploader.js.map +0 -1
- package/src/NativeMyUploader.ts +0 -25
|
@@ -1,112 +1,85 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
|
3
|
+
import { NativePicker } from '../NativeModules';
|
|
4
|
+
// 1. Standalone pickFile Fonksiyonu
|
|
5
|
+
export const pickFile = async (options = {}) => {
|
|
6
|
+
var _options$multipleFile, _options$maxFiles, _options$maxSize, _options$fileTypes, _options$excludedUris;
|
|
7
|
+
if (!NativePicker) throw new Error("DocumentPicker module is not linked.");
|
|
9
8
|
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
multipleFiles = false,
|
|
16
|
-
maxFiles = 0,
|
|
17
|
-
...rest
|
|
18
|
-
} = options;
|
|
19
|
-
if (!multipleFiles && maxFiles > 1) {
|
|
20
|
-
throw new Error('`maxFiles` cannot be greater than 1 when `multipleFiles` is false.');
|
|
21
|
-
}
|
|
22
|
-
let effectiveMaxFiles = maxFiles;
|
|
23
|
-
if (multipleFiles && maxFiles === 0) {
|
|
24
|
-
effectiveMaxFiles = 3;
|
|
25
|
-
}
|
|
26
|
-
const finalOptions = {
|
|
27
|
-
...rest,
|
|
28
|
-
multipleFiles,
|
|
29
|
-
maxFiles: effectiveMaxFiles,
|
|
30
|
-
excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : [],
|
|
9
|
+
// Native tarafa gönderilecek options
|
|
10
|
+
const nativeOptions = {
|
|
11
|
+
multipleFiles: (_options$multipleFile = options.multipleFiles) !== null && _options$multipleFile !== void 0 ? _options$multipleFile : false,
|
|
12
|
+
maxFiles: (_options$maxFiles = options.maxFiles) !== null && _options$maxFiles !== void 0 ? _options$maxFiles : 0,
|
|
13
|
+
maxSize: (_options$maxSize = options.maxSize) !== null && _options$maxSize !== void 0 ? _options$maxSize : 0,
|
|
31
14
|
fileTypes: (_options$fileTypes = options.fileTypes) !== null && _options$fileTypes !== void 0 ? _options$fileTypes : ['*/*'],
|
|
32
|
-
|
|
15
|
+
excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : []
|
|
33
16
|
};
|
|
34
|
-
return
|
|
35
|
-
}
|
|
17
|
+
return await NativePicker.openDocument(nativeOptions);
|
|
18
|
+
};
|
|
36
19
|
|
|
37
|
-
//
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
fileTypes = ['*/*'],
|
|
43
|
-
maxSize = 0,
|
|
44
|
-
excludedUris = [],
|
|
45
|
-
// UI Props with defaults
|
|
46
|
-
buttonPlaceHolder = 'Dosya Seçin...',
|
|
20
|
+
// 2. MyUploader Bileşeni
|
|
21
|
+
const MyUploader = ({
|
|
22
|
+
onSelect,
|
|
23
|
+
onError,
|
|
24
|
+
buttonPlaceHolder = "Dosya Seç",
|
|
47
25
|
ButtonStyle,
|
|
48
26
|
ButtonTextStyle,
|
|
49
27
|
disabled = false,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
multipleFiles = false,
|
|
29
|
+
fileTypes = ['*/*'],
|
|
30
|
+
maxSize = 0,
|
|
31
|
+
maxFiles = 0,
|
|
32
|
+
excludedUris = []
|
|
53
33
|
}) => {
|
|
34
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
54
35
|
const handlePress = async () => {
|
|
36
|
+
if (disabled || isLoading) return;
|
|
37
|
+
setIsLoading(true);
|
|
55
38
|
try {
|
|
56
|
-
const
|
|
39
|
+
const files = await pickFile({
|
|
57
40
|
multipleFiles,
|
|
58
|
-
maxFiles,
|
|
59
41
|
fileTypes,
|
|
60
42
|
maxSize,
|
|
43
|
+
maxFiles,
|
|
61
44
|
excludedUris
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// Eğer kullanıcı seçim yapmadan kapatırsa bazı sistemler boş array dönebilir.
|
|
66
|
-
// Sadece doluysa callback'i tetikleyelim.
|
|
67
|
-
if (selectedFiles && selectedFiles.length > 0) {
|
|
68
|
-
onSelect(selectedFiles);
|
|
69
|
-
}
|
|
45
|
+
});
|
|
46
|
+
onSelect(files);
|
|
70
47
|
} catch (error) {
|
|
71
|
-
|
|
72
|
-
// bu yüzden sadece konsola yazdırıp onError'ı tetiklemeyebiliriz.
|
|
73
|
-
// Native kodunuz "E_PICKER_CANCELLED" koduyla reject ediyor.
|
|
74
|
-
if (error.code !== 'E_PICKER_CANCELLED') {
|
|
48
|
+
if (onError) {
|
|
75
49
|
onError(error);
|
|
50
|
+
} else {
|
|
51
|
+
console.error("MyUploader Error:", error);
|
|
76
52
|
}
|
|
53
|
+
} finally {
|
|
54
|
+
setIsLoading(false);
|
|
77
55
|
}
|
|
78
56
|
};
|
|
79
57
|
return /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
80
|
-
style: [styles.button, ButtonStyle, disabled && styles.
|
|
58
|
+
style: [styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled],
|
|
81
59
|
onPress: handlePress,
|
|
82
|
-
disabled: disabled
|
|
83
|
-
}, /*#__PURE__*/React.createElement(
|
|
84
|
-
|
|
60
|
+
disabled: disabled || isLoading
|
|
61
|
+
}, isLoading ? /*#__PURE__*/React.createElement(ActivityIndicator, {
|
|
62
|
+
color: "#FFF"
|
|
63
|
+
}) : /*#__PURE__*/React.createElement(Text, {
|
|
64
|
+
style: [styles.text, ButtonTextStyle]
|
|
85
65
|
}, buttonPlaceHolder));
|
|
86
66
|
};
|
|
87
|
-
|
|
88
|
-
// Varsayılan stiller
|
|
89
67
|
const styles = StyleSheet.create({
|
|
90
68
|
button: {
|
|
91
|
-
backgroundColor: '#
|
|
92
|
-
|
|
93
|
-
paddingVertical: 10,
|
|
69
|
+
backgroundColor: '#6200EE',
|
|
70
|
+
padding: 12,
|
|
94
71
|
borderRadius: 8,
|
|
95
72
|
alignItems: 'center',
|
|
96
73
|
justifyContent: 'center'
|
|
97
74
|
},
|
|
98
|
-
|
|
99
|
-
color: '#
|
|
100
|
-
|
|
101
|
-
|
|
75
|
+
text: {
|
|
76
|
+
color: '#FFF',
|
|
77
|
+
fontWeight: '600',
|
|
78
|
+
fontSize: 16
|
|
102
79
|
},
|
|
103
|
-
|
|
104
|
-
backgroundColor: '#
|
|
80
|
+
disabled: {
|
|
81
|
+
backgroundColor: '#B0B0B0'
|
|
105
82
|
}
|
|
106
83
|
});
|
|
107
|
-
|
|
108
|
-
// İhtiyaca göre pickFile'ı da export edebilirsiniz.
|
|
109
|
-
export { pickFile };
|
|
110
|
-
// Component'i varsayılan olarak export ediyoruz.
|
|
111
|
-
export default MyUploaderAndroid;
|
|
84
|
+
export default MyUploader;
|
|
112
85
|
//# sourceMappingURL=MyUploader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","useState","TouchableOpacity","Text","StyleSheet","ActivityIndicator","NativePicker","pickFile","options","_options$multipleFile","_options$maxFiles","_options$maxSize","_options$fileTypes","_options$excludedUris","Error","nativeOptions","multipleFiles","maxFiles","maxSize","fileTypes","excludedUris","openDocument","MyUploader","onSelect","onError","buttonPlaceHolder","ButtonStyle","ButtonTextStyle","disabled","isLoading","setIsLoading","handlePress","files","error","console","createElement","style","styles","button","onPress","color","text","create","backgroundColor","padding","borderRadius","alignItems","justifyContent","fontWeight","fontSize"],"sources":["MyUploader.tsx"],"sourcesContent":["import React, { useState } from 'react';\r\nimport { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';\r\nimport { NativePicker } from '../NativeModules';\r\nimport type { MyUploaderProps, DocumentPickerOptions, FileInfo } from '../types';\r\n\r\n// 1. Standalone pickFile Fonksiyonu\r\nexport const pickFile = async (options: DocumentPickerOptions = {}): Promise<FileInfo[]> => {\r\n if (!NativePicker) throw new Error(\"DocumentPicker module is not linked.\");\r\n \r\n // Native tarafa gönderilecek options\r\n const nativeOptions = {\r\n multipleFiles: options.multipleFiles ?? false,\r\n maxFiles: options.maxFiles ?? 0,\r\n maxSize: options.maxSize ?? 0,\r\n fileTypes: options.fileTypes ?? ['*/*'],\r\n excludedUris: options.excludedUris ?? [],\r\n };\r\n\r\n return await NativePicker.openDocument(nativeOptions);\r\n};\r\n\r\n// 2. MyUploader Bileşeni\r\nconst MyUploader: React.FC<MyUploaderProps> = ({\r\n onSelect,\r\n onError,\r\n buttonPlaceHolder = \"Dosya Seç\",\r\n ButtonStyle,\r\n ButtonTextStyle,\r\n disabled = false,\r\n multipleFiles = false,\r\n fileTypes = ['*/*'],\r\n maxSize = 0,\r\n maxFiles = 0,\r\n excludedUris = [],\r\n}) => {\r\n const [isLoading, setIsLoading] = useState(false);\r\n\r\n const handlePress = async () => {\r\n if (disabled || isLoading) return;\r\n setIsLoading(true);\r\n\r\n try {\r\n const files = await pickFile({\r\n multipleFiles,\r\n fileTypes,\r\n maxSize,\r\n maxFiles,\r\n excludedUris\r\n });\r\n \r\n onSelect(files);\r\n } catch (error: any) {\r\n if (onError) {\r\n onError(error);\r\n } else {\r\n console.error(\"MyUploader Error:\", error);\r\n }\r\n } finally {\r\n setIsLoading(false);\r\n }\r\n };\r\n\r\n return (\r\n <TouchableOpacity\r\n style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled]}\r\n onPress={handlePress}\r\n disabled={disabled || isLoading}\r\n >\r\n {isLoading ? (\r\n <ActivityIndicator color=\"#FFF\" />\r\n ) : (\r\n <Text style={[styles.text, ButtonTextStyle]}>{buttonPlaceHolder}</Text>\r\n )}\r\n </TouchableOpacity>\r\n );\r\n};\r\n\r\nconst styles = StyleSheet.create({\r\n button: {\r\n backgroundColor: '#6200EE',\r\n padding: 12,\r\n borderRadius: 8,\r\n alignItems: 'center',\r\n justifyContent: 'center'\r\n },\r\n text: {\r\n color: '#FFF',\r\n fontWeight: '600',\r\n fontSize: 16\r\n },\r\n disabled: {\r\n backg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ACsC,MAAM,CAAC;EAC/BJ,MAAM,EAAE;IACNK,eAAe,EAAE,SAAS;IAC1BC,OAAO,EAAE,EAAE;IACXC,YAAY,EAAE,CAAC;IACfC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE;EAClB,CAAC;EACDN,IAAI,EAAE;IACJD,KAAK,EAAE,MAAM;IACbQ,UAAU,EAAE,KAAK;IACjBC,QAAQ,EAAE;EACZ,CAAC;EACDrB,QAAQ,EAAE;IACRe,eAAe,EAAE;EACnB;AACF,CAAC,CAAC;AAEF,eAAerB,UAAU","ignoreList":[]}
|
package/lib/module/index.d.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.d.ts"],"sourcesContent":["import * as React from 'react';\r\nimport type {
|
|
1
|
+
{"version":3,"names":[],"sources":["index.d.ts"],"sourcesContent":["import * as React from 'react';\r\nimport type { \r\n DocumentPickerOptions, \r\n MyUploaderProps, \r\n FileInfo,\r\n DownloadFileProps } from './types';\r\n\r\nexport * from './types';\r\n\r\nexport declare const MyUploader: React.FC<MyUploaderProps>;\r\n\r\n// DownloadFile Component Tanımı (3. Bunu ekledik)\r\nexport declare const DownloadFile: React.FC<DownloadFileProps>;\r\n\r\n// pickFile Fonksiyon Tanımı\r\nexport function pickFile(options?: DocumentPickerOptions): Promise<FileInfo[]>;\r\n\r\n// Varsayılan dışa aktarım (İsteğe bağlı, genellikle ana bileşen verilir)\r\nexport default MyUploader;"],"mappings":"AAOA,cAAc,SAAS;;AAIvB;;AAGA;;AAGA","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { pickFile } from './components/MyUploader';
|
|
1
|
+
import MyUploader, { pickFile } from "./components/MyUploader";
|
|
2
|
+
import DownloadFile from "./components/DownloadFile";
|
|
4
3
|
|
|
5
|
-
//
|
|
6
|
-
export
|
|
4
|
+
// 1. MyUploader'ı DEFAULT olarak dışa aktar (import MyUploader from ... için)
|
|
5
|
+
export default MyUploader;
|
|
6
|
+
|
|
7
|
+
// 2. Diğerlerini NAMED olarak dışa aktar (import { DownloadFile, pickFile } ... için)
|
|
8
|
+
export { DownloadFile, pickFile };
|
|
7
9
|
export * from './types';
|
|
8
|
-
export default MyUploaderAndroid;
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["MyUploader","pickFile","DownloadFile"],"sources":["index.ts"],"sourcesContent":["import MyUploader,{pickFile} from \"./components/MyUploader\";\r\nimport DownloadFile from \"./components/DownloadFile\";\r\n\r\n\r\n// 1. MyUploader'ı DEFAULT olarak dışa aktar (import MyUploader from ... için)\r\nexport default MyUploader;\r\n\r\n// 2. Diğerlerini NAMED olarak dışa aktar (import { DownloadFile, pickFile } ... için)\r\nexport { DownloadFile, pickFile };\r\n\r\n\r\nexport * from './types';\r\n\r\n\r\n\r\n"],"mappings":"AAAA,OAAOA,UAAU,IAAEC,QAAQ,QAAO,yBAAyB;AAC3D,OAAOC,YAAY,MAAM,2BAA2B;;AAGpD;AACA,eAAeF,UAAU;;AAEzB;AACA,SAASE,YAAY,EAAED,QAAQ;AAG/B,cAAc,SAAS","ignoreList":[]}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { StyleProp, TextStyle, ViewStyle } from 'react-native';\r\n\r\
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["// import type { StyleProp, TextStyle, ViewStyle } from 'react-native';\r\n\r\n// export interface FileInfo {\r\n// fileName: string;\r\n// fileSize: number; \r\n// fileType: string | null;\r\n// fileUri: string;\r\n// base64: string;\r\n// }\r\n\r\n// export interface MyUploaderProps{\r\n// onSelect: (files: FileInfo[]) => void;\r\n// onError?: (error: Error) => void;\r\n// buttonPlaceHolder?: string;\r\n// ButtonStyle?: StyleProp<ViewStyle>;\r\n// ButtonTextStyle?: StyleProp<TextStyle>;\r\n// disabled?: boolean; \r\n// multipleFiles?: boolean;\r\n// fileTypes?: string[];\r\n// maxSize?: number;\r\n// maxFiles?: number;\r\n// excludedUris?: string[];\r\n// }\r\n\r\n// export interface DownloadedFileInfo {\r\n// originalUrl: string;\r\n// localUri: string;\r\n// }\r\n\r\n// export interface SkippedFileInfo {\r\n// originalUrl: string;\r\n// reason: string; \r\n// }\r\n\r\n\r\n\r\n// export interface UploadFileProps {\r\n// files: string[];\r\n// multipleLoad?: boolean;\r\n// disabled?: boolean;\r\n// debug?: boolean; \r\n// maxSize?: number;\r\n// fileTypes?: string[];\r\n// buttonPlaceHolder?: string;\r\n// buttonIcon?: React.ReactNode;\r\n// ButtonStyle?: StyleProp<ViewStyle>;\r\n// ButtonTextStyle?: StyleProp<TextStyle>;\r\n// onSuccess?: (result: DownloadResult) => void;\r\n// onError?: (error: Error) => void;\r\n// }\r\n\r\n// export interface DownloadFileProps {\r\n// files: string[];\r\n// multipleDownload?: boolean;\r\n// disabled?: boolean;\r\n// debug?: boolean;\r\n// maxSize?: number; // MB\r\n// fileTypes?: string[];\r\n// buttonPlaceHolder?: string;\r\n// buttonIcon?: React.ReactNode;\r\n// ButtonStyle?: ViewStyle;\r\n// ButtonTextStyle?: TextStyle;\r\n// onSuccess?: (result: DownloadResult) => void;\r\n// onError?: (error: any) => void;\r\n// }\r\n// export interface DownloadResult {\r\n// successful: { originalUrl: string; localUri: string | null }[];\r\n// skipped: { originalUrl: string; reason: string }[];\r\n// }\r\n\r\n\r\nimport type { ViewStyle, TextStyle } from 'react-native';\r\n\r\nexport interface FileInfo {\r\n uri: string;\r\n name: string;\r\n type: string;\r\n size: number;\r\n base64?: string;\r\n}\r\n\r\nexport interface DownloadResult {\r\n successful: { originalUrl: string; localUri: string | null }[];\r\n skipped: { originalUrl: string; reason: string }[];\r\n}\r\n\r\n// ----- MyUploader & pickFile Props -----\r\nexport interface DocumentPickerOptions {\r\n multipleFiles?: boolean;\r\n fileTypes?: string[]; // örn: ['image/*', 'application/pdf']\r\n maxSize?: number; // MB cinsinden\r\n maxFiles?: number;\r\n excludedUris?: string[];\r\n}\r\n\r\nexport interface MyUploaderProps extends DocumentPickerOptions {\r\n onSelect: (files: FileInfo[]) => void;\r\n onError?: (error: Error) => void;\r\n buttonPlaceHolder?: string;\r\n ButtonStyle?: ViewStyle;\r\n ButtonTextStyle?: TextStyle;\r\n disabled?: boolean;\r\n}\r\n\r\n// ----- DownloadFile Props -----\r\nexport interface DownloadFileProps {\r\n files: string[];\r\n multipleDownload?: boolean; // multipleFiles yerine multipleDownload (İsim karışmaması için)\r\n disabled?: boolean;\r\n debug?: boolean;\r\n maxSize?: number; // MB\r\n fileTypes?: string[]; // İndirilecek dosyanın Content-Type kontrolü\r\n buttonPlaceHolder?: string;\r\n buttonIcon?: React.ReactNode;\r\n ButtonStyle?: ViewStyle;\r\n ButtonTextStyle?: TextStyle;\r\n onSuccess?: (result: DownloadResult) => void;\r\n onError?: (error: any) => void;\r\n}"],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const { DownloadFile, DocumentPicker } = NativeModules;
|
|
4
|
+
|
|
5
|
+
if (!DownloadFile) console.warn("MyUploader: DownloadFile native module not found.");
|
|
6
|
+
if (!DocumentPicker) console.warn("MyUploader: DocumentPicker native module not found.");
|
|
7
|
+
|
|
8
|
+
export const NativeDownload = DownloadFile;
|
|
9
|
+
export const NativePicker = DocumentPicker;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
|
3
|
+
import { NativeDownload } from '../NativeModules';
|
|
3
4
|
import type { DownloadFileProps, DownloadResult } from '../types';
|
|
4
5
|
|
|
5
|
-
const { DownloadFile: DownloadFileModule } = NativeModules;
|
|
6
|
-
|
|
7
6
|
const DownloadFile: React.FC<DownloadFileProps> = ({
|
|
8
7
|
files,
|
|
9
|
-
|
|
8
|
+
multipleDownload = false,
|
|
10
9
|
disabled = false,
|
|
11
10
|
debug = false,
|
|
12
11
|
maxSize = 0,
|
|
@@ -15,92 +14,69 @@ const DownloadFile: React.FC<DownloadFileProps> = ({
|
|
|
15
14
|
buttonIcon,
|
|
16
15
|
ButtonStyle,
|
|
17
16
|
ButtonTextStyle,
|
|
18
|
-
onSuccess
|
|
19
|
-
onError
|
|
17
|
+
onSuccess,
|
|
18
|
+
onError,
|
|
20
19
|
}) => {
|
|
21
20
|
const [isLoading, setIsLoading] = useState(false);
|
|
22
21
|
|
|
23
22
|
const handlePress = async () => {
|
|
24
|
-
if (!
|
|
25
|
-
onError(new Error("DownloadFile native module is not available."));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
23
|
+
if (disabled || isLoading || !files.length) return;
|
|
29
24
|
setIsLoading(true);
|
|
30
|
-
const downloadOptions = { maxSize, fileTypes, debug };
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const filesToProcess = multipleLoad ? files : files.slice(0, 1);
|
|
34
|
-
const downloadPromises = filesToProcess.map(url =>
|
|
35
|
-
DownloadFileModule.downloadFile(url, downloadOptions)
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const settledResults = await Promise.allSettled(downloadPromises);
|
|
39
25
|
|
|
40
|
-
|
|
26
|
+
const options = { debug, maxSize, fileTypes };
|
|
27
|
+
const targetFiles = multipleDownload ? files : [files[0]];
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
try {
|
|
30
|
+
const promises = targetFiles.map(url => NativeDownload.downloadFile(url, options));
|
|
31
|
+
const results = await Promise.allSettled(promises);
|
|
32
|
+
|
|
33
|
+
const final: DownloadResult = { successful: [], skipped: [] };
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
35
|
+
results.forEach((res, index) => {
|
|
36
|
+
const originalUrl = targetFiles[index] ?? "";
|
|
37
|
+
if (res.status === 'fulfilled') {
|
|
38
|
+
final.successful.push({ originalUrl, localUri: res.value });
|
|
52
39
|
} else {
|
|
53
|
-
|
|
54
|
-
originalUrl,
|
|
55
|
-
reason:
|
|
40
|
+
final.skipped.push({
|
|
41
|
+
originalUrl,
|
|
42
|
+
reason: res.reason?.message || "Bilinmeyen Hata"
|
|
56
43
|
});
|
|
57
44
|
}
|
|
58
45
|
});
|
|
59
|
-
|
|
60
|
-
onSuccess(finalResult);
|
|
61
46
|
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
if (onSuccess) onSuccess(final);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (onError) onError(e);
|
|
50
|
+
else console.error(e);
|
|
64
51
|
} finally {
|
|
65
52
|
setIsLoading(false);
|
|
66
53
|
}
|
|
67
54
|
};
|
|
68
55
|
|
|
69
|
-
const content = isLoading ? (
|
|
70
|
-
<ActivityIndicator color="#FFFFFF" />
|
|
71
|
-
) : (
|
|
72
|
-
buttonIcon || <Text style={[styles.buttonText, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
|
|
73
|
-
);
|
|
74
|
-
|
|
75
56
|
return (
|
|
76
57
|
<TouchableOpacity
|
|
77
|
-
style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.
|
|
58
|
+
style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled]}
|
|
78
59
|
onPress={handlePress}
|
|
79
60
|
disabled={disabled || isLoading}
|
|
80
61
|
>
|
|
81
|
-
{
|
|
62
|
+
{isLoading ? (
|
|
63
|
+
<ActivityIndicator color="#FFF" />
|
|
64
|
+
) : (
|
|
65
|
+
buttonIcon ? buttonIcon : <Text style={[styles.text, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
|
|
66
|
+
)}
|
|
82
67
|
</TouchableOpacity>
|
|
83
68
|
);
|
|
84
69
|
};
|
|
85
70
|
|
|
86
71
|
const styles = StyleSheet.create({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
buttonText: {
|
|
97
|
-
color: '#FFFFFF',
|
|
98
|
-
fontSize: 16,
|
|
99
|
-
fontWeight: 'bold',
|
|
100
|
-
},
|
|
101
|
-
disabledButton: {
|
|
102
|
-
backgroundColor: '#A9A9A9',
|
|
103
|
-
},
|
|
72
|
+
button: {
|
|
73
|
+
backgroundColor: '#03DAC6',
|
|
74
|
+
padding: 12,
|
|
75
|
+
borderRadius: 8,
|
|
76
|
+
alignItems: 'center',
|
|
77
|
+
},
|
|
78
|
+
text: { color: '#000', fontWeight: 'bold' },
|
|
79
|
+
disabled: { backgroundColor: '#AAA' }
|
|
104
80
|
});
|
|
105
81
|
|
|
106
82
|
export default DownloadFile;
|
|
@@ -1,127 +1,96 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
|
3
|
+
import { NativePicker } from '../NativeModules';
|
|
4
|
+
import type { MyUploaderProps, DocumentPickerOptions, FileInfo } from '../types';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
throw new Error(LINKING_ERROR);
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
// Mevcut pickFile fonksiyonunu dahili (internal) olarak kullanmak üzere saklayalım.
|
|
19
|
-
// İsterseniz bunu dışa aktarmaya devam edebilirsiniz.
|
|
20
|
-
async function pickFile(
|
|
21
|
-
options: DocumentPickerOptions = {}
|
|
22
|
-
): Promise<FileInfo[]> {
|
|
23
|
-
const { multipleFiles = false, maxFiles = 0, ...rest } = options;
|
|
24
|
-
|
|
25
|
-
if (!multipleFiles && maxFiles > 1) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
'`maxFiles` cannot be greater than 1 when `multipleFiles` is false.'
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
let effectiveMaxFiles = maxFiles;
|
|
31
|
-
if (multipleFiles && maxFiles === 0) {
|
|
32
|
-
effectiveMaxFiles = 3;
|
|
33
|
-
}
|
|
34
|
-
const finalOptions: DocumentPickerOptions = {
|
|
35
|
-
...rest,
|
|
36
|
-
multipleFiles,
|
|
37
|
-
maxFiles: effectiveMaxFiles,
|
|
38
|
-
excludedUris: options.excludedUris ?? [],
|
|
39
|
-
fileTypes: options.fileTypes ?? ['*/*'],
|
|
6
|
+
// 1. Standalone pickFile Fonksiyonu
|
|
7
|
+
export const pickFile = async (options: DocumentPickerOptions = {}): Promise<FileInfo[]> => {
|
|
8
|
+
if (!NativePicker) throw new Error("DocumentPicker module is not linked.");
|
|
9
|
+
|
|
10
|
+
// Native tarafa gönderilecek options
|
|
11
|
+
const nativeOptions = {
|
|
12
|
+
multipleFiles: options.multipleFiles ?? false,
|
|
13
|
+
maxFiles: options.maxFiles ?? 0,
|
|
40
14
|
maxSize: options.maxSize ?? 0,
|
|
15
|
+
fileTypes: options.fileTypes ?? ['*/*'],
|
|
16
|
+
excludedUris: options.excludedUris ?? [],
|
|
41
17
|
};
|
|
42
|
-
return DocumentPicker.openDocument(finalOptions);
|
|
43
|
-
}
|
|
44
18
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
19
|
+
return await NativePicker.openDocument(nativeOptions);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 2. MyUploader Bileşeni
|
|
23
|
+
const MyUploader: React.FC<MyUploaderProps> = ({
|
|
24
|
+
onSelect,
|
|
25
|
+
onError,
|
|
26
|
+
buttonPlaceHolder = "Dosya Seç",
|
|
27
|
+
ButtonStyle,
|
|
28
|
+
ButtonTextStyle,
|
|
29
|
+
disabled = false,
|
|
48
30
|
multipleFiles = false,
|
|
49
|
-
maxFiles = 0,
|
|
50
31
|
fileTypes = ['*/*'],
|
|
51
32
|
maxSize = 0,
|
|
33
|
+
maxFiles = 0,
|
|
52
34
|
excludedUris = [],
|
|
53
|
-
// UI Props with defaults
|
|
54
|
-
buttonPlaceHolder = 'Dosya Seçin...',
|
|
55
|
-
ButtonStyle,
|
|
56
|
-
ButtonTextStyle,
|
|
57
|
-
disabled = false,
|
|
58
|
-
// Callbacks
|
|
59
|
-
onSelect,
|
|
60
|
-
onError = (error) => console.error('MyUploader Error:', error),
|
|
61
35
|
}) => {
|
|
36
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
37
|
+
|
|
62
38
|
const handlePress = async () => {
|
|
39
|
+
if (disabled || isLoading) return;
|
|
40
|
+
setIsLoading(true);
|
|
41
|
+
|
|
63
42
|
try {
|
|
64
|
-
const
|
|
43
|
+
const files = await pickFile({
|
|
65
44
|
multipleFiles,
|
|
66
|
-
maxFiles,
|
|
67
45
|
fileTypes,
|
|
68
46
|
maxSize,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
maxFiles,
|
|
48
|
+
excludedUris
|
|
49
|
+
});
|
|
72
50
|
|
|
73
|
-
|
|
74
|
-
// Sadece doluysa callback'i tetikleyelim.
|
|
75
|
-
if (selectedFiles && selectedFiles.length > 0) {
|
|
76
|
-
onSelect(selectedFiles);
|
|
77
|
-
}
|
|
78
|
-
|
|
51
|
+
onSelect(files);
|
|
79
52
|
} catch (error: any) {
|
|
80
|
-
|
|
81
|
-
// bu yüzden sadece konsola yazdırıp onError'ı tetiklemeyebiliriz.
|
|
82
|
-
// Native kodunuz "E_PICKER_CANCELLED" koduyla reject ediyor.
|
|
83
|
-
if (error.code !== 'E_PICKER_CANCELLED') {
|
|
53
|
+
if (onError) {
|
|
84
54
|
onError(error);
|
|
55
|
+
} else {
|
|
56
|
+
console.error("MyUploader Error:", error);
|
|
85
57
|
}
|
|
58
|
+
} finally {
|
|
59
|
+
setIsLoading(false);
|
|
86
60
|
}
|
|
87
61
|
};
|
|
88
62
|
|
|
89
63
|
return (
|
|
90
64
|
<TouchableOpacity
|
|
91
|
-
style={[styles.button, ButtonStyle, disabled && styles.
|
|
65
|
+
style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled]}
|
|
92
66
|
onPress={handlePress}
|
|
93
|
-
disabled={disabled}
|
|
67
|
+
disabled={disabled || isLoading}
|
|
94
68
|
>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
{isLoading ? (
|
|
70
|
+
<ActivityIndicator color="#FFF" />
|
|
71
|
+
) : (
|
|
72
|
+
<Text style={[styles.text, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
|
|
73
|
+
)}
|
|
98
74
|
</TouchableOpacity>
|
|
99
75
|
);
|
|
100
76
|
};
|
|
101
77
|
|
|
102
|
-
// Varsayılan stiller
|
|
103
78
|
const styles = StyleSheet.create({
|
|
104
79
|
button: {
|
|
105
|
-
backgroundColor: '#
|
|
106
|
-
|
|
107
|
-
paddingVertical: 10,
|
|
80
|
+
backgroundColor: '#6200EE',
|
|
81
|
+
padding: 12,
|
|
108
82
|
borderRadius: 8,
|
|
109
83
|
alignItems: 'center',
|
|
110
|
-
justifyContent: 'center'
|
|
84
|
+
justifyContent: 'center'
|
|
111
85
|
},
|
|
112
|
-
|
|
113
|
-
color: '#
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
disabledButton: {
|
|
118
|
-
backgroundColor: '#A9A9A9',
|
|
86
|
+
text: {
|
|
87
|
+
color: '#FFF',
|
|
88
|
+
fontWeight: '600',
|
|
89
|
+
fontSize: 16
|
|
119
90
|
},
|
|
91
|
+
disabled: {
|
|
92
|
+
backgroundColor: '#B0B0B0'
|
|
93
|
+
}
|
|
120
94
|
});
|
|
121
95
|
|
|
122
|
-
|
|
123
|
-
export { pickFile };
|
|
124
|
-
export type { FileInfo, DocumentPickerOptions, MyUploaderProps } from "../types";
|
|
125
|
-
|
|
126
|
-
// Component'i varsayılan olarak export ediyoruz.
|
|
127
|
-
export default MyUploaderAndroid;
|
|
96
|
+
export default MyUploader;
|