react-native-my-uploader-android 1.0.24 → 1.0.26
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/README.md +44 -176
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/myuploaderandroid/DownloadFileModule.kt +144 -0
- package/android/src/main/java/com/myuploaderandroid/MyUploaderPackage.kt +4 -1
- package/lib/commonjs/components/DownloadFile.js +103 -0
- package/lib/commonjs/components/DownloadFile.js.map +1 -0
- package/lib/commonjs/components/MyUploader.js +119 -0
- package/lib/commonjs/components/MyUploader.js.map +1 -0
- package/lib/commonjs/index.d.js.map +1 -1
- package/lib/commonjs/index.js +30 -108
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/components/DownloadFile.js +96 -0
- package/lib/module/components/DownloadFile.js.map +1 -0
- package/lib/module/components/MyUploader.js +112 -0
- package/lib/module/components/MyUploader.js.map +1 -0
- package/lib/module/index.d.js.map +1 -1
- package/lib/module/index.js +6 -109
- 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 +106 -0
- package/src/{index.tsx → components/MyUploader.tsx} +2 -2
- package/src/index.d.ts +2 -2
- package/src/index.ts +10 -0
- package/src/types.ts +38 -0
package/README.md
CHANGED
|
@@ -1,192 +1,60 @@
|
|
|
1
1
|
# react-native-my-uploader
|
|
2
2
|
|
|
3
|
-
file uploader
|
|
3
|
+
file uploader for android
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npm install react-native-my-uploader
|
|
9
|
+
npm install react-native-my-uploader-android
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
## Usage
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
```js
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
console.error('Dosya seçme hatası:', error);
|
|
60
|
-
Alert.alert('Bir Hata Oluştu', error.message || 'Bilinmeyen bir hata.');
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<View style={styles.container}>
|
|
66
|
-
<StatusBar barStyle="dark-content" />
|
|
67
|
-
<View style={styles.header}>
|
|
68
|
-
<Text style={styles.title}>Dosya Yükleyici Paket Testi</Text>
|
|
69
|
-
</View>
|
|
70
|
-
|
|
71
|
-
<View style={styles.buttonGrid}>
|
|
72
|
-
<Button
|
|
73
|
-
title="Tek Bir Görüntü Seç"
|
|
74
|
-
onPress={() =>
|
|
75
|
-
handlePickFile({
|
|
76
|
-
multipleFiles: false,
|
|
77
|
-
fileTypes: ['image/*'],
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
/>
|
|
81
|
-
<Button
|
|
82
|
-
title="birden Fazla Dosya Seç (Maks 2MB)"
|
|
83
|
-
onPress={() =>
|
|
84
|
-
handlePickFile({
|
|
85
|
-
multipleFiles: true,
|
|
86
|
-
fileTypes: ['application/*'],
|
|
87
|
-
maxSize: 2,
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
/>
|
|
91
|
-
<Button
|
|
92
|
-
title="Listeyi Temizle"
|
|
93
|
-
color="#c0392b"
|
|
94
|
-
onPress={() => setSelectedFiles([])}
|
|
95
|
-
/>
|
|
96
|
-
</View>
|
|
97
|
-
|
|
98
|
-
<View style={styles.resultsArea}>
|
|
99
|
-
<Text style={styles.resultsTitle}>
|
|
100
|
-
Seçilen Dosyalar ({selectedFiles.length} adet)
|
|
101
|
-
</Text>
|
|
102
|
-
<ScrollView contentContainerStyle={styles.scrollViewContent}>
|
|
103
|
-
{selectedFiles.length > 0 ? (
|
|
104
|
-
selectedFiles.map((file, index) => (
|
|
105
|
-
<View key={`${file.fileUri}-${index}`} style={styles.fileCard}>
|
|
106
|
-
<Text style={styles.fileName} numberOfLines={1}>
|
|
107
|
-
{file.fileName}
|
|
108
|
-
</Text>
|
|
109
|
-
<Text style={styles.fileDetail}>
|
|
110
|
-
Boyut: {(file.fileSize / 1024).toFixed(2)} KB
|
|
111
|
-
</Text>
|
|
112
|
-
</View>
|
|
113
|
-
))
|
|
114
|
-
) : (
|
|
115
|
-
<Text style={styles.noFilesText}>
|
|
116
|
-
Seçilen dosya yok.
|
|
117
|
-
</Text>
|
|
118
|
-
)}
|
|
119
|
-
</ScrollView>
|
|
120
|
-
</View>
|
|
121
|
-
</View>
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const styles = StyleSheet.create({
|
|
126
|
-
container: {
|
|
127
|
-
flex: 1,
|
|
128
|
-
backgroundColor: '#f0f2f5',
|
|
129
|
-
},
|
|
130
|
-
header: {
|
|
131
|
-
padding: 20,
|
|
132
|
-
alignItems: 'center',
|
|
133
|
-
},
|
|
134
|
-
title: {
|
|
135
|
-
fontSize: 22,
|
|
136
|
-
fontWeight: 'bold',
|
|
137
|
-
color: '#1c1e21',
|
|
138
|
-
},
|
|
139
|
-
buttonGrid: {
|
|
140
|
-
paddingHorizontal: 20,
|
|
141
|
-
gap: 10,
|
|
142
|
-
},
|
|
143
|
-
resultsArea: {
|
|
144
|
-
flex: 1,
|
|
145
|
-
marginTop: 20,
|
|
146
|
-
borderTopWidth: 1,
|
|
147
|
-
borderTopColor: '#dddfe2',
|
|
148
|
-
paddingHorizontal: 20,
|
|
149
|
-
},
|
|
150
|
-
resultsTitle: {
|
|
151
|
-
fontSize: 18,
|
|
152
|
-
fontWeight: '600',
|
|
153
|
-
paddingVertical: 15,
|
|
154
|
-
color: '#1c1e21',
|
|
155
|
-
},
|
|
156
|
-
scrollViewContent: {
|
|
157
|
-
paddingBottom: 20,
|
|
158
|
-
},
|
|
159
|
-
fileCard: {
|
|
160
|
-
backgroundColor: '#ffffff',
|
|
161
|
-
padding: 15,
|
|
162
|
-
borderRadius: 8,
|
|
163
|
-
marginBottom: 10,
|
|
164
|
-
shadowColor: '#000',
|
|
165
|
-
shadowOffset: {width: 0, height: 1},
|
|
166
|
-
shadowOpacity: 0.2,
|
|
167
|
-
shadowRadius: 1.41,
|
|
168
|
-
elevation: 2,
|
|
169
|
-
},
|
|
170
|
-
fileName: {
|
|
171
|
-
fontSize: 16,
|
|
172
|
-
fontWeight: 'bold',
|
|
173
|
-
color: '#000',
|
|
174
|
-
},
|
|
175
|
-
fileDetail: {
|
|
176
|
-
fontSize: 13,
|
|
177
|
-
color: '#555',
|
|
178
|
-
marginTop: 4,
|
|
179
|
-
},
|
|
180
|
-
noFilesText: {
|
|
181
|
-
textAlign: 'center',
|
|
182
|
-
color: '#888',
|
|
183
|
-
marginTop: 30,
|
|
184
|
-
fontStyle: 'italic',
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
export default App;
|
|
16
|
+
import MyUploader,{FileInfo} from 'react-native-my-uploader-android';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const [selectedFiles, setSelectedFiles] = useState<FileInfo[]>([]); // response= base64,fileName,fileSize,fileType,FileUri
|
|
20
|
+
|
|
21
|
+
//for "react-native-my-uploader-android": "^1.0.25" version
|
|
22
|
+
<MyUploader
|
|
23
|
+
multipleFiles={false}
|
|
24
|
+
// maxFiles={3}
|
|
25
|
+
maxSize={5} // 5MB
|
|
26
|
+
fileTypes={["*/*"]}
|
|
27
|
+
buttonPlaceHolder="Dosya Seç (En Fazla 3)"
|
|
28
|
+
ButtonStyle={styles.customButton}
|
|
29
|
+
ButtonTextStyle={styles.customButtonText}
|
|
30
|
+
onSelect={(files) => {
|
|
31
|
+
console.log('Dosyalar seçildi:', files);
|
|
32
|
+
// Yeni seçilenleri mevcut listeye ekle
|
|
33
|
+
setSelectedFiles(prevFiles => [...prevFiles, ...files]);
|
|
34
|
+
}}
|
|
35
|
+
onError={(error) => {
|
|
36
|
+
Alert.alert(`Bir hata oluştu: ${error.message}`);
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<MyUploader
|
|
41
|
+
multipleFiles={true}
|
|
42
|
+
maxFiles={3}
|
|
43
|
+
maxSize={5} // 5MB
|
|
44
|
+
fileTypes={['application/pdf', 'image/jpeg']}
|
|
45
|
+
buttonPlaceHolder="Dosya Seç (En Fazla 3)"
|
|
46
|
+
ButtonStyle={styles.customButton}
|
|
47
|
+
ButtonTextStyle={styles.customButtonText}
|
|
48
|
+
onSelect={(files) => {
|
|
49
|
+
console.log('Dosyalar seçildi:', files);
|
|
50
|
+
// Yeni seçilenleri mevcut listeye ekle
|
|
51
|
+
setSelectedFiles(prevFiles => [...prevFiles, ...files]);
|
|
52
|
+
}}
|
|
53
|
+
onError={(error) => {
|
|
54
|
+
Alert.alert(`Bir hata oluştu: ${error.message}`);
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
|
|
190
58
|
```
|
|
191
59
|
|
|
192
60
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package com.myuploader
|
|
2
|
+
|
|
3
|
+
import android.app.DownloadManager
|
|
4
|
+
import android.content.BroadcastReceiver
|
|
5
|
+
import android.content.Context
|
|
6
|
+
import android.content.Intent
|
|
7
|
+
import android.content.IntentFilter
|
|
8
|
+
import android.net.Uri
|
|
9
|
+
import android.os.Build
|
|
10
|
+
import android.os.Environment
|
|
11
|
+
import android.util.Log
|
|
12
|
+
import android.webkit.CookieManager
|
|
13
|
+
import android.webkit.URLUtil
|
|
14
|
+
import com.facebook.react.bridge.*
|
|
15
|
+
import com.myuploader.BuildConfig
|
|
16
|
+
import java.net.HttpURLConnection
|
|
17
|
+
import java.net.URL
|
|
18
|
+
|
|
19
|
+
class DownloadFileModule(private val reactContext: ReactApplicationContext) :
|
|
20
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
21
|
+
|
|
22
|
+
private val TAG = "DownloadFileModule"
|
|
23
|
+
private val downloadPromises = mutableMapOf<Long, Promise>()
|
|
24
|
+
|
|
25
|
+
override fun getName(): String = "DownloadFile"
|
|
26
|
+
|
|
27
|
+
init {
|
|
28
|
+
val receiver = object : BroadcastReceiver() {
|
|
29
|
+
override fun onReceive(context: Context, intent: Intent) {
|
|
30
|
+
val downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
|
|
31
|
+
if (downloadPromises.containsKey(downloadId)) {
|
|
32
|
+
val promise = downloadPromises[downloadId]
|
|
33
|
+
checkDownloadStatus(downloadId, promise)
|
|
34
|
+
downloadPromises.remove(downloadId)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
val intentFilter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
|
39
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
40
|
+
reactContext.registerReceiver(receiver, intentFilter, Context.RECEIVER_NOT_EXPORTED)
|
|
41
|
+
} else {
|
|
42
|
+
reactContext.registerReceiver(receiver, intentFilter)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@ReactMethod
|
|
47
|
+
fun downloadFile(fileUrl: String, options: ReadableMap, promise: Promise) {
|
|
48
|
+
val isDebug = if (options.hasKey("debug")) options.getBoolean("debug") else false
|
|
49
|
+
val shouldLog = BuildConfig.DEBUG && isDebug
|
|
50
|
+
val maxSizeMB = if (options.hasKey("maxSize")) options.getDouble("maxSize") else 0.0
|
|
51
|
+
|
|
52
|
+
if (shouldLog) Log.d(TAG, "İndirme isteği alındı. URL: $fileUrl")
|
|
53
|
+
|
|
54
|
+
Thread {
|
|
55
|
+
try {
|
|
56
|
+
val url = URL(fileUrl)
|
|
57
|
+
val connection = url.openConnection() as HttpURLConnection
|
|
58
|
+
val cookie = CookieManager.getInstance().getCookie(fileUrl)
|
|
59
|
+
if (cookie != null) connection.setRequestProperty("Cookie", cookie)
|
|
60
|
+
connection.requestMethod = "HEAD"
|
|
61
|
+
connection.connect()
|
|
62
|
+
|
|
63
|
+
val responseCode = connection.responseCode
|
|
64
|
+
if (responseCode !in 200..299) {
|
|
65
|
+
promise.reject("E_HTTP_ERROR", "Sunucu hatası: $responseCode")
|
|
66
|
+
return@Thread
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
val fileSize = connection.contentLengthLong
|
|
70
|
+
val contentType = connection.contentType
|
|
71
|
+
val contentDisposition = connection.getHeaderField("Content-Disposition")
|
|
72
|
+
val cleanContentType = contentType?.split(";")?.get(0)?.trim() ?: "*/*"
|
|
73
|
+
val fileName = URLUtil.guessFileName(fileUrl, contentDisposition, cleanContentType)
|
|
74
|
+
|
|
75
|
+
if (shouldLog) Log.d(TAG, "Dosya: $fileName, Boyut: $fileSize bytes, Tip: $cleanContentType")
|
|
76
|
+
|
|
77
|
+
if (maxSizeMB > 0 && fileSize > maxSizeMB * 1024 * 1024) {
|
|
78
|
+
promise.reject("E_FILE_TOO_LARGE", "Dosya boyutu (${(fileSize / 1024.0 / 1024.0).toInt()}MB) belirtilen limitten (${maxSizeMB}MB) büyük.")
|
|
79
|
+
return@Thread
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
val request = DownloadManager.Request(Uri.parse(fileUrl))
|
|
83
|
+
.setTitle(fileName)
|
|
84
|
+
.setDescription("İndiriliyor...")
|
|
85
|
+
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
|
86
|
+
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
|
|
87
|
+
.setAllowedOverMetered(true)
|
|
88
|
+
|
|
89
|
+
if (cookie != null) request.addRequestHeader("Cookie", cookie)
|
|
90
|
+
if (cleanContentType != "*/*") request.setMimeType(cleanContentType)
|
|
91
|
+
|
|
92
|
+
val downloadManager = reactContext.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
|
93
|
+
val downloadId = downloadManager.enqueue(request)
|
|
94
|
+
|
|
95
|
+
if (BuildConfig.DEBUG) Log.i(TAG, "İndirme sıraya eklendi. ID: #$downloadId")
|
|
96
|
+
downloadPromises[downloadId] = promise
|
|
97
|
+
|
|
98
|
+
} catch (e: Exception) {
|
|
99
|
+
if (BuildConfig.DEBUG) Log.e(TAG, "İndirme başlatılırken hata!", e)
|
|
100
|
+
promise.reject("E_DOWNLOAD_SETUP_FAILED", e.message)
|
|
101
|
+
}
|
|
102
|
+
}.start()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private fun checkDownloadStatus(id: Long, promise: Promise?) {
|
|
106
|
+
val downloadManager = reactContext.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
|
107
|
+
val query = DownloadManager.Query().setFilterById(id)
|
|
108
|
+
val cursor = downloadManager.query(query)
|
|
109
|
+
|
|
110
|
+
if (cursor.moveToFirst()) {
|
|
111
|
+
val statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)
|
|
112
|
+
val status = cursor.getInt(statusIndex)
|
|
113
|
+
|
|
114
|
+
if (status == DownloadManager.STATUS_SUCCESSFUL) {
|
|
115
|
+
val uriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)
|
|
116
|
+
val localUri = cursor.getString(uriIndex)
|
|
117
|
+
promise?.resolve(localUri)
|
|
118
|
+
} else {
|
|
119
|
+
val reasonIndex = cursor.getColumnIndex(DownloadManager.COLUMN_REASON)
|
|
120
|
+
val reason = cursor.getInt(reasonIndex)
|
|
121
|
+
val reasonText = getDownloadErrorReason(reason)
|
|
122
|
+
promise?.reject("E_DOWNLOAD_FAILED", "İndirme başarısız. Sebep: $reasonText (Kod: $reason)")
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
promise?.reject("E_DOWNLOAD_NOT_FOUND", "İndirme işlemi bulunamadı.")
|
|
126
|
+
}
|
|
127
|
+
cursor.close()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private fun getDownloadErrorReason(reasonCode: Int): String {
|
|
131
|
+
return when (reasonCode) {
|
|
132
|
+
DownloadManager.ERROR_CANNOT_RESUME -> "İndirme devam ettirilemiyor."
|
|
133
|
+
DownloadManager.ERROR_DEVICE_NOT_FOUND -> "Harici depolama bulunamadı."
|
|
134
|
+
DownloadManager.ERROR_FILE_ALREADY_EXISTS -> "Aynı isimde bir dosya zaten var."
|
|
135
|
+
DownloadManager.ERROR_FILE_ERROR -> "Dosya sistemi hatası."
|
|
136
|
+
DownloadManager.ERROR_HTTP_DATA_ERROR -> "Sunucu ile veri alışverişinde hata."
|
|
137
|
+
DownloadManager.ERROR_INSUFFICIENT_SPACE -> "Cihazda yeterli alan yok."
|
|
138
|
+
DownloadManager.ERROR_TOO_MANY_REDIRECTS -> "Çok fazla yönlendirme yapıldı."
|
|
139
|
+
DownloadManager.ERROR_UNHANDLED_HTTP_CODE -> "Sunucudan beklenmeyen HTTP kodu alındı."
|
|
140
|
+
DownloadManager.ERROR_UNKNOWN -> "Bilinmeyen bir hata oluştu."
|
|
141
|
+
else -> "Bilinmeyen hata."
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -7,7 +7,10 @@ import com.facebook.react.uimanager.ViewManager
|
|
|
7
7
|
|
|
8
8
|
class MyUploaderPackage : ReactPackage {
|
|
9
9
|
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
10
|
-
return listOf(
|
|
10
|
+
return listOf(
|
|
11
|
+
MyUploaderModule(reactContext)
|
|
12
|
+
DownloadFileModule(reactContext)
|
|
13
|
+
)
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
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); }
|
|
10
|
+
const {
|
|
11
|
+
DownloadFile: DownloadFileModule
|
|
12
|
+
} = _reactNative.NativeModules;
|
|
13
|
+
const DownloadFile = ({
|
|
14
|
+
files,
|
|
15
|
+
multipleLoad = false,
|
|
16
|
+
disabled = false,
|
|
17
|
+
debug = false,
|
|
18
|
+
maxSize = 0,
|
|
19
|
+
fileTypes = ['*/*'],
|
|
20
|
+
buttonPlaceHolder = 'Dosyaları İndir',
|
|
21
|
+
buttonIcon,
|
|
22
|
+
ButtonStyle,
|
|
23
|
+
ButtonTextStyle,
|
|
24
|
+
onSuccess = () => {},
|
|
25
|
+
onError = error => console.error('DownloadFile Error:', error)
|
|
26
|
+
}) => {
|
|
27
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
28
|
+
const handlePress = async () => {
|
|
29
|
+
if (!DownloadFileModule) {
|
|
30
|
+
onError(new Error("DownloadFile native module is not available."));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setIsLoading(true);
|
|
34
|
+
const downloadOptions = {
|
|
35
|
+
maxSize,
|
|
36
|
+
fileTypes,
|
|
37
|
+
debug
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
const filesToProcess = multipleLoad ? files : files.slice(0, 1);
|
|
41
|
+
const downloadPromises = filesToProcess.map(url => DownloadFileModule.downloadFile(url, downloadOptions));
|
|
42
|
+
const settledResults = await Promise.allSettled(downloadPromises);
|
|
43
|
+
const finalResult = {
|
|
44
|
+
successful: [],
|
|
45
|
+
skipped: []
|
|
46
|
+
};
|
|
47
|
+
settledResults.forEach((result, index) => {
|
|
48
|
+
// DÜZELTME: `filesToProcess[index]` ifadesinin sonuna `!` ekleyerek
|
|
49
|
+
// TypeScript'e bu değerin asla undefined olmayacağını bildiriyoruz.
|
|
50
|
+
const originalUrl = filesToProcess[index];
|
|
51
|
+
if (result.status === 'fulfilled') {
|
|
52
|
+
finalResult.successful.push({
|
|
53
|
+
originalUrl,
|
|
54
|
+
// Artık hata vermeyecek
|
|
55
|
+
localUri: result.value
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
finalResult.skipped.push({
|
|
59
|
+
originalUrl,
|
|
60
|
+
// Artık hata vermeyecek
|
|
61
|
+
reason: result.reason.message
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
onSuccess(finalResult);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
onError(error);
|
|
68
|
+
} finally {
|
|
69
|
+
setIsLoading(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const content = isLoading ? /*#__PURE__*/_react.default.createElement(_reactNative.ActivityIndicator, {
|
|
73
|
+
color: "#FFFFFF"
|
|
74
|
+
}) : buttonIcon || /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
75
|
+
style: [styles.buttonText, ButtonTextStyle]
|
|
76
|
+
}, buttonPlaceHolder);
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
78
|
+
style: [styles.button, ButtonStyle, (disabled || isLoading) && styles.disabledButton],
|
|
79
|
+
onPress: handlePress,
|
|
80
|
+
disabled: disabled || isLoading
|
|
81
|
+
}, content);
|
|
82
|
+
};
|
|
83
|
+
const styles = _reactNative.StyleSheet.create({
|
|
84
|
+
button: {
|
|
85
|
+
backgroundColor: '#008CBA',
|
|
86
|
+
paddingHorizontal: 20,
|
|
87
|
+
paddingVertical: 10,
|
|
88
|
+
borderRadius: 8,
|
|
89
|
+
alignItems: 'center',
|
|
90
|
+
justifyContent: 'center',
|
|
91
|
+
flexDirection: 'row'
|
|
92
|
+
},
|
|
93
|
+
buttonText: {
|
|
94
|
+
color: '#FFFFFF',
|
|
95
|
+
fontSize: 16,
|
|
96
|
+
fontWeight: 'bold'
|
|
97
|
+
},
|
|
98
|
+
disabledButton: {
|
|
99
|
+
backgroundColor: '#A9A9A9'
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
var _default = exports.default = DownloadFile;
|
|
103
|
+
//# sourceMappingURL=DownloadFile.js.map
|
|
@@ -0,0 +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","DownloadFileModule","NativeModules","files","multipleLoad","disabled","debug","maxSize","fileTypes","buttonPlaceHolder","buttonIcon","ButtonStyle","ButtonTextStyle","onSuccess","onError","error","console","isLoading","setIsLoading","useState","handlePress","Error","downloadOptions","filesToProcess","slice","downloadPromises","map","url","downloadFile","settledResults","Promise","allSettled","finalResult","successful","skipped","forEach","result","index","originalUrl","status","push","localUri","value","reason","message","content","createElement","ActivityIndicator","color","Text","style","styles","buttonText","TouchableOpacity","button","disabledButton","onPress","StyleSheet","create","backgroundColor","paddingHorizontal","paddingVertical","borderRadius","alignItems","justifyContent","flexDirection","fontSize","fontWeight","_default","exports"],"sources":["DownloadFile.tsx"],"sourcesContent":["import React, { useState } from 'react';\r\nimport { NativeModules, TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';\r\nimport type { DownloadFileProps, DownloadResult } from '../types';\r\n\r\nconst { DownloadFile: DownloadFileModule } = NativeModules;\r\n\r\nconst DownloadFile: React.FC<DownloadFileProps> = ({\r\n files,\r\n multipleLoad = 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 = (error) => console.error('DownloadFile Error:', error),\r\n}) => {\r\n const [isLoading, setIsLoading] = useState(false);\r\n\r\n const handlePress = async () => {\r\n if (!DownloadFileModule) {\r\n onError(new Error(\"DownloadFile native module is not available.\"));\r\n return;\r\n }\r\n\r\n setIsLoading(true);\r\n const downloadOptions = { maxSize, fileTypes, debug };\r\n\r\n try {\r\n const filesToProcess = multipleLoad ? files : files.slice(0, 1);\r\n const downloadPromises = filesToProcess.map(url => \r\n DownloadFileModule.downloadFile(url, downloadOptions)\r\n );\r\n\r\n const settledResults = await Promise.allSettled(downloadPromises);\r\n\r\n const finalResult: DownloadResult = { successful: [], skipped: [] };\r\n\r\n settledResults.forEach((result, index) => {\r\n // DÜZELTME: `filesToProcess[index]` ifadesinin sonuna `!` ekleyerek\r\n // TypeScript'e bu değerin asla undefined olmayacağını bildiriyoruz.\r\n const originalUrl = filesToProcess[index]!;\r\n\r\n if (result.status === 'fulfilled') {\r\n finalResult.successful.push({\r\n originalUrl, // Artık hata vermeyecek\r\n localUri: result.value,\r\n });\r\n } else {\r\n finalResult.skipped.push({\r\n originalUrl, // Artık hata vermeyecek\r\n reason: result.reason.message,\r\n });\r\n }\r\n });\r\n \r\n onSuccess(finalResult);\r\n\r\n } catch (error: any) {\r\n onError(error);\r\n } finally {\r\n setIsLoading(false);\r\n }\r\n };\r\n\r\n const content = isLoading ? (\r\n <ActivityIndicator color=\"#FFFFFF\" />\r\n ) : (\r\n buttonIcon || <Text style={[styles.buttonText, ButtonTextStyle]}>{buttonPlaceHolder}</Text>\r\n );\r\n\r\n return (\r\n <TouchableOpacity\r\n style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabledButton]}\r\n onPress={handlePress}\r\n disabled={disabled || isLoading}\r\n >\r\n {content}\r\n </TouchableOpacity>\r\n );\r\n};\r\n\r\nconst styles = StyleSheet.create({\r\n button: {\r\n backgroundColor: '#008CBA',\r\n paddingHorizontal: 20,\r\n paddingVertical: 10,\r\n borderRadius: 8,\r\n alignItems: 'center',\r\n justifyContent: 'center',\r\n flexDirection: 'row',\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\nexport default DownloadFile;"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAAoG,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,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,C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A,CAAClE,YAAA,CAAAmE,iBAAiB;IAACC,KAAK,EAAC;EAAS,CAAE,CAAC,GAErCtC,UAAU,iBAAIjC,MAAA,CAAAc,OAAA,CAAAuD,aAAA,CAAClE,YAAA,CAAAqE,IAAI;IAACC,KAAK,EAAE,CAACC,MAAM,CAACC,UAAU,EAAExC,eAAe;EAAE,GAAEH,iBAAwB,CAC3F;EAED,oBACEhC,MAAA,CAAAc,OAAA,CAAAuD,aAAA,CAAClE,YAAA,CAAAyE,gBAAgB;IACfH,KAAK,EAAE,CAACC,MAAM,CAACG,MAAM,EAAE3C,WAAW,EAAE,CAACN,QAAQ,IAAIY,SAAS,KAAKkC,MAAM,CAACI,cAAc,CAAE;IACtFC,OAAO,EAAEpC,WAAY;IACrBf,QAAQ,EAAEA,QAAQ,IAAIY;EAAU,GAE/B4B,OACe,CAAC;AAEvB,CAAC;AAED,MAAMM,MAAM,GAAGM,uBAAU,CAACC,MAAM,CAAC;EAC7BJ,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,QAAQ;IACxBC,aAAa,EAAE;EACjB,CAAC;EACDb,UAAU,EAAE;IACVJ,KAAK,EAAE,SAAS;IAChBkB,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE;EACd,CAAC;EACDZ,cAAc,EAAE;IACdI,eAAe,EAAE;EACnB;AACJ,CAAC,CAAC;AAAC,IAAAS,QAAA,GAAAC,OAAA,CAAA9E,OAAA,GAEYS,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.pickFile = pickFile;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactNative = require("react-native");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
const LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;
|
|
12
|
+
const DocumentPicker = _reactNative.NativeModules.DocumentPicker ? _reactNative.NativeModules.DocumentPicker : new Proxy({}, {
|
|
13
|
+
get() {
|
|
14
|
+
throw new Error(LINKING_ERROR);
|
|
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(options = {}) {
|
|
21
|
+
var _options$excludedUris, _options$fileTypes, _options$maxSize;
|
|
22
|
+
const {
|
|
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 : [],
|
|
39
|
+
fileTypes: (_options$fileTypes = options.fileTypes) !== null && _options$fileTypes !== void 0 ? _options$fileTypes : ['*/*'],
|
|
40
|
+
maxSize: (_options$maxSize = options.maxSize) !== null && _options$maxSize !== void 0 ? _options$maxSize : 0
|
|
41
|
+
};
|
|
42
|
+
return DocumentPicker.openDocument(finalOptions);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// YENİ: MyUploader Component'i
|
|
46
|
+
const MyUploaderAndroid = ({
|
|
47
|
+
// DocumentPickerOptions
|
|
48
|
+
multipleFiles = false,
|
|
49
|
+
maxFiles = 0,
|
|
50
|
+
fileTypes = ['*/*'],
|
|
51
|
+
maxSize = 0,
|
|
52
|
+
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
|
+
}) => {
|
|
62
|
+
const handlePress = async () => {
|
|
63
|
+
try {
|
|
64
|
+
const options = {
|
|
65
|
+
multipleFiles,
|
|
66
|
+
maxFiles,
|
|
67
|
+
fileTypes,
|
|
68
|
+
maxSize,
|
|
69
|
+
excludedUris
|
|
70
|
+
};
|
|
71
|
+
const selectedFiles = await pickFile(options);
|
|
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
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
// Kullanıcının seçimi iptal etmesi bir "hata" sayılmamalı,
|
|
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') {
|
|
83
|
+
onError(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
|
|
88
|
+
style: [styles.button, ButtonStyle, disabled && styles.disabledButton],
|
|
89
|
+
onPress: handlePress,
|
|
90
|
+
disabled: disabled
|
|
91
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
|
|
92
|
+
style: [styles.buttonText, ButtonTextStyle]
|
|
93
|
+
}, buttonPlaceHolder));
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// Varsayılan stiller
|
|
97
|
+
const styles = _reactNative.StyleSheet.create({
|
|
98
|
+
button: {
|
|
99
|
+
backgroundColor: '#007AFF',
|
|
100
|
+
paddingHorizontal: 20,
|
|
101
|
+
paddingVertical: 10,
|
|
102
|
+
borderRadius: 8,
|
|
103
|
+
alignItems: 'center',
|
|
104
|
+
justifyContent: 'center'
|
|
105
|
+
},
|
|
106
|
+
buttonText: {
|
|
107
|
+
color: '#FFFFFF',
|
|
108
|
+
fontSize: 16,
|
|
109
|
+
fontWeight: 'bold'
|
|
110
|
+
},
|
|
111
|
+
disabledButton: {
|
|
112
|
+
backgroundColor: '#A9A9A9'
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// İhtiyaca göre pickFile'ı da export edebilirsiniz.
|
|
117
|
+
// Component'i varsayılan olarak export ediyoruz.
|
|
118
|
+
var _default = exports.default = MyUploaderAndroid;
|
|
119
|
+
//# sourceMappingURL=MyUploader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","e","__esModule","default","LINKING_ERROR","DocumentPicker","NativeModules","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","TouchableOpacity","style","styles","button","disabledButton","onPress","Text","buttonText","StyleSheet","create","backgroundColor","paddingHorizontal","paddingVertical","borderRadius","alignItems","justifyContent","color","fontSize","fontWeight","_default","exports"],"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,IAAAA,M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IAAI;IAACL,KAAK,EAAE,CAACC,MAAM,CAACK,UAAU,EAAElB,eAAe;EAAE,GAC/CF,iBACG,CACU,CAAC;AAEvB,CAAC;;AAED;AACA,MAAMe,MAAM,GAAGM,uBAAU,CAACC,MAAM,CAAC;EAC/BN,MAAM,EAAE;IACNO,eAAe,EAAE,SAAS;IAC1BC,iBAAiB,EAAE,EAAE;IACrBC,eAAe,EAAE,EAAE;IACnBC,YAAY,EAAE,CAAC;IACfC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE;EAClB,CAAC;EACDR,UAAU,EAAE;IACVS,KAAK,EAAE,SAAS;IAChBC,QAAQ,EAAE,EAAE;IACZC,UAAU,EAAE;EACd,CAAC;EACDd,cAAc,EAAE;IACdM,eAAe,EAAE;EACnB;AACF,CAAC,CAAC;;AAEF;AAIA;AAAA,IAAAS,QAAA,GAAAC,OAAA,CAAAvD,OAAA,GACeqB,iBAAiB","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 { DocumentPickerOptions, MyUploaderProps,FileInfo } from './types';\r\n\r\nexport * from './types';\r\n\r\ndeclare const MyUploader: React.FC<MyUploaderProps>;\r\
|
|
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 { 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,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":[]}
|