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.
Files changed (37) hide show
  1. package/android/src/main/java/com/myuploaderandroid/DownloadFileModule.kt +91 -58
  2. package/android/src/main/java/com/myuploaderandroid/MyUploaderModule.kt +71 -87
  3. package/lib/commonjs/NativeModules.js +16 -0
  4. package/lib/commonjs/NativeModules.js.map +1 -0
  5. package/lib/commonjs/components/DownloadFile.js +37 -49
  6. package/lib/commonjs/components/DownloadFile.js.map +1 -1
  7. package/lib/commonjs/components/MyUploader.js +54 -80
  8. package/lib/commonjs/components/MyUploader.js.map +1 -1
  9. package/lib/commonjs/index.d.js.map +1 -1
  10. package/lib/commonjs/index.js +4 -4
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/types.js.map +1 -1
  13. package/lib/module/NativeModules.js +10 -0
  14. package/lib/module/NativeModules.js.map +1 -0
  15. package/lib/module/components/DownloadFile.js +38 -50
  16. package/lib/module/components/DownloadFile.js.map +1 -1
  17. package/lib/module/components/MyUploader.js +52 -79
  18. package/lib/module/components/MyUploader.js.map +1 -1
  19. package/lib/module/index.d.js +6 -0
  20. package/lib/module/index.d.js.map +1 -1
  21. package/lib/module/index.js +7 -6
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/types.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/NativeModules.ts +9 -0
  26. package/src/components/DownloadFile.tsx +38 -62
  27. package/src/components/MyUploader.tsx +59 -90
  28. package/src/index.d.ts +13 -4
  29. package/src/index.ts +11 -6
  30. package/src/types.ts +96 -41
  31. package/android/src/main/java/com/myuploader/MyUploaderModule.kt +0 -173
  32. package/android/src/main/java/com/myuploader/MyUploaderPackage.kt +0 -16
  33. package/lib/commonjs/NativeMyUploader.js +0 -15
  34. package/lib/commonjs/NativeMyUploader.js.map +0 -1
  35. package/lib/module/NativeMyUploader.js +0 -9
  36. package/lib/module/NativeMyUploader.js.map +0 -1
  37. package/src/NativeMyUploader.ts +0 -25
