react-native-my-uploader-android 1.0.27 → 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/android/src/main/java/com/myuploaderandroid/MyUploaderPackage.kt +1 -1
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DownloadFile","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_NativeModules","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DownloadFile","files","multipleDownload","disabled","debug","maxSize","fileTypes","buttonPlaceHolder","buttonIcon","ButtonStyle","ButtonTextStyle","onSuccess","onError","isLoading","setIsLoading","useState","handlePress","length","options","targetFiles","promises","map","url","NativeDownload","downloadFile","results","Promise","allSettled","final","successful","skipped","forEach","res","index","_targetFiles$index","originalUrl","status","push","localUri","value","_res$reason","reason","message","console","error","createElement","TouchableOpacity","style","styles","button","onPress","ActivityIndicator","color","Text","text","StyleSheet","create","backgroundColor","padding","borderRadius","alignItems","fontWeight","_default","exports"],"sources":["DownloadFile.tsx"],"sourcesContent":["import React, { useState } from 'react';\r\nimport { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';\r\nimport { NativeDownload } from '../NativeModules';\r\nimport type { DownloadFileProps, DownloadResult } from '../types';\r\n\r\nconst DownloadFile: React.FC<DownloadFileProps> = ({\r\n files,\r\n multipleDownload = false,\r\n disabled = false,\r\n debug = false,\r\n maxSize = 0,\r\n fileTypes = ['*/*'],\r\n buttonPlaceHolder = 'Dosyaları İndir',\r\n buttonIcon,\r\n ButtonStyle,\r\n ButtonTextStyle,\r\n onSuccess,\r\n onError,\r\n}) => {\r\n const [isLoading, setIsLoading] = useState(false);\r\n\r\n const handlePress = async () => {\r\n if (disabled || isLoading || !files.length) return;\r\n setIsLoading(true);\r\n\r\n const options = { debug, maxSize, fileTypes };\r\n const targetFiles = multipleDownload ? files : [files[0]];\r\n\r\n try {\r\n const promises = targetFiles.map(url => NativeDownload.downloadFile(url, options));\r\n const results = await Promise.allSettled(promises);\r\n \r\n const final: DownloadResult = { successful: [], skipped: [] };\r\n\r\n results.forEach((res, index) => {\r\n const originalUrl = targetFiles[index] ?? \"\";\r\n if (res.status === 'fulfilled') {\r\n final.successful.push({ originalUrl, localUri: res.value });\r\n } else {\r\n final.skipped.push({ \r\n originalUrl, \r\n reason: res.reason?.message || \"Bilinmeyen Hata\" \r\n });\r\n }\r\n });\r\n\r\n if (onSuccess) onSuccess(final);\r\n } catch (e) {\r\n if (onError) onError(e);\r\n else console.error(e);\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 buttonIcon ? buttonIcon : <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: '#03DAC6',\r\n padding: 12,\r\n borderRadius: 8,\r\n alignItems: 'center',\r\n },\r\n text: { color: '#000', fontWeight: 'bold' },\r\n disabled: { backgroundColor: '#AAA' }\r\n});\r\n\r\nexport default DownloadFile;"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAAkD,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,C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CAAC,SAAS;MACRiC,YAAY,CAAC,KAAK,CAAC;IACrB;EACF,CAAC;EAED,oBACEtC,MAAA,CAAAe,OAAA,CAAAsD,aAAA,CAAClE,YAAA,CAAAmE,gBAAgB;IACfC,KAAK,EAAE,CAACC,MAAM,CAACC,MAAM,EAAExC,WAAW,EAAE,CAACN,QAAQ,IAAIU,SAAS,KAAKmC,MAAM,CAAC7C,QAAQ,CAAE;IAChF+C,OAAO,EAAElC,WAAY;IACrBb,QAAQ,EAAEA,QAAQ,IAAIU;EAAU,GAE/BA,SAAS,gBACRrC,MAAA,CAAAe,OAAA,CAAAsD,aAAA,CAAClE,YAAA,CAAAwE,iBAAiB;IAACC,KAAK,EAAC;EAAM,CAAE,CAAC,GAElC5C,UAAU,GAAGA,UAAU,gBAAGhC,MAAA,CAAAe,OAAA,CAAAsD,aAAA,CAAClE,YAAA,CAAA0E,IAAI;IAACN,KAAK,EAAE,CAACC,MAAM,CAACM,IAAI,EAAE5C,eAAe;EAAE,GAAEH,iBAAwB,CAElF,CAAC;AAEvB,CAAC;AAED,MAAMyC,MAAM,GAAGO,uBAAU,CAACC,MAAM,CAAC;EAC/BP,MAAM,EAAE;IACNQ,eAAe,EAAE,SAAS;IAC1BC,OAAO,EAAE,EAAE;IACXC,YAAY,EAAE,CAAC;IACfC,UAAU,EAAE;EACd,CAAC;EACDN,IAAI,EAAE;IAAEF,KAAK,EAAE,MAAM;IAAES,UAAU,EAAE;EAAO,CAAC;EAC3C1D,QAAQ,EAAE;IAAEsD,eAAe,EAAE;EAAO;AACtC,CAAC,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAxE,OAAA,GAEYS,YAAY","ignoreList":[]}
|
|
@@ -3,117 +3,91 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
6
|
+
exports.pickFile = exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _reactNative = require("react-native");
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
9
|
+
var _NativeModules = require("../NativeModules");
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
|
+
// 1. Standalone pickFile Fonksiyonu
|
|
12
|
+
const pickFile = async (options = {}) => {
|
|
13
|
+
var _options$multipleFile, _options$maxFiles, _options$maxSize, _options$fileTypes, _options$excludedUris;
|
|
14
|
+
if (!_NativeModules.NativePicker) throw new Error("DocumentPicker module is not linked.");
|
|
17
15
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
multipleFiles = false,
|
|
24
|
-
maxFiles = 0,
|
|
25
|
-
...rest
|
|
26
|
-
} = options;
|
|
27
|
-
if (!multipleFiles && maxFiles > 1) {
|
|
28
|
-
throw new Error('`maxFiles` cannot be greater than 1 when `multipleFiles` is false.');
|
|
29
|
-
}
|
|
30
|
-
let effectiveMaxFiles = maxFiles;
|
|
31
|
-
if (multipleFiles && maxFiles === 0) {
|
|
32
|
-
effectiveMaxFiles = 3;
|
|
33
|
-
}
|
|
34
|
-
const finalOptions = {
|
|
35
|
-
...rest,
|
|
36
|
-
multipleFiles,
|
|
37
|
-
maxFiles: effectiveMaxFiles,
|
|
38
|
-
excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : [],
|
|
16
|
+
// Native tarafa gönderilecek options
|
|
17
|
+
const nativeOptions = {
|
|
18
|
+
multipleFiles: (_options$multipleFile = options.multipleFiles) !== null && _options$multipleFile !== void 0 ? _options$multipleFile : false,
|
|
19
|
+
maxFiles: (_options$maxFiles = options.maxFiles) !== null && _options$maxFiles !== void 0 ? _options$maxFiles : 0,
|
|
20
|
+
maxSize: (_options$maxSize = options.maxSize) !== null && _options$maxSize !== void 0 ? _options$maxSize : 0,
|
|
39
21
|
fileTypes: (_options$fileTypes = options.fileTypes) !== null && _options$fileTypes !== void 0 ? _options$fileTypes : ['*/*'],
|
|
40
|
-
|
|
22
|
+
excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : []
|
|
41
23
|
};
|
|
42
|
-
return
|
|
43
|
-
}
|
|
24
|
+
return await _NativeModules.NativePicker.openDocument(nativeOptions);
|
|
25
|
+
};
|
|
44
26
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
maxSize = 0,
|
|
52
|
-
excludedUris = [],
|
|
53
|
-
// UI Props with defaults
|
|
54
|
-
buttonPlaceHolder = 'Dosya Seçin...',
|
|
27
|
+
// 2. MyUploader Bileşeni
|
|
28
|
+
exports.pickFile = pickFile;
|
|
29
|
+
const MyUploader = ({
|
|
30
|
+
onSelect,
|
|
31
|
+
onError,
|
|
32
|
+
buttonPlaceHolder = "Dosya Seç",
|
|
55
33
|
ButtonStyle,
|
|
56
34
|
ButtonTextStyle,
|
|
57
35
|
disabled = false,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
36
|
+
multipleFiles = false,
|
|
37
|
+
fileTypes = ['*/*'],
|
|
38
|
+
maxSize = 0,
|
|
39
|
+
maxFiles = 0,
|
|
40
|
+
excludedUris = []
|
|
61
41
|
}) => {
|
|
42
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
62
43
|
const handlePress = async () => {
|
|
44
|
+
if (disabled || isLoading) return;
|
|
45
|
+
setIsLoading(true);
|
|
63
46
|
try {
|
|
64
|
-
const
|
|
47
|
+
const files = await pickFile({
|
|
65
48
|
multipleFiles,
|
|
66
|
-
maxFiles,
|
|
67
49
|
fileTypes,
|
|
68
50
|
maxSize,
|
|
51
|
+
maxFiles,
|
|
69
52
|
excludedUris
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
}
|
|
53
|
+
});
|
|
54
|
+
onSelect(files);
|
|
78
55
|
} catch (error) {
|
|
79
|
-
|
|
80
|
-
// bu yüzden sadece konsola yazdırıp onError'ı tetiklemeyebiliriz.
|
|
81
|
-
// Native kodunuz "E_PICKER_CANCELLED" koduyla reject ediyor.
|
|
82
|
-
if (error.code !== 'E_PICKER_CANCELLED') {
|
|
56
|
+
if (onError) {
|
|
83
57
|
onError(error);
|
|
58
|
+
} else {
|
|
59
|
+
console.error("MyUploader Error:", error);
|
|
84
60
|
}
|
|
61
|
+
} finally {
|
|
62
|
+
setIsLoading(false);
|
|
85
63
|
}
|
|
86
64
|
};
|
|
87
65
|
return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
88
|
-
style: [styles.button, ButtonStyle, disabled && styles.
|
|
66
|
+
style: [styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled],
|
|
89
67
|
onPress: handlePress,
|
|
90
|
-
disabled: disabled
|
|
91
|
-
}, /*#__PURE__*/_react.default.createElement(_reactNative.
|
|
92
|
-
|
|
68
|
+
disabled: disabled || isLoading
|
|
69
|
+
}, isLoading ? /*#__PURE__*/_react.default.createElement(_reactNative.ActivityIndicator, {
|
|
70
|
+
color: "#FFF"
|
|
71
|
+
}) : /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
72
|
+
style: [styles.text, ButtonTextStyle]
|
|
93
73
|
}, buttonPlaceHolder));
|
|
94
74
|
};
|
|
95
|
-
|
|
96
|
-
// Varsayılan stiller
|
|
97
75
|
const styles = _reactNative.StyleSheet.create({
|
|
98
76
|
button: {
|
|
99
|
-
backgroundColor: '#
|
|
100
|
-
|
|
101
|
-
paddingVertical: 10,
|
|
77
|
+
backgroundColor: '#6200EE',
|
|
78
|
+
padding: 12,
|
|
102
79
|
borderRadius: 8,
|
|
103
80
|
alignItems: 'center',
|
|
104
81
|
justifyContent: 'center'
|
|
105
82
|
},
|
|
106
|
-
|
|
107
|
-
color: '#
|
|
108
|
-
|
|
109
|
-
|
|
83
|
+
text: {
|
|
84
|
+
color: '#FFF',
|
|
85
|
+
fontWeight: '600',
|
|
86
|
+
fontSize: 16
|
|
110
87
|
},
|
|
111
|
-
|
|
112
|
-
backgroundColor: '#
|
|
88
|
+
disabled: {
|
|
89
|
+
backgroundColor: '#B0B0B0'
|
|
113
90
|
}
|
|
114
91
|
});
|
|
115
|
-
|
|
116
|
-
// İhtiyaca göre pickFile'ı da export edebilirsiniz.
|
|
117
|
-
// Component'i varsayılan olarak export ediyoruz.
|
|
118
|
-
var _default = exports.default = MyUploaderAndroid;
|
|
92
|
+
var _default = exports.default = MyUploader;
|
|
119
93
|
//# sourceMappingURL=MyUploader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_NativeModules","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","pickFile","options","_options$multipleFile","_options$maxFiles","_options$maxSize","_options$fileTypes","_options$excludedUris","NativePicker","Error","nativeOptions","multipleFiles","maxFiles","maxSize","fileTypes","excludedUris","openDocument","exports","MyUploader","onSelect","onError","buttonPlaceHolder","ButtonStyle","ButtonTextStyle","disabled","isLoading","setIsLoading","useState","handlePress","files","error","console","createElement","TouchableOpacity","style","styles","button","onPress","ActivityIndicator","color","Text","text","StyleSheet","create","backgroundColor","padding","borderRadius","alignItems","justifyContent","fontWeight","fontSize","_default"],"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":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAAgD,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAA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,EAAEA,QAAQ,IAAIC;EAAU,GAE/BA,SAAS,gBACRhD,MAAA,CAAAe,OAAA,CAAAwC,aAAA,CAACpD,YAAA,CAAA0D,iBAAiB;IAACC,KAAK,EAAC;EAAM,CAAE,CAAC,gBAElC9D,MAAA,CAAAe,OAAA,CAAAwC,aAAA,CAACpD,YAAA,CAAA4D,IAAI;IAACN,KAAK,EAAE,CAACC,MAAM,CAACM,IAAI,EAAElB,eAAe;EAAE,GAAEF,iBAAwB,CAExD,CAAC;AAEvB,CAAC;AAED,MAAMc,MAAM,GAAGO,uBAAU,CAACC,MAAM,CAAC;EAC/BP,MAAM,EAAE;IACNQ,eAAe,EAAE,SAAS;IAC1BC,OAAO,EAAE,EAAE;IACXC,YAAY,EAAE,CAAC;IACfC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE;EAClB,CAAC;EACDP,IAAI,EAAE;IACJF,KAAK,EAAE,MAAM;IACbU,UAAU,EAAE,KAAK;IACjBC,QAAQ,EAAE;EACZ,CAAC;EACD1B,QAAQ,EAAE;IACRoB,eAAe,EAAE;EACnB;AACF,CAAC,CAAC;AAAC,IAAAO,QAAA,GAAAlC,OAAA,CAAAzB,OAAA,GAEY0B,UAAU","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.d.ts"],"sourcesContent":["import * as React from 'react';\r\nimport type {
|
|
1
|
+
{"version":3,"names":["_types","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"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,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
pickFile: true,
|
|
8
|
-
|
|
8
|
+
DownloadFile: true
|
|
9
9
|
};
|
|
10
|
-
Object.defineProperty(exports, "
|
|
10
|
+
Object.defineProperty(exports, "DownloadFile", {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
get: function () {
|
|
13
13
|
return _DownloadFile.default;
|
|
@@ -36,6 +36,6 @@ Object.keys(_types).forEach(function (key) {
|
|
|
36
36
|
});
|
|
37
37
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
38
38
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
39
|
-
//
|
|
40
|
-
var _default = exports.default = _MyUploader.default;
|
|
39
|
+
// 1. MyUploader'ı DEFAULT olarak dışa aktar (import MyUploader from ... için)
|
|
40
|
+
var _default = exports.default = _MyUploader.default; // 2. Diğerlerini NAMED olarak dışa aktar (import { DownloadFile, pickFile } ... için)
|
|
41
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_MyUploader","_interopRequireWildcard","require","_DownloadFile","_interopRequireDefault","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","set","getOwnPropertyDescriptor","_default","
|
|
1
|
+
{"version":3,"names":["_MyUploader","_interopRequireWildcard","require","_DownloadFile","_interopRequireDefault","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","set","getOwnPropertyDescriptor","_default","MyUploader"],"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,IAAAA,WAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAC,sBAAA,CAAAF,OAAA;AAUA,IAAAG,MAAA,GAAAH,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OA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AAAK,CAAA,CAAAT,GAAA,IAAAS,CAAA,CAAAI,GAAA,IAAAL,CAAA,CAAAE,CAAA,EAAAN,CAAA,EAAAK,CAAA,IAAAC,CAAA,CAAAN,CAAA,IAAAH,CAAA,CAAAG,CAAA,WAAAM,CAAA,KAAAT,CAAA,EAAAG,CAAA;AAPxB;AAAA,IAAAW,QAAA,GAAAlB,OAAA,CAAAM,OAAA,GACea,mBAAU,EAEzB","ignoreList":[]}
|
|
@@ -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":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
const {
|
|
3
|
+
DownloadFile,
|
|
4
|
+
DocumentPicker
|
|
5
|
+
} = NativeModules;
|
|
6
|
+
if (!DownloadFile) console.warn("MyUploader: DownloadFile native module not found.");
|
|
7
|
+
if (!DocumentPicker) console.warn("MyUploader: DocumentPicker native module not found.");
|
|
8
|
+
export const NativeDownload = DownloadFile;
|
|
9
|
+
export const NativePicker = DocumentPicker;
|
|
10
|
+
//# sourceMappingURL=NativeModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModules","DownloadFile","DocumentPicker","console","warn","NativeDownload","NativePicker"],"sources":["NativeModules.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\r\n\r\nconst { DownloadFile, DocumentPicker } = NativeModules;\r\n\r\nif (!DownloadFile) console.warn(\"MyUploader: DownloadFile native module not found.\");\r\nif (!DocumentPicker) console.warn(\"MyUploader: DocumentPicker native module not found.\");\r\n\r\nexport const NativeDownload = DownloadFile;\r\nexport const NativePicker = DocumentPicker;"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAE5C,MAAM;EAAEC,YAAY;EAAEC;AAAe,CAAC,GAAGF,aAAa;AAEtD,IAAI,CAACC,YAAY,EAAEE,OAAO,CAACC,IAAI,CAAC,mDAAmD,CAAC;AACpF,IAAI,CAACF,cAAc,EAAEC,OAAO,CAACC,IAAI,CAAC,qDAAqD,CAAC;AAExF,OAAO,MAAMC,cAAc,GAAGJ,YAAY;AAC1C,OAAO,MAAMK,YAAY,GAAGJ,cAAc","ignoreList":[]}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
DownloadFile: DownloadFileModule
|
|
5
|
-
} = NativeModules;
|
|
2
|
+
import { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
|
|
3
|
+
import { NativeDownload } from '../NativeModules';
|
|
6
4
|
const DownloadFile = ({
|
|
7
5
|
files,
|
|
8
|
-
|
|
6
|
+
multipleDownload = false,
|
|
9
7
|
disabled = false,
|
|
10
8
|
debug = false,
|
|
11
9
|
maxSize = 0,
|
|
@@ -14,82 +12,72 @@ const DownloadFile = ({
|
|
|
14
12
|
buttonIcon,
|
|
15
13
|
ButtonStyle,
|
|
16
14
|
ButtonTextStyle,
|
|
17
|
-
onSuccess
|
|
18
|
-
onError
|
|
15
|
+
onSuccess,
|
|
16
|
+
onError
|
|
19
17
|
}) => {
|
|
20
18
|
const [isLoading, setIsLoading] = useState(false);
|
|
21
19
|
const handlePress = async () => {
|
|
22
|
-
if (!
|
|
23
|
-
onError(new Error("DownloadFile native module is not available."));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
20
|
+
if (disabled || isLoading || !files.length) return;
|
|
26
21
|
setIsLoading(true);
|
|
27
|
-
const
|
|
22
|
+
const options = {
|
|
23
|
+
debug,
|
|
28
24
|
maxSize,
|
|
29
|
-
fileTypes
|
|
30
|
-
debug
|
|
25
|
+
fileTypes
|
|
31
26
|
};
|
|
27
|
+
const targetFiles = multipleDownload ? files : [files[0]];
|
|
32
28
|
try {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const finalResult = {
|
|
29
|
+
const promises = targetFiles.map(url => NativeDownload.downloadFile(url, options));
|
|
30
|
+
const results = await Promise.allSettled(promises);
|
|
31
|
+
const final = {
|
|
37
32
|
successful: [],
|
|
38
33
|
skipped: []
|
|
39
34
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
finalResult.successful.push({
|
|
35
|
+
results.forEach((res, index) => {
|
|
36
|
+
var _targetFiles$index;
|
|
37
|
+
const originalUrl = (_targetFiles$index = targetFiles[index]) !== null && _targetFiles$index !== void 0 ? _targetFiles$index : "";
|
|
38
|
+
if (res.status === 'fulfilled') {
|
|
39
|
+
final.successful.push({
|
|
46
40
|
originalUrl,
|
|
47
|
-
|
|
48
|
-
localUri: result.value
|
|
41
|
+
localUri: res.value
|
|
49
42
|
});
|
|
50
43
|
} else {
|
|
51
|
-
|
|
44
|
+
var _res$reason;
|
|
45
|
+
final.skipped.push({
|
|
52
46
|
originalUrl,
|
|
53
|
-
|
|
54
|
-
reason: result.reason.message
|
|
47
|
+
reason: ((_res$reason = res.reason) === null || _res$reason === void 0 ? void 0 : _res$reason.message) || "Bilinmeyen Hata"
|
|
55
48
|
});
|
|
56
49
|
}
|
|
57
50
|
});
|
|
58
|
-
onSuccess(
|
|
59
|
-
} catch (
|
|
60
|
-
onError(error);
|
|
51
|
+
if (onSuccess) onSuccess(final);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (onError) onError(e);else console.error(e);
|
|
61
54
|
} finally {
|
|
62
55
|
setIsLoading(false);
|
|
63
56
|
}
|
|
64
57
|
};
|
|
65
|
-
const content = isLoading ? /*#__PURE__*/React.createElement(ActivityIndicator, {
|
|
66
|
-
color: "#FFFFFF"
|
|
67
|
-
}) : buttonIcon || /*#__PURE__*/React.createElement(Text, {
|
|
68
|
-
style: [styles.buttonText, ButtonTextStyle]
|
|
69
|
-
}, buttonPlaceHolder);
|
|
70
58
|
return /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
71
|
-
style: [styles.button, ButtonStyle, (disabled || isLoading) && styles.
|
|
59
|
+
style: [styles.button, ButtonStyle, (disabled || isLoading) && styles.disabled],
|
|
72
60
|
onPress: handlePress,
|
|
73
61
|
disabled: disabled || isLoading
|
|
74
|
-
},
|
|
62
|
+
}, isLoading ? /*#__PURE__*/React.createElement(ActivityIndicator, {
|
|
63
|
+
color: "#FFF"
|
|
64
|
+
}) : buttonIcon ? buttonIcon : /*#__PURE__*/React.createElement(Text, {
|
|
65
|
+
style: [styles.text, ButtonTextStyle]
|
|
66
|
+
}, buttonPlaceHolder));
|
|
75
67
|
};
|
|
76
68
|
const styles = StyleSheet.create({
|
|
77
69
|
button: {
|
|
78
|
-
backgroundColor: '#
|
|
79
|
-
|
|
80
|
-
paddingVertical: 10,
|
|
70
|
+
backgroundColor: '#03DAC6',
|
|
71
|
+
padding: 12,
|
|
81
72
|
borderRadius: 8,
|
|
82
|
-
alignItems: 'center'
|
|
83
|
-
justifyContent: 'center',
|
|
84
|
-
flexDirection: 'row'
|
|
73
|
+
alignItems: 'center'
|
|
85
74
|
},
|
|
86
|
-
|
|
87
|
-
color: '#
|
|
88
|
-
fontSize: 16,
|
|
75
|
+
text: {
|
|
76
|
+
color: '#000',
|
|
89
77
|
fontWeight: 'bold'
|
|
90
78
|
},
|
|
91
|
-
|
|
92
|
-
backgroundColor: '#
|
|
79
|
+
disabled: {
|
|
80
|
+
backgroundColor: '#AAA'
|
|
93
81
|
}
|
|
94
82
|
});
|
|
95
83
|
export default DownloadFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","
|
|
1
|
+
{"version":3,"names":["React","useState","TouchableOpacity","Text","StyleSheet","ActivityIndicator","NativeDownload","DownloadFile","files","multipleDownload","disabled","debug","maxSize","fileTypes","buttonPlaceHolder","buttonIcon","ButtonStyle","ButtonTextStyle","onSuccess","onError","isLoading","setIsLoading","handlePress","length","options","targetFiles","promises","map","url","downloadFile","results","Promise","allSettled","final","successful","skipped","forEach","res","index","_targetFiles$index","originalUrl","status","push","localUri","value","_res$reason","reason","message","e","console","error","createElement","style","styles","button","onPress","color","text","create","backgroundColor","padding","borderRadius","alignItems","fontWeight"],"sources":["DownloadFile.tsx"],"sourcesContent":["import React, { useState } from 'react';\r\nimport { TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';\r\nimport { NativeDownload } from '../NativeModules';\r\nimport type { DownloadFileProps, DownloadResult } from '../types';\r\n\r\nconst DownloadFile: React.FC<DownloadFileProps> = ({\r\n files,\r\n multipleDownload = false,\r\n disabled = false,\r\n debug = false,\r\n maxSize = 0,\r\n fileTypes = ['*/*'],\r\n buttonPlaceHolder = 'Dosyaları İndir',\r\n buttonIcon,\r\n ButtonStyle,\r\n ButtonTextStyle,\r\n onSuccess,\r\n onError,\r\n}) => {\r\n const [isLoading, setIsLoading] = useState(false);\r\n\r\n const handlePress = async () => {\r\n if (disabled || isLoading || !files.length) return;\r\n setIsLoading(true);\r\n\r\n const options = { debug, maxSize, fileTypes };\r\n const targetFiles = multipleDownload ? files : [files[0]];\r\n\r\n try {\r\n const promises = targetFiles.map(url => NativeDownload.downloadFile(url, options));\r\n const results = await Promise.allSettled(promises);\r\n \r\n const final: DownloadResult = { successful: [], skipped: [] };\r\n\r\n results.forEach((res, index) => {\r\n const originalUrl = targetFiles[index] ?? \"\";\r\n if (res.status === 'fulfilled') {\r\n final.successful.push({ originalUrl, localUri: res.value });\r\n } else {\r\n final.skipped.push({ \r\n originalUrl, \r\n reason: res.reason?.message || \"Bilinmeyen Hata\" \r\n });\r\n }\r\n });\r\n\r\n if (onSuccess) onSuccess(final);\r\n } catch (e) {\r\n if (onError) onError(e);\r\n else console.error(e);\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 buttonIcon ? buttonIcon : <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: '#03DAC6',\r\n padding: 12,\r\n borderRadius: 8,\r\n alignItems: 'center',\r\n },\r\n text: { color: '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