react-native-my-uploader-android 1.0.21 → 1.0.22
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/LICENSE +20 -20
- package/MyUploader.podspec +21 -21
- package/README.md +205 -205
- package/android/build.gradle +39 -39
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/main/java/com/myuploader/MyUploaderModule.kt +172 -172
- package/android/src/main/java/com/myuploader/MyUploaderPackage.kt +15 -15
- package/ios/MyUploader.h +8 -8
- package/ios/MyUploader.mm +10 -10
- package/ios/myUploader.swift +97 -97
- package/lib/commonjs/NativeMyUploader.js +0 -2
- package/lib/commonjs/NativeMyUploader.js.map +1 -1
- package/lib/commonjs/index.d.js.map +1 -1
- package/lib/commonjs/index.js +80 -16
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js +4 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/NativeMyUploader.js +0 -3
- package/lib/module/NativeMyUploader.js.map +1 -1
- package/lib/module/index.d.js.map +1 -1
- package/lib/module/index.js +81 -19
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +1 -1
- package/lib/module/types.js.map +1 -1
- package/package.json +161 -161
- package/src/NativeMyUploader.ts +24 -26
- package/src/index.d.ts +7 -59
- package/src/index.tsx +127 -58
- package/src/types.ts +25 -47
package/lib/commonjs/index.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
exports.pickFile = pickFile;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
9
|
var _reactNative = require("react-native");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Native modülün düzgün bir şekilde bağlanıp bağlanmadığını kontrol eden güvenlik mekanizması
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
const LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;
|
|
12
12
|
const DocumentPicker = _reactNative.NativeModules.DocumentPicker ? _reactNative.NativeModules.DocumentPicker : new Proxy({}, {
|
|
13
13
|
get() {
|
|
@@ -15,14 +15,10 @@ const DocumentPicker = _reactNative.NativeModules.DocumentPicker ? _reactNative.
|
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param options Dosya seçici için yapılandırma ayarları.
|
|
21
|
-
* @returns Seçilen dosya bilgilerini içeren bir Promise<FileInfo[]> döner.
|
|
22
|
-
*/
|
|
18
|
+
// Mevcut pickFile fonksiyonunu dahili (internal) olarak kullanmak üzere saklayalım.
|
|
19
|
+
// İsterseniz bunu dışa aktarmaya devam edebilirsiniz.
|
|
23
20
|
async function pickFile(options = {}) {
|
|
24
21
|
var _options$excludedUris, _options$fileTypes, _options$maxSize;
|
|
25
|
-
// Gelen opsiyonları varsayılan değerlerle birleştir
|
|
26
22
|
const {
|
|
27
23
|
multipleFiles = false,
|
|
28
24
|
maxFiles = 0,
|
|
@@ -31,25 +27,93 @@ async function pickFile(options = {}) {
|
|
|
31
27
|
if (!multipleFiles && maxFiles > 1) {
|
|
32
28
|
throw new Error('`maxFiles` cannot be greater than 1 when `multipleFiles` is false.');
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
// KURAL: `multipleFiles: true` iken `maxFiles` belirtilmemişse, varsayılan olarak 3 ata.
|
|
36
30
|
let effectiveMaxFiles = maxFiles;
|
|
37
31
|
if (multipleFiles && maxFiles === 0) {
|
|
38
32
|
effectiveMaxFiles = 3;
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
// Native koda gönderilecek nihai, temizlenmiş ve varsayılanları atanmış opsiyonları oluştur.
|
|
42
34
|
const finalOptions = {
|
|
43
35
|
...rest,
|
|
44
36
|
multipleFiles,
|
|
45
37
|
maxFiles: effectiveMaxFiles,
|
|
46
|
-
// Diğer opsiyonlar için de null/undefined kontrolü yap
|
|
47
38
|
excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : [],
|
|
48
39
|
fileTypes: (_options$fileTypes = options.fileTypes) !== null && _options$fileTypes !== void 0 ? _options$fileTypes : ['*/*'],
|
|
49
40
|
maxSize: (_options$maxSize = options.maxSize) !== null && _options$maxSize !== void 0 ? _options$maxSize : 0
|
|
50
41
|
};
|
|
51
|
-
|
|
52
|
-
// Nihai opsiyonlarla native modülü çağır
|
|
53
42
|
return DocumentPicker.openDocument(finalOptions);
|
|
54
43
|
}
|
|
44
|
+
|
|
45
|
+
// YENİ: MyUploader Component'i
|
|
46
|
+
const MyUploader = ({
|
|
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 = MyUploader;
|
|
55
119
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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","MyUploader","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":["index.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 MyUploader: 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 };\r\n\r\n// Component'i varsayılan olarak export ediyoruz.\r\nexport default MyUploader;"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAA4E,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAG5E,MAAMG,aAAa,GAAG,mEAAmE;AAEzF,MAAMC,cAAc,GAAGC,0BAAa,CAACD,cAAc,GAC/CC,0BAAa,CAACD,cAAc,GAC5B,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACL,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA,eAAeM,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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KAAK,oBAAoB,EAAE;QACvCN,OAAO,CAACC,KAAK,CAAC;MAChB;IACF;EACF,CAAC;EAED,oBACElC,MAAA,CAAAM,OAAA,CAAAkC,aAAA,CAACrC,YAAA,CAAAsC,gBAAgB;IACfC,KAAK,EAAE,CAACC,MAAM,CAACC,MAAM,EAAEf,WAAW,EAAEE,QAAQ,IAAIY,MAAM,CAACE,cAAc,CAAE;IACvEC,OAAO,EAAEV,WAAY;IACrBL,QAAQ,EAAEA;EAAS,gBAEnB/B,MAAA,CAAAM,OAAA,CAAAkC,aAAA,CAACrC,YAAA,CAAA4C,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,UAAU","ignoreList":[]}
|
package/lib/commonjs/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["
|
|
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}"],"mappings":"","ignoreList":[]}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native';
|
|
2
|
-
|
|
3
|
-
// Native modülün tip tanımı
|
|
4
|
-
|
|
5
2
|
const LINKING_ERROR = `The package 'react--native-my-uploader' doesn't seem to be linked. Make sure: \n\n` + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
6
3
|
const DocumentPicker = NativeModules.DocumentPicker ? NativeModules.DocumentPicker : new Proxy({}, {
|
|
7
4
|
get() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","LINKING_ERROR","DocumentPicker","Proxy","get","Error"],"sources":["NativeMyUploader.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\nimport type { FileInfo, DocumentPickerOptions } from './types';\
|
|
1
|
+
{"version":3,"names":["NativeModules","LINKING_ERROR","DocumentPicker","Proxy","get","Error"],"sources":["NativeMyUploader.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\r\nimport type { FileInfo, DocumentPickerOptions } from './types';\r\n\r\ninterface MyUploaderType {\r\n openDocument(options: DocumentPickerOptions): Promise<FileInfo[]>;\r\n}\r\n\r\nconst LINKING_ERROR =\r\n `The package 'react--native-my-uploader' doesn't seem to be linked. Make sure: \\n\\n` +\r\n '- You rebuilt the app after installing the package\\n' +\r\n '- You are not using Expo Go\\n';\r\n \r\n\r\nconst DocumentPicker = NativeModules.DocumentPicker\r\n ? (NativeModules.DocumentPicker as MyUploaderType)\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\nexport default DocumentPicker;"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAO5C,MAAMC,aAAa,GACjB,oFAAoF,GACpF,sDAAsD,GACtD,+BAA+B;AAGjC,MAAMC,cAAc,GAAGF,aAAa,CAACE,cAAc,GAC9CF,aAAa,CAACE,cAAc,GAC7B,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACJ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,eAAeC,cAAc","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.d.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":[],"sources":["index.d.ts"],"sourcesContent":["import * as React from 'react';\r\nimport type {FileInfo,DocumentPickerOptions, MyUploaderProps} from './types';\r\n\r\ndeclare const MyUploader: React.FC<MyUploaderProps>;\r\nexport default MyUploader;\r\n\r\n// Fonksiyonu hala export etmek isterseniz\r\nexport function pickFile(options?: DocumentPickerOptions): Promise<FileInfo[]>;"],"mappings":"","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
// Gerekli tipleri ve arayüzleri import et
|
|
4
|
-
|
|
5
|
-
// Native modülün düzgün bir şekilde bağlanıp bağlanmadığını kontrol eden güvenlik mekanizması
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NativeModules, TouchableOpacity, Text, StyleSheet } from 'react-native';
|
|
6
3
|
const LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;
|
|
7
4
|
const DocumentPicker = NativeModules.DocumentPicker ? NativeModules.DocumentPicker : new Proxy({}, {
|
|
8
5
|
get() {
|
|
@@ -10,14 +7,10 @@ const DocumentPicker = NativeModules.DocumentPicker ? NativeModules.DocumentPick
|
|
|
10
7
|
}
|
|
11
8
|
});
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* @returns Seçilen dosya bilgilerini içeren bir Promise<FileInfo[]> döner.
|
|
17
|
-
*/
|
|
18
|
-
export async function pickFile(options = {}) {
|
|
10
|
+
// Mevcut pickFile fonksiyonunu dahili (internal) olarak kullanmak üzere saklayalım.
|
|
11
|
+
// İsterseniz bunu dışa aktarmaya devam edebilirsiniz.
|
|
12
|
+
async function pickFile(options = {}) {
|
|
19
13
|
var _options$excludedUris, _options$fileTypes, _options$maxSize;
|
|
20
|
-
// Gelen opsiyonları varsayılan değerlerle birleştir
|
|
21
14
|
const {
|
|
22
15
|
multipleFiles = false,
|
|
23
16
|
maxFiles = 0,
|
|
@@ -26,25 +19,94 @@ export async function pickFile(options = {}) {
|
|
|
26
19
|
if (!multipleFiles && maxFiles > 1) {
|
|
27
20
|
throw new Error('`maxFiles` cannot be greater than 1 when `multipleFiles` is false.');
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
// KURAL: `multipleFiles: true` iken `maxFiles` belirtilmemişse, varsayılan olarak 3 ata.
|
|
31
22
|
let effectiveMaxFiles = maxFiles;
|
|
32
23
|
if (multipleFiles && maxFiles === 0) {
|
|
33
24
|
effectiveMaxFiles = 3;
|
|
34
25
|
}
|
|
35
|
-
|
|
36
|
-
// Native koda gönderilecek nihai, temizlenmiş ve varsayılanları atanmış opsiyonları oluştur.
|
|
37
26
|
const finalOptions = {
|
|
38
27
|
...rest,
|
|
39
28
|
multipleFiles,
|
|
40
29
|
maxFiles: effectiveMaxFiles,
|
|
41
|
-
// Diğer opsiyonlar için de null/undefined kontrolü yap
|
|
42
30
|
excludedUris: (_options$excludedUris = options.excludedUris) !== null && _options$excludedUris !== void 0 ? _options$excludedUris : [],
|
|
43
31
|
fileTypes: (_options$fileTypes = options.fileTypes) !== null && _options$fileTypes !== void 0 ? _options$fileTypes : ['*/*'],
|
|
44
32
|
maxSize: (_options$maxSize = options.maxSize) !== null && _options$maxSize !== void 0 ? _options$maxSize : 0
|
|
45
33
|
};
|
|
46
|
-
|
|
47
|
-
// Nihai opsiyonlarla native modülü çağır
|
|
48
34
|
return DocumentPicker.openDocument(finalOptions);
|
|
49
35
|
}
|
|
36
|
+
|
|
37
|
+
// YENİ: MyUploader Component'i
|
|
38
|
+
const MyUploader = ({
|
|
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...',
|
|
47
|
+
ButtonStyle,
|
|
48
|
+
ButtonTextStyle,
|
|
49
|
+
disabled = false,
|
|
50
|
+
// Callbacks
|
|
51
|
+
onSelect,
|
|
52
|
+
onError = error => console.error('MyUploader Error:', error)
|
|
53
|
+
}) => {
|
|
54
|
+
const handlePress = async () => {
|
|
55
|
+
try {
|
|
56
|
+
const options = {
|
|
57
|
+
multipleFiles,
|
|
58
|
+
maxFiles,
|
|
59
|
+
fileTypes,
|
|
60
|
+
maxSize,
|
|
61
|
+
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
|
+
}
|
|
70
|
+
} 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') {
|
|
75
|
+
onError(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return /*#__PURE__*/React.createElement(TouchableOpacity, {
|
|
80
|
+
style: [styles.button, ButtonStyle, disabled && styles.disabledButton],
|
|
81
|
+
onPress: handlePress,
|
|
82
|
+
disabled: disabled
|
|
83
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
84
|
+
style: [styles.buttonText, ButtonTextStyle]
|
|
85
|
+
}, buttonPlaceHolder));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Varsayılan stiller
|
|
89
|
+
const styles = StyleSheet.create({
|
|
90
|
+
button: {
|
|
91
|
+
backgroundColor: '#007AFF',
|
|
92
|
+
paddingHorizontal: 20,
|
|
93
|
+
paddingVertical: 10,
|
|
94
|
+
borderRadius: 8,
|
|
95
|
+
alignItems: 'center',
|
|
96
|
+
justifyContent: 'center'
|
|
97
|
+
},
|
|
98
|
+
buttonText: {
|
|
99
|
+
color: '#FFFFFF',
|
|
100
|
+
fontSize: 16,
|
|
101
|
+
fontWeight: 'bold'
|
|
102
|
+
},
|
|
103
|
+
disabledButton: {
|
|
104
|
+
backgroundColor: '#A9A9A9'
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// İhtiyaca göre pickFile'ı da export edebilirsiniz.
|
|
109
|
+
export { pickFile };
|
|
110
|
+
// Component'i varsayılan olarak export ediyoruz.
|
|
111
|
+
export default MyUploader;
|
|
50
112
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","LINKING_ERROR","DocumentPicker","Proxy","get","Error","pickFile","options","_options$excludedUris","_options$fileTypes","_options$maxSize","multipleFiles","maxFiles","rest","effectiveMaxFiles","finalOptions","excludedUris","fileTypes","maxSize","openDocument"],"sources":["index.tsx"],"sourcesContent":["import {
|
|
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","MyUploader","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":["index.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 MyUploader: 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 };\r\n\r\n// Component'i varsayılan olarak export ediyoruz.\r\nexport default MyUploader;"],"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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AAgB;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,UAAU","ignoreList":[]}
|
package/lib/module/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["
|
|
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}"],"mappings":"","ignoreList":[]}
|