@@ -1,112 +1,85 @@
1
- import React from 'react';
2
- import { NativeModules, TouchableOpacity, Text, StyleSheet } from 'react-native';
3
- const LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;
4
- const DocumentPicker = NativeModules.DocumentPicker ? NativeModules.DocumentPicker : new Proxy({}, {
5
- get() {
6
- throw new Error(LINKING_ERROR);
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
- // Mevcut pickFile fonksiyonunu dahili (internal) olarak kullanmak üzere saklayalım.
11
- // İsterseniz bunu dışa aktarmaya devam edebilirsiniz.
12
- async function pickFile(options = {}) {
13
- var _options$excludedUris, _options$fileTypes, _options$maxSize;
14
- const {
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
- maxSize: (_options$maxSize = options.maxSize) !== null && _options$maxSize !== void 0 ? _options$maxSize : 0
15
+ excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : []
33
16
  };
34
- return DocumentPicker.openDocument(finalOptions);
35
- }
17
+ return await NativePicker.openDocument(nativeOptions);
18
+ };
36
19
 
37
- // YENİ: MyUploader Component'i
38
- const MyUploaderAndroid = ({
39
- // DocumentPickerOptions
40
- multipleFiles = false,
41
- maxFiles = 0,
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
- // Callbacks
51
- onSelect,
52
- onError = error => console.error('MyUploader Error:', error)
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 options = {
39
+ const files = await pickFile({
57
40
  multipleFiles,
58
- maxFiles,
59
41
  fileTypes,
60
42
  maxSize,
43
+ maxFiles,
61
44
  excludedUris
62
- };
63
- const selectedFiles = await pickFile(options);
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
- // Kullanıcının seçimi iptal etmesi bir "hata" sayılmamalı,
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.disabledButton],
58
+ style: [styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled],
81
59
  onPress: handlePress,
82
- disabled: disabled
83
- }, /*#__PURE__*/React.createElement(Text, {
84
- style: [styles.buttonText, ButtonTextStyle]
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: '#007AFF',
92
- paddingHorizontal: 20,
93
- paddingVertical: 10,
69
+ backgroundColor: '#6200EE',
70
+ padding: 12,
94
71
  borderRadius: 8,
95
72
  alignItems: 'center',
96
73
  justifyContent: 'center'
97
74
  },
98
- buttonText: {
99
- color: '#FFFFFF',
100
- fontSize: 16,
101
- fontWeight: 'bold'
75
+ text: {
76
+ color: '#FFF',
77
+ fontWeight: '600',
78
+ fontSize: 16
102
79
  },
103
- disabledButton: {
104
- backgroundColor: '#A9A9A9'
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","NativeModules","TouchableOpacity","Text","StyleSheet","LINKING_ERROR","DocumentPicker","Proxy","get","Error","pickFile","options","_options$excludedUris","_options$fileTypes","_options$maxSize","multipleFiles","maxFiles","rest","effectiveMaxFiles","finalOptions","excludedUris","fileTypes","maxSize","openDocument","MyUploaderAndroid","buttonPlaceHolder","ButtonStyle","ButtonTextStyle","disabled","onSelect","onError","error","console","handlePress","selectedFiles","length","code","createElement","style","styles","button","disabledButton","onPress","buttonText","create","backgroundColor","paddingHorizontal","paddingVertical","borderRadius","alignItems","justifyContent","color","fontSize","fontWeight"],"sources":["MyUploader.tsx"],"sourcesContent":["import React from 'react';\r\nimport {NativeModules,TouchableOpacity,Text,StyleSheet} from 'react-native';\r\nimport type {FileInfo,DocumentPickerOptions, MyUploaderProps} from '../types';\r\n\r\nconst LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;\r\n\r\nconst DocumentPicker = NativeModules.DocumentPicker\r\n ? NativeModules.DocumentPicker\r\n : new Proxy(\r\n {},\r\n {\r\n get() {\r\n throw new Error(LINKING_ERROR);\r\n },\r\n }\r\n );\r\n\r\n// Mevcut pickFile fonksiyonunu dahili (internal) olarak kullanmak üzere saklayalım.\r\n// İsterseniz bunu dışa aktarmaya devam edebilirsiniz.\r\nasync function pickFile(\r\n options: DocumentPickerOptions = {}\r\n): Promise<FileInfo[]> {\r\n const { multipleFiles = false, maxFiles = 0, ...rest } = options;\r\n\r\n if (!multipleFiles && maxFiles > 1) {\r\n throw new Error(\r\n '`maxFiles` cannot be greater than 1 when `multipleFiles` is false.'\r\n );\r\n }\r\n let effectiveMaxFiles = maxFiles;\r\n if (multipleFiles && maxFiles === 0) {\r\n effectiveMaxFiles = 3;\r\n }\r\n const finalOptions: DocumentPickerOptions = {\r\n ...rest,\r\n multipleFiles,\r\n maxFiles: effectiveMaxFiles,\r\n excludedUris: options.excludedUris ?? [],\r\n fileTypes: options.fileTypes ?? ['*/*'],\r\n maxSize: options.maxSize ?? 0,\r\n };\r\n return DocumentPicker.openDocument(finalOptions);\r\n}\r\n\r\n// YENİ: MyUploader Component'i\r\nconst MyUploaderAndroid: React.FC<MyUploaderProps> = ({\r\n // DocumentPickerOptions\r\n multipleFiles = false,\r\n maxFiles = 0,\r\n fileTypes = ['*/*'],\r\n maxSize = 0,\r\n excludedUris = [],\r\n // UI Props with defaults\r\n buttonPlaceHolder = 'Dosya Seçin...',\r\n ButtonStyle,\r\n ButtonTextStyle,\r\n disabled = false,\r\n // Callbacks\r\n onSelect,\r\n onError = (error) => console.error('MyUploader Error:', error),\r\n}) => {\r\n const handlePress = async () => {\r\n try {\r\n const options: DocumentPickerOptions = {\r\n multipleFiles,\r\n maxFiles,\r\n fileTypes,\r\n maxSize,\r\n excludedUris,\r\n };\r\n const selectedFiles = await pickFile(options);\r\n \r\n // Eğer kullanıcı seçim yapmadan kapatırsa bazı sistemler boş array dönebilir.\r\n // Sadece doluysa callback'i tetikleyelim.\r\n if (selectedFiles && selectedFiles.length > 0) {\r\n onSelect(selectedFiles);\r\n }\r\n\r\n } catch (error: any) {\r\n // Kullanıcının seçimi iptal etmesi bir \"hata\" sayılmamalı,\r\n // bu yüzden sadece konsola yazdırıp onError'ı tetiklemeyebiliriz.\r\n // Native kodunuz \"E_PICKER_CANCELLED\" koduyla reject ediyor.\r\n if (error.code !== 'E_PICKER_CANCELLED') {\r\n onError(error);\r\n }\r\n }\r\n };\r\n\r\n return (\r\n <TouchableOpacity\r\n style={[styles.button, ButtonStyle, disabled && styles.disabledButton]}\r\n onPress={handlePress}\r\n disabled={disabled}\r\n >\r\n <Text style={[styles.buttonText, ButtonTextStyle]}>\r\n {buttonPlaceHolder}\r\n </Text>\r\n </TouchableOpacity>\r\n );\r\n};\r\n\r\n// Varsayılan stiller\r\nconst styles = StyleSheet.create({\r\n button: {\r\n backgroundColor: '#007AFF',\r\n paddingHorizontal: 20,\r\n paddingVertical: 10,\r\n borderRadius: 8,\r\n alignItems: 'center',\r\n justifyContent: 'center',\r\n },\r\n buttonText: {\r\n color: '#FFFFFF',\r\n fontSize: 16,\r\n fontWeight: 'bold',\r\n },\r\n disabledButton: {\r\n backgroundColor: '#A9A9A9',\r\n },\r\n});\r\n\r\n// İhtiyaca göre pickFile'ı da export edebilirsiniz.\r\nexport { pickFile };\r\nexport type { FileInfo, DocumentPickerOptions, MyUploaderProps } from \"../types\";\r\n\r\n// Component'i varsayılan olarak export ediyoruz.\r\nexport default MyUploaderAndroid;"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAAQC,aAAa,EAACC,gBAAgB,EAACC,IAAI,EAACC,UAAU,QAAO,cAAc;AAG3E,MAAMC,aAAa,GAAG,mEAAmE;AAEzF,MAAMC,cAAc,GAAGL,aAAa,CAACK,cAAc,GAC/CL,aAAa,CAACK,cAAc,GAC5B,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACJ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA,eAAeK,QAAQA,CACrBC,OAA8B,GAAG,CAAC,CAAC,EACd;EAAA,IAAAC,qBAAA,EAAAC,kBAAA,EAAAC,gBAAA;EACrB,MAAM;IAAEC,aAAa,GAAG,KAAK;IAAEC,QAAQ,GAAG,CAAC;IAAE,GAAGC;EAAK,CAAC,GAAGN,OAAO;EAEhE,IAAI,CAACI,aAAa,IAAIC,QAAQ,GAAG,CAAC,EAAE;IAClC,MAAM,IAAIP,KAAK,CACb,oEACF,CAAC;EACH;EACA,IAAIS,iBAAiB,GAAGF,QAAQ;EAChC,IAAID,aAAa,IAAIC,QAAQ,KAAK,CAAC,EAAE;IACnCE,iBAAiB,GAAG,CAAC;EACvB;EACA,MAAMC,YAAmC,GAAG;IAC1C,GAAGF,IAAI;IACPF,aAAa;IACbC,QAAQ,EAAEE,iBAAiB;IAC3BE,YAAY,GAAAR,qBAAA,GAAED,OAAO,CAACS,YAAY,cAAAR,qBAAA,cAAAA,qBAAA,GAAI,EAAE;IACxCS,SAAS,GAAAR,kBAAA,GAAEF,OAAO,CAACU,SAAS,cAAAR,kBAAA,cAAAA,kBAAA,GAAI,CAAC,KAAK,CAAC;IACvCS,OAAO,GAAAR,gBAAA,GAAEH,OAAO,CAACW,OAAO,cAAAR,gBAAA,cAAAA,gBAAA,GAAI;EAC9B,CAAC;EACD,OAAOR,cAAc,CAACiB,YAAY,CAACJ,YAAY,CAAC;AAClD;;AAEA;AACA,MAAMK,iBAA4C,GAAGA,CAAC;EACpD;EACAT,aAAa,GAAG,KAAK;EACrBC,QAAQ,GAAG,CAAC;EACZK,SAAS,GAAG,CAAC,KAAK,CAAC;EACnBC,OAAO,GAAG,CAAC;EACXF,YAAY,GAAG,EAAE;EACjB;EACAK,iBAAiB,GAAG,gBAAgB;EACpCC,WAAW;EACXC,eAAe;EACfC,QAAQ,GAAG,KAAK;EAChB;EACAC,QAAQ;EACRC,OAAO,GAAIC,KAAK,IAAKC,OAAO,CAACD,KAAK,CAAC,mBAAmB,EAAEA,KAAK;AAC/D,CAAC,KAAK;EACJ,MAAME,WAAW,GAAG,MAAAA,CAAA,KAAY;IAC9B,IAAI;MACF,MAAMtB,OAA8B,GAAG;QACrCI,aAAa;QACbC,QAAQ;QACRK,SAAS;QACTC,OAAO;QACPF;MACF,CAAC;MACD,MAAMc,aAAa,GAAG,MAAMxB,QAAQ,CAACC,OAAO,CAAC;;MAE7C;MACA;MACA,IAAIuB,aAAa,IAAIA,aAAa,CAACC,MAAM,GAAG,CAAC,EAAE;QAC7CN,QAAQ,CAACK,aAAa,CAAC;MACzB;IAEF,CAAC,CAAC,OAAOH,KAAU,EAAE;MACnB;MACA;MACA;MACA,IAAIA,KAAK,CAACK,IAAI,KAAK,oBAAoB,EAAE;QACvCN,OAAO,CAACC,KAAK,CAAC;MAChB;IACF;EACF,CAAC;EAED,oBACE/B,KAAA,CAAAqC,aAAA,CAACnC,gBAAgB;IACfoC,KAAK,EAAE,CAACC,MAAM,CAACC,MAAM,EAAEd,WAAW,EAAEE,QAAQ,IAAIW,MAAM,CAACE,cAAc,CAAE;IACvEC,OAAO,EAAET,WAAY;IACrBL,QAAQ,EAAEA;EAAS,gBAEnB5B,KAAA,CAAAqC,aAAA,CAAClC,IAAI;IAACmC,KAAK,EAAE,CAACC,MAAM,CAACI,UAAU,EAAEhB,eAAe;EAAE,GAC/CF,iBACG,CACU,CAAC;AAEvB,CAAC;;AAED;AACA,MAAMc,MAAM,GAAGnC,UAAU,CAACwC,MAAM,CAAC;EAC/BJ,MAAM,EAAE;IACNK,eAAe,EAAE,SAAS;IAC1BC,iBAAiB,EAAE,EAAE;IACrBC,eAAe,EAAE,EAAE;IACnBC,YAAY,EAAE,CAAC;IACfC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE;EAClB,CAAC;EACDP,UAAU,EAAE;IACVQ,KAAK,EAAE,SAAS;IAChBC,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE;EACd,CAAC;EACDZ,cAAc,EAAE;IACdI,eAAe,EAAE;EACnB;AACF,CAAC,CAAC;;AAEF;AACA,SAASnC,QAAQ;AAGjB;AACA,eAAec,iBAAiB","ignoreList":[]}
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 backgroundColor: '#B0B0B0'\r\n }\r\n});\r\n\r\nexport default MyUploader;"],"mappings":"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","ignoreList":[]}
@@ -1,2 +1,8 @@
1
1
  export * from './types';
2
+
3
+ // DownloadFile Component Tanımı (3. Bunu ekledik)
4
+
5
+ // pickFile Fonksiyon Tanımı
6
+
7
+ // Varsayılan dışa aktarım (İsteğe bağlı, genellikle ana bileşen verilir)
2
8
  //# sourceMappingURL=index.d.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.d.ts"],"sourcesContent":["import * as React from 'react';\r\nimport type { DocumentPickerOptions, MyUploaderProps,FileInfo,DownloadFileProps } from './types';\r\n\r\nexport * from './types';\r\n\r\ndeclare const MyUploader: React.FC<MyUploaderProps>;\r\nexport default MyUploader;\r\n\r\nexport declare const DownloadFile: React.FC<DownloadFileProps>;\r\nexport function pickFile(options?: DocumentPickerOptions): Promise<FileInfo[]>;"],"mappings":"AAGA,cAAc,SAAS","ignoreList":[]}
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":[]}
@@ -1,9 +1,10 @@
1
- import MyUploaderAndroid from "./components/MyUploader";
2
- import DownloadFileAndroid from "./components/DownloadFile";
3
- import { pickFile } from './components/MyUploader';
1
+ import MyUploader, { pickFile } from "./components/MyUploader";
2
+ import DownloadFile from "./components/DownloadFile";
4
3
 
5
- // Component'leri ve fonksiyonları dışa aktar
6
- export { DownloadFileAndroid, pickFile };
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
@@ -1 +1 @@
1
- {"version":3,"names":["MyUploaderAndroid","DownloadFileAndroid","pickFile"],"sources":["index.ts"],"sourcesContent":["import MyUploaderAndroid from \"./components/MyUploader\";\r\nimport DownloadFileAndroid from \"./components/DownloadFile\";\r\nimport { pickFile } from './components/MyUploader';\r\n\r\n// Component'leri ve fonksiyonları dışa aktar\r\nexport { DownloadFileAndroid, pickFile };\r\nexport * from './types';\r\nexport default MyUploaderAndroid;\r\n\r\n\r\n"],"mappings":"AAAA,OAAOA,iBAAiB,MAAM,yBAAyB;AACvD,OAAOC,mBAAmB,MAAM,2BAA2B;AAC3D,SAASC,QAAQ,QAAQ,yBAAyB;;AAElD;AACA,SAASD,mBAAmB,EAAEC,QAAQ;AACtC,cAAc,SAAS;AACvB,eAAeF,iBAAiB","ignoreList":[]}
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":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { StyleProp, TextStyle, ViewStyle } from 'react-native';\r\n\r\nexport interface FileInfo {\r\n fileName: string;\r\n fileSize: number; // in bytes\r\n fileType: string | null;\r\n fileUri: string;\r\n base64: string;\r\n}\r\n\r\nexport interface DocumentPickerOptions {\r\n multipleFiles?: boolean;\r\n fileTypes?: string[];\r\n maxSize?: number;\r\n maxFiles?: number;\r\n excludedUris?: string[];\r\n}\r\nexport interface MyUploaderProps extends DocumentPickerOptions {\r\n // Geri bildirim (callback) fonksiyonları\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}\r\n\r\n//download File Module Props\r\nexport interface DownloadedFileInfo {\r\n originalUrl: string;\r\n localUri: string; // Cihazdaki dosyanın URI'si\r\n}\r\n\r\n// YENİ: Atlanan dosyalar hakkında bilgi vermek için arayüz\r\nexport interface SkippedFileInfo {\r\n originalUrl: string;\r\n reason: string; // Neden atlandığı (örn: \"Dosya çok büyük\")\r\n}\r\n\r\n// YENİ: onSUCCESS callback'inin döndüreceği sonuç nesnesi\r\nexport interface DownloadResult {\r\n successful: DownloadedFileInfo[];\r\n skipped: SkippedFileInfo[];\r\n}\r\n\r\n// GÜNCELLENDİ: DownloadFileProps arayüzü\r\nexport interface DownloadFileProps {\r\n files: string[];\r\n // YENİ PROPLAR\r\n multipleLoad?: boolean;\r\n disabled?: boolean;\r\n debug?: boolean; // Mevcut debug prop'u\r\n\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 \r\n // GÜNCELLENDİ: Callback daha zengin bir nesne döndürecek\r\n onSuccess?: (result: DownloadResult) => void;\r\n onError?: (error: Error) => void;\r\n}"],"mappings":"","ignoreList":[]}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-my-uploader-android",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "file uploader for android",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -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 { NativeModules, TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
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
- multipleLoad = false,
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 = (error) => console.error('DownloadFile Error:', error),
17
+ onSuccess,
18
+ onError,
20
19
  }) => {
21
20
  const [isLoading, setIsLoading] = useState(false);
22
21
 
23
22
  const handlePress = async () => {
24
- if (!DownloadFileModule) {
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
- const finalResult: DownloadResult = { successful: [], skipped: [] };
26
+ const options = { debug, maxSize, fileTypes };
27
+ const targetFiles = multipleDownload ? files : [files[0]];
41
28
 
42
- settledResults.forEach((result, index) => {
43
- // DÜZELTME: `filesToProcess[index]` ifadesinin sonuna `!` ekleyerek
44
- // TypeScript'e bu değerin asla undefined olmayacağını bildiriyoruz.
45
- const originalUrl = filesToProcess[index]!;
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
- if (result.status === 'fulfilled') {
48
- finalResult.successful.push({
49
- originalUrl, // Artık hata vermeyecek
50
- localUri: result.value,
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
- finalResult.skipped.push({
54
- originalUrl, // Artık hata vermeyecek
55
- reason: result.reason.message,
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
- } catch (error: any) {
63
- onError(error);
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.disabledButton]}
58
+ style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled]}
78
59
  onPress={handlePress}
79
60
  disabled={disabled || isLoading}
80
61
  >
81
- {content}
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
- button: {
88
- backgroundColor: '#008CBA',
89
- paddingHorizontal: 20,
90
- paddingVertical: 10,
91
- borderRadius: 8,
92
- alignItems: 'center',
93
- justifyContent: 'center',
94
- flexDirection: 'row',
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 {NativeModules,TouchableOpacity,Text,StyleSheet} from 'react-native';
3
- import type {FileInfo,DocumentPickerOptions, MyUploaderProps} from '../types';
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
- const LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;
6
-
7
- const DocumentPicker = NativeModules.DocumentPicker
8
- ? NativeModules.DocumentPicker
9
- : new Proxy(
10
- {},
11
- {
12
- get() {
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
- // YENİ: MyUploader Component'i
46
- const MyUploaderAndroid: React.FC<MyUploaderProps> = ({
47
- // DocumentPickerOptions
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 options: DocumentPickerOptions = {
43
+ const files = await pickFile({
65
44
  multipleFiles,
66
- maxFiles,
67
45
  fileTypes,
68
46
  maxSize,
69
- excludedUris,
70
- };
71
- const selectedFiles = await pickFile(options);
47
+ maxFiles,
48
+ excludedUris
49
+ });
72
50
 
73
- // Eğer kullanıcı seçim yapmadan kapatırsa bazı sistemler boş array dönebilir.
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
- // Kullanıcının seçimi iptal etmesi bir "hata" sayılmamalı,
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.disabledButton]}
65
+ style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled]}
92
66
  onPress={handlePress}
93
- disabled={disabled}
67
+ disabled={disabled || isLoading}
94
68
  >
95
- <Text style={[styles.buttonText, ButtonTextStyle]}>
96
- {buttonPlaceHolder}
97
- </Text>
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: '#007AFF',
106
- paddingHorizontal: 20,
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
- buttonText: {
113
- color: '#FFFFFF',
114
- fontSize: 16,
115
- fontWeight: 'bold',
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
- // İhtiyaca göre pickFile'ı da export edebilirsiniz.
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;