react-native-my-uploader-android 1.0.28 → 1.0.30
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 +93 -42
- package/lib/commonjs/components/DownloadFile.js +37 -47
- package/lib/commonjs/components/DownloadFile.js.map +1 -1
- package/lib/commonjs/components/MyUploader.js +57 -80
- package/lib/commonjs/components/MyUploader.js.map +1 -1
- package/lib/commonjs/index.d.js.map +1 -1
- package/lib/commonjs/index.js +9 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/components/DownloadFile.js +38 -48
- package/lib/module/components/DownloadFile.js.map +1 -1
- package/lib/module/components/MyUploader.js +55 -79
- package/lib/module/components/MyUploader.js.map +1 -1
- package/lib/module/index.d.js +10 -0
- package/lib/module/index.d.js.map +1 -1
- package/lib/module/index.js +10 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DownloadFile.tsx +40 -61
- package/src/components/MyUploader.tsx +59 -89
- package/src/index.d.ts +12 -5
- package/src/index.ts +12 -6
- package/src/types.ts +98 -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,88 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
throw new Error(LINKING_ERROR);
|
|
7
|
-
}
|
|
8
|
-
});
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator, NativeModules } from 'react-native';
|
|
3
|
+
const {
|
|
4
|
+
UploadDocumentPicker: NativeUploadPicker
|
|
5
|
+
} = NativeModules;
|
|
9
6
|
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 : [],
|
|
7
|
+
// 1. Standalone pickFile Fonksiyonu
|
|
8
|
+
export const pickFile = async (options = {}) => {
|
|
9
|
+
var _options$multipleFile, _options$maxFiles, _options$maxSize, _options$fileTypes, _options$excludedUris;
|
|
10
|
+
if (!NativeUploadPicker) throw new Error("DocumentPicker module is not linked.");
|
|
11
|
+
|
|
12
|
+
// Native tarafa gönderilecek options
|
|
13
|
+
const nativeOptions = {
|
|
14
|
+
multipleFiles: (_options$multipleFile = options.multipleFiles) !== null && _options$multipleFile !== void 0 ? _options$multipleFile : false,
|
|
15
|
+
maxFiles: (_options$maxFiles = options.maxFiles) !== null && _options$maxFiles !== void 0 ? _options$maxFiles : 0,
|
|
16
|
+
maxSize: (_options$maxSize = options.maxSize) !== null && _options$maxSize !== void 0 ? _options$maxSize : 0,
|
|
31
17
|
fileTypes: (_options$fileTypes = options.fileTypes) !== null && _options$fileTypes !== void 0 ? _options$fileTypes : ['*/*'],
|
|
32
|
-
|
|
18
|
+
excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : []
|
|
33
19
|
};
|
|
34
|
-
return
|
|
35
|
-
}
|
|
20
|
+
return await NativeUploadPicker.openDocument(nativeOptions);
|
|
21
|
+
};
|
|
36
22
|
|
|
37
|
-
//
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
fileTypes = ['*/*'],
|
|
43
|
-
maxSize = 0,
|
|
44
|
-
excludedUris = [],
|
|
45
|
-
// UI Props with defaults
|
|
46
|
-
buttonPlaceHolder = 'Dosya Seçin...',
|
|
23
|
+
// 2. MyUploader Bileşeni
|
|
24
|
+
const MyUploader = ({
|
|
25
|
+
onSelect,
|
|
26
|
+
onError,
|
|
27
|
+
buttonPlaceHolder = "Dosya Seç",
|
|
47
28
|
ButtonStyle,
|
|
48
29
|
ButtonTextStyle,
|
|
49
30
|
disabled = false,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
multipleFiles = false,
|
|
32
|
+
fileTypes = ['*/*'],
|
|
33
|
+
maxSize = 0,
|
|
34
|
+
maxFiles = 0,
|
|
35
|
+
excludedUris = []
|
|
53
36
|
}) => {
|
|
37
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
54
38
|
const handlePress = async () => {
|
|
39
|
+
if (disabled || isLoading) return;
|
|
40
|
+
setIsLoading(true);
|
|
55
41
|
try {
|
|
56
|
-
const
|
|
42
|
+
const files = await pickFile({
|
|
57
43
|
multipleFiles,
|
|
58
|
-
maxFiles,
|
|
59
44
|
fileTypes,
|
|
60
45
|
maxSize,
|
|
46
|
+
maxFiles,
|
|
61
47
|
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
|
-
}
|
|
48
|
+
});
|
|
49
|
+
onSelect(files);
|
|
70
50
|
} 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') {
|
|
51
|
+
if (onError) {
|
|
75
52
|
onError(error);
|
|
53
|
+
} else {
|
|
54
|
+
console.error("MyUploader Error:", error);
|
|
76
55
|
}
|
|
56
|
+
} finally {
|
|
57
|
+
setIsLoading(false);
|
|
77
58
|
}
|
|
78
59
|
};
|
|
79
60
|
return /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
80
|
-
style: [styles.button, ButtonStyle, disabled && styles.
|
|
61
|
+
style: [styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled],
|
|
81
62
|
onPress: handlePress,
|
|
82
|
-
disabled: disabled
|
|
83
|
-
}, /*#__PURE__*/React.createElement(
|
|
84
|
-
|
|
63
|
+
disabled: disabled || isLoading
|
|
64
|
+
}, isLoading ? /*#__PURE__*/React.createElement(ActivityIndicator, {
|
|
65
|
+
color: "#FFF"
|
|
66
|
+
}) : /*#__PURE__*/React.createElement(Text, {
|
|
67
|
+
style: [styles.text, ButtonTextStyle]
|
|
85
68
|
}, buttonPlaceHolder));
|
|
86
69
|
};
|
|
87
|
-
|
|
88
|
-
// Varsayılan stiller
|
|
89
70
|
const styles = StyleSheet.create({
|
|
90
71
|
button: {
|
|
91
|
-
backgroundColor: '#
|
|
92
|
-
|
|
93
|
-
paddingVertical: 10,
|
|
72
|
+
backgroundColor: '#6200EE',
|
|
73
|
+
padding: 12,
|
|
94
74
|
borderRadius: 8,
|
|
95
75
|
alignItems: 'center',
|
|
96
76
|
justifyContent: 'center'
|
|
97
77
|
},
|
|
98
|
-
|
|
99
|
-
color: '#
|
|
100
|
-
|
|
101
|
-
|
|
78
|
+
text: {
|
|
79
|
+
color: '#FFF',
|
|
80
|
+
fontWeight: '600',
|
|
81
|
+
fontSize: 16
|
|
102
82
|
},
|
|
103
|
-
|
|
104
|
-
backgroundColor: '#
|
|
83
|
+
disabled: {
|
|
84
|
+
backgroundColor: '#B0B0B0'
|
|
105
85
|
}
|
|
106
86
|
});
|
|
107
|
-
|
|
108
|
-
// İhtiyaca göre pickFile'ı da export edebilirsiniz.
|
|
109
|
-
export { pickFile };
|
|
110
|
-
// Component'i varsayılan olarak export ediyoruz.
|
|
111
|
-
export default MyUploaderAndroid;
|
|
87
|
+
export default MyUploader;
|
|
112
88
|
//# sourceMappingURL=MyUploader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","useState","TouchableOpacity","Text","StyleSheet","ActivityIndicator","NativeModules","UploadDocumentPicker","NativeUploadPicker","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,NativeModules } from 'react-native';\r\nimport type { MyUploaderProps, DocumentPickerOptions, FileInfo } from '../types';\r\n\r\nconst { UploadDocumentPicker: NativeUploadPicker } = NativeModules;\r\n\r\n// 1. Standalone pickFile Fonksiyonu\r\nexport const pickFile = async (options: DocumentPickerOptions = {}): Promise<FileInfo[]> => {\r\n if (!NativeUploadPicker) 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 NativeUploadPicker.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 backgroundColor: '#B0B0B0'\r\n }\r\n});\r\n\r\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UAAU,CAACwC,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,2 +1,12 @@
|
|
|
1
|
+
// import type { DownloadFileProps } from './types';
|
|
2
|
+
|
|
1
3
|
export * from './types';
|
|
4
|
+
|
|
5
|
+
// DownloadFile Component Tanımı (3. Bunu ekledik)
|
|
6
|
+
// export declare const DownloadFile: React.FC<DownloadFileProps>;
|
|
7
|
+
|
|
8
|
+
// pickFile Fonksiyon Tanımı
|
|
9
|
+
|
|
10
|
+
// Varsayılan dışa aktarım (İsteğe bağlı, genellikle ana bileşen verilir)
|
|
11
|
+
export {};
|
|
2
12
|
//# sourceMappingURL=index.d.js.map
|
|
@@ -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 { DocumentPickerOptions, MyUploaderProps, FileInfo } from './types';\r\n// import type { DownloadFileProps } from './types';\r\n\r\nexport * from './types';\r\n\r\n// DownloadFile Component Tanımı (3. Bunu ekledik)\r\n// export declare const DownloadFile: React.FC<DownloadFileProps>;\r\n\r\n// pickFile Fonksiyon Tanımı\r\nexport declare function pickFile(options?: DocumentPickerOptions): Promise<FileInfo[]>;\r\n\r\nexport declare const MyUploader: React.FC<MyUploaderProps>;\r\n\r\n// Varsayılan dışa aktarım (İsteğe bağlı, genellikle ana bileşen verilir)\r\ndeclare const _default: React.FC<MyUploaderProps>;\r\nexport default _default;"],"mappings":"AAEA;;AAEA,cAAc,SAAS;;AAEvB;AACA;;AAEA;;AAKA;AAAA","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
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
|
+
// 2. Diğerlerini NAMED olarak dışa aktar (import { DownloadFile, pickFile } ... için)
|
|
5
|
+
// export { DownloadFile, pickFile };
|
|
6
|
+
|
|
7
|
+
// Sadece bu paketle ilgili olanları dışa aktar
|
|
8
|
+
export { MyUploader, pickFile };
|
|
7
9
|
export * from './types';
|
|
8
|
-
|
|
10
|
+
|
|
11
|
+
// Varsayılan dışa aktarım olarak da ana bileşeni verelim
|
|
12
|
+
export default MyUploader;
|
|
9
13
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["MyUploader","pickFile"],"sources":["index.ts"],"sourcesContent":["import MyUploader,{pickFile} from \"./components/MyUploader\";\r\n// import DownloadFile from \"./components/DownloadFile\";\r\n\r\n// 2. Diğerlerini NAMED olarak dışa aktar (import { DownloadFile, pickFile } ... için)\r\n// export { DownloadFile, pickFile };\r\n\r\n\r\n// Sadece bu paketle ilgili olanları dışa aktar\r\nexport { MyUploader, pickFile };\r\nexport * from './types';\r\n\r\n// Varsayılan dışa aktarım olarak da ana bileşeni verelim\r\nexport default MyUploader;\r\n\r\n\r\n\r\n"],"mappings":"AAAA,OAAOA,UAAU,IAAEC,QAAQ,QAAO,yBAAyB;AAC3D;;AAEA;AACA;;AAGA;AACA,SAASD,UAAU,EAAEC,QAAQ;AAC7B,cAAc,SAAS;;AAEvB;AACA,eAAeD,UAAU","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 | null;\r\n}\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}\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}"],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator,NativeModules } from 'react-native';
|
|
3
3
|
import type { DownloadFileProps, DownloadResult } from '../types';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
const { DownloadFile: NativeDownload } = NativeModules;
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
const DownloadFile: React.FC<DownloadFileProps> = ({
|
|
8
10
|
files,
|
|
9
|
-
|
|
11
|
+
multipleDownload = false,
|
|
10
12
|
disabled = false,
|
|
11
13
|
debug = false,
|
|
12
14
|
maxSize = 0,
|
|
@@ -15,92 +17,69 @@ const DownloadFile: React.FC<DownloadFileProps> = ({
|
|
|
15
17
|
buttonIcon,
|
|
16
18
|
ButtonStyle,
|
|
17
19
|
ButtonTextStyle,
|
|
18
|
-
onSuccess
|
|
19
|
-
onError
|
|
20
|
+
onSuccess,
|
|
21
|
+
onError,
|
|
20
22
|
}) => {
|
|
21
23
|
const [isLoading, setIsLoading] = useState(false);
|
|
22
24
|
|
|
23
25
|
const handlePress = async () => {
|
|
24
|
-
if (!
|
|
25
|
-
onError(new Error("DownloadFile native module is not available."));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
26
|
+
if (disabled || isLoading || !files.length) return;
|
|
29
27
|
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
28
|
|
|
40
|
-
|
|
29
|
+
const options = { debug, maxSize, fileTypes };
|
|
30
|
+
const targetFiles = multipleDownload ? files : [files[0]];
|
|
41
31
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
32
|
+
try {
|
|
33
|
+
const promises = targetFiles.map(url => NativeDownload.downloadFile(url, options));
|
|
34
|
+
const results = await Promise.allSettled(promises);
|
|
35
|
+
|
|
36
|
+
const final: DownloadResult = { successful: [], skipped: [] };
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
38
|
+
results.forEach((res, index) => {
|
|
39
|
+
const originalUrl = targetFiles[index] ?? "";
|
|
40
|
+
if (res.status === 'fulfilled') {
|
|
41
|
+
final.successful.push({ originalUrl, localUri: res.value });
|
|
52
42
|
} else {
|
|
53
|
-
|
|
54
|
-
originalUrl,
|
|
55
|
-
reason:
|
|
43
|
+
final.skipped.push({
|
|
44
|
+
originalUrl,
|
|
45
|
+
reason: res.reason?.message || "Bilinmeyen Hata"
|
|
56
46
|
});
|
|
57
47
|
}
|
|
58
48
|
});
|
|
59
|
-
|
|
60
|
-
onSuccess(finalResult);
|
|
61
49
|
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
if (onSuccess) onSuccess(final);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (onError) onError(e);
|
|
53
|
+
else console.error(e);
|
|
64
54
|
} finally {
|
|
65
55
|
setIsLoading(false);
|
|
66
56
|
}
|
|
67
57
|
};
|
|
68
58
|
|
|
69
|
-
const content = isLoading ? (
|
|
70
|
-
<ActivityIndicator color="#FFFFFF" />
|
|
71
|
-
) : (
|
|
72
|
-
buttonIcon || <Text style={[styles.buttonText, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
|
|
73
|
-
);
|
|
74
|
-
|
|
75
59
|
return (
|
|
76
60
|
<TouchableOpacity
|
|
77
|
-
style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.
|
|
61
|
+
style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled]}
|
|
78
62
|
onPress={handlePress}
|
|
79
63
|
disabled={disabled || isLoading}
|
|
80
64
|
>
|
|
81
|
-
{
|
|
65
|
+
{isLoading ? (
|
|
66
|
+
<ActivityIndicator color="#FFF" />
|
|
67
|
+
) : (
|
|
68
|
+
buttonIcon ? buttonIcon : <Text style={[styles.text, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
|
|
69
|
+
)}
|
|
82
70
|
</TouchableOpacity>
|
|
83
71
|
);
|
|
84
72
|
};
|
|
85
73
|
|
|
86
74
|
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
|
-
},
|
|
75
|
+
button: {
|
|
76
|
+
backgroundColor: '#03DAC6',
|
|
77
|
+
padding: 12,
|
|
78
|
+
borderRadius: 8,
|
|
79
|
+
alignItems: 'center',
|
|
80
|
+
},
|
|
81
|
+
text: { color: '#000', fontWeight: 'bold' },
|
|
82
|
+
disabled: { backgroundColor: '#AAA' }
|
|
104
83
|
});
|
|
105
84
|
|
|
106
85
|
export default DownloadFile;
|
|
@@ -1,127 +1,97 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator,NativeModules } from 'react-native';
|
|
3
|
+
import type { MyUploaderProps, DocumentPickerOptions, FileInfo } from '../types';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const { UploadDocumentPicker: NativeUploadPicker } = NativeModules;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 ?? ['*/*'],
|
|
7
|
+
// 1. Standalone pickFile Fonksiyonu
|
|
8
|
+
export const pickFile = async (options: DocumentPickerOptions = {}): Promise<FileInfo[]> => {
|
|
9
|
+
if (!NativeUploadPicker) throw new Error("DocumentPicker module is not linked.");
|
|
10
|
+
|
|
11
|
+
// Native tarafa gönderilecek options
|
|
12
|
+
const nativeOptions = {
|
|
13
|
+
multipleFiles: options.multipleFiles ?? false,
|
|
14
|
+
maxFiles: options.maxFiles ?? 0,
|
|
40
15
|
maxSize: options.maxSize ?? 0,
|
|
16
|
+
fileTypes: options.fileTypes ?? ['*/*'],
|
|
17
|
+
excludedUris: options.excludedUris ?? [],
|
|
41
18
|
};
|
|
42
|
-
return DocumentPicker.openDocument(finalOptions);
|
|
43
|
-
}
|
|
44
19
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
20
|
+
return await NativeUploadPicker.openDocument(nativeOptions);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// 2. MyUploader Bileşeni
|
|
24
|
+
const MyUploader: React.FC<MyUploaderProps> = ({
|
|
25
|
+
onSelect,
|
|
26
|
+
onError,
|
|
27
|
+
buttonPlaceHolder = "Dosya Seç",
|
|
28
|
+
ButtonStyle,
|
|
29
|
+
ButtonTextStyle,
|
|
30
|
+
disabled = false,
|
|
48
31
|
multipleFiles = false,
|
|
49
|
-
maxFiles = 0,
|
|
50
32
|
fileTypes = ['*/*'],
|
|
51
33
|
maxSize = 0,
|
|
34
|
+
maxFiles = 0,
|
|
52
35
|
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
36
|
}) => {
|
|
37
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
38
|
+
|
|
62
39
|
const handlePress = async () => {
|
|
40
|
+
if (disabled || isLoading) return;
|
|
41
|
+
setIsLoading(true);
|
|
42
|
+
|
|
63
43
|
try {
|
|
64
|
-
const
|
|
44
|
+
const files = await pickFile({
|
|
65
45
|
multipleFiles,
|
|
66
|
-
maxFiles,
|
|
67
46
|
fileTypes,
|
|
68
47
|
maxSize,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
48
|
+
maxFiles,
|
|
49
|
+
excludedUris
|
|
50
|
+
});
|
|
72
51
|
|
|
73
|
-
|
|
74
|
-
// Sadece doluysa callback'i tetikleyelim.
|
|
75
|
-
if (selectedFiles && selectedFiles.length > 0) {
|
|
76
|
-
onSelect(selectedFiles);
|
|
77
|
-
}
|
|
78
|
-
|
|
52
|
+
onSelect(files);
|
|
79
53
|
} 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') {
|
|
54
|
+
if (onError) {
|
|
84
55
|
onError(error);
|
|
56
|
+
} else {
|
|
57
|
+
console.error("MyUploader Error:", error);
|
|
85
58
|
}
|
|
59
|
+
} finally {
|
|
60
|
+
setIsLoading(false);
|
|
86
61
|
}
|
|
87
62
|
};
|
|
88
63
|
|
|
89
64
|
return (
|
|
90
65
|
<TouchableOpacity
|
|
91
|
-
style={[styles.button, ButtonStyle, disabled && styles.
|
|
66
|
+
style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled]}
|
|
92
67
|
onPress={handlePress}
|
|
93
|
-
disabled={disabled}
|
|
68
|
+
disabled={disabled || isLoading}
|
|
94
69
|
>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
70
|
+
{isLoading ? (
|
|
71
|
+
<ActivityIndicator color="#FFF" />
|
|
72
|
+
) : (
|
|
73
|
+
<Text style={[styles.text, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
|
|
74
|
+
)}
|
|
98
75
|
</TouchableOpacity>
|
|
99
76
|
);
|
|
100
77
|
};
|
|
101
78
|
|
|
102
|
-
// Varsayılan stiller
|
|
103
79
|
const styles = StyleSheet.create({
|
|
104
80
|
button: {
|
|
105
|
-
backgroundColor: '#
|
|
106
|
-
|
|
107
|
-
paddingVertical: 10,
|
|
81
|
+
backgroundColor: '#6200EE',
|
|
82
|
+
padding: 12,
|
|
108
83
|
borderRadius: 8,
|
|
109
84
|
alignItems: 'center',
|
|
110
|
-
justifyContent: 'center'
|
|
85
|
+
justifyContent: 'center'
|
|
111
86
|
},
|
|
112
|
-
|
|
113
|
-
color: '#
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
disabledButton: {
|
|
118
|
-
backgroundColor: '#A9A9A9',
|
|
87
|
+
text: {
|
|
88
|
+
color: '#FFF',
|
|
89
|
+
fontWeight: '600',
|
|
90
|
+
fontSize: 16
|
|
119
91
|
},
|
|
92
|
+
disabled: {
|
|
93
|
+
backgroundColor: '#B0B0B0'
|
|
94
|
+
}
|
|
120
95
|
});
|
|
121
96
|
|
|
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;
|
|
97
|
+
export default MyUploader;
|