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/package.json
CHANGED
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-native-my-uploader-android",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "file uploader",
|
|
5
|
-
"main": "./lib/module/index.js",
|
|
6
|
-
"types": "./src/index.d.ts",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"source": "./src/index.tsx",
|
|
10
|
-
"types": "./src/index.d.ts",
|
|
11
|
-
"default": "./lib/module/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"files": [
|
|
15
|
-
"src",
|
|
16
|
-
"lib",
|
|
17
|
-
"android",
|
|
18
|
-
"ios",
|
|
19
|
-
"cpp",
|
|
20
|
-
"*.podspec",
|
|
21
|
-
"react-native.config.js",
|
|
22
|
-
"!ios/build",
|
|
23
|
-
"!android/build",
|
|
24
|
-
"!android/gradle",
|
|
25
|
-
"!android/gradlew",
|
|
26
|
-
"!android/gradlew.bat",
|
|
27
|
-
"!android/local.properties",
|
|
28
|
-
"!**/__tests__",
|
|
29
|
-
"!**/__fixtures__",
|
|
30
|
-
"!**/__mocks__",
|
|
31
|
-
"!**/.*"
|
|
32
|
-
],
|
|
33
|
-
"scripts": {
|
|
34
|
-
"example": "yarn workspace react-native-my-uploader-example",
|
|
35
|
-
"test": "jest",
|
|
36
|
-
"typecheck": "tsc",
|
|
37
|
-
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
38
|
-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
39
|
-
"prepare": "bob build",
|
|
40
|
-
"release": "release-it --only-version"
|
|
41
|
-
},
|
|
42
|
-
"keywords": [
|
|
43
|
-
"react-native",
|
|
44
|
-
"ios",
|
|
45
|
-
"android"
|
|
46
|
-
],
|
|
47
|
-
"repository": {
|
|
48
|
-
"type": "git",
|
|
49
|
-
"url": "git+https://www.npmjs.com/~yrncskn.git"
|
|
50
|
-
},
|
|
51
|
-
"author": "Yaren Coskun <yarencoskunceng@gmail.com> (https://www.npmjs.com/~yrncskn)",
|
|
52
|
-
"license": "MIT",
|
|
53
|
-
"bugs": {
|
|
54
|
-
"url": "https://www.npmjs.com/~yrncskn/issues"
|
|
55
|
-
},
|
|
56
|
-
"homepage": "https://www.npmjs.com/~yrncskn#readme",
|
|
57
|
-
"publishConfig": {
|
|
58
|
-
"registry": "https://registry.npmjs.org/"
|
|
59
|
-
},
|
|
60
|
-
"devDependencies": {
|
|
61
|
-
"@commitlint/config-conventional": "^19.8.1",
|
|
62
|
-
"@eslint/compat": "^1.3.2",
|
|
63
|
-
"@eslint/eslintrc": "^3.3.1",
|
|
64
|
-
"@eslint/js": "^9.35.0",
|
|
65
|
-
"@evilmartians/lefthook": "^1.12.3",
|
|
66
|
-
"@react-native-community/bob": "^0.17.1",
|
|
67
|
-
"@react-native-community/cli": "20.0.1",
|
|
68
|
-
"@react-native/babel-preset": "0.81.1",
|
|
69
|
-
"@react-native/eslint-config": "^0.81.1",
|
|
70
|
-
"@release-it/conventional-changelog": "^10.0.1",
|
|
71
|
-
"@types/jest": "^29.5.14",
|
|
72
|
-
"@types/react": "^19.1.0",
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
|
74
|
-
"@typescript-eslint/parser": "^8.46.4",
|
|
75
|
-
"commitlint": "^19.8.1",
|
|
76
|
-
"del-cli": "^6.0.0",
|
|
77
|
-
"eslint": "^9.35.0",
|
|
78
|
-
"eslint-config-prettier": "^10.1.8",
|
|
79
|
-
"eslint-plugin-ft-flow": "^3.0.11",
|
|
80
|
-
"eslint-plugin-jest": "^29.0.1",
|
|
81
|
-
"eslint-plugin-prettier": "^5.5.4",
|
|
82
|
-
"eslint-plugin-react-native": "^5.0.0",
|
|
83
|
-
"jest": "^29.7.0",
|
|
84
|
-
"prettier": "^3.6.2",
|
|
85
|
-
"react": "19.1.0",
|
|
86
|
-
"react-native": "0.81.1",
|
|
87
|
-
"react-native-builder-bob": "^0.40.14",
|
|
88
|
-
"release-it": "^19.0.4",
|
|
89
|
-
"turbo": "^2.5.6",
|
|
90
|
-
"typescript": "^5.9.2"
|
|
91
|
-
},
|
|
92
|
-
"peerDependencies": {
|
|
93
|
-
"react": "*",
|
|
94
|
-
"react-native": "*"
|
|
95
|
-
},
|
|
96
|
-
"workspaces": [
|
|
97
|
-
"example"
|
|
98
|
-
],
|
|
99
|
-
"packageManager": "yarn@3.6.1",
|
|
100
|
-
"jest": {
|
|
101
|
-
"preset": "react-native",
|
|
102
|
-
"modulePathIgnorePatterns": [
|
|
103
|
-
"<rootDir>/example/node_modules",
|
|
104
|
-
"<rootDir>/lib/"
|
|
105
|
-
]
|
|
106
|
-
},
|
|
107
|
-
"commitlint": {
|
|
108
|
-
"extends": [
|
|
109
|
-
"@commitlint/config-conventional"
|
|
110
|
-
]
|
|
111
|
-
},
|
|
112
|
-
"release-it": {
|
|
113
|
-
"git": {
|
|
114
|
-
"commitMessage": "chore: release ${version}",
|
|
115
|
-
"tagName": "v${version}"
|
|
116
|
-
},
|
|
117
|
-
"npm": {
|
|
118
|
-
"publish": true
|
|
119
|
-
},
|
|
120
|
-
"github": {
|
|
121
|
-
"release": true
|
|
122
|
-
},
|
|
123
|
-
"plugins": {
|
|
124
|
-
"@release-it/conventional-changelog": {
|
|
125
|
-
"preset": {
|
|
126
|
-
"name": "angular"
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
"prettier": {
|
|
132
|
-
"quoteProps": "consistent",
|
|
133
|
-
"singleQuote": true,
|
|
134
|
-
"tabWidth": 2,
|
|
135
|
-
"trailingComma": "es5",
|
|
136
|
-
"useTabs": false
|
|
137
|
-
},
|
|
138
|
-
"react-native-builder-bob": {
|
|
139
|
-
"source": "src",
|
|
140
|
-
"output": "lib",
|
|
141
|
-
"targets": [
|
|
142
|
-
[
|
|
143
|
-
"module",
|
|
144
|
-
{
|
|
145
|
-
"esm": true
|
|
146
|
-
}
|
|
147
|
-
],
|
|
148
|
-
[
|
|
149
|
-
"typescript",
|
|
150
|
-
{
|
|
151
|
-
"project": "tsconfig.build.json"
|
|
152
|
-
}
|
|
153
|
-
]
|
|
154
|
-
]
|
|
155
|
-
},
|
|
156
|
-
"create-react-native-library": {
|
|
157
|
-
"languages": "kotlin-objc",
|
|
158
|
-
"type": "turbo-module",
|
|
159
|
-
"version": "0.54.8"
|
|
160
|
-
}
|
|
161
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-my-uploader-android",
|
|
3
|
+
"version": "1.0.22",
|
|
4
|
+
"description": "file uploader",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"lib",
|
|
17
|
+
"android",
|
|
18
|
+
"ios",
|
|
19
|
+
"cpp",
|
|
20
|
+
"*.podspec",
|
|
21
|
+
"react-native.config.js",
|
|
22
|
+
"!ios/build",
|
|
23
|
+
"!android/build",
|
|
24
|
+
"!android/gradle",
|
|
25
|
+
"!android/gradlew",
|
|
26
|
+
"!android/gradlew.bat",
|
|
27
|
+
"!android/local.properties",
|
|
28
|
+
"!**/__tests__",
|
|
29
|
+
"!**/__fixtures__",
|
|
30
|
+
"!**/__mocks__",
|
|
31
|
+
"!**/.*"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"example": "yarn workspace react-native-my-uploader-example",
|
|
35
|
+
"test": "jest",
|
|
36
|
+
"typecheck": "tsc",
|
|
37
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
38
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
39
|
+
"prepare": "bob build",
|
|
40
|
+
"release": "release-it --only-version"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"react-native",
|
|
44
|
+
"ios",
|
|
45
|
+
"android"
|
|
46
|
+
],
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://www.npmjs.com/~yrncskn.git"
|
|
50
|
+
},
|
|
51
|
+
"author": "Yaren Coskun <yarencoskunceng@gmail.com> (https://www.npmjs.com/~yrncskn)",
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://www.npmjs.com/~yrncskn/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://www.npmjs.com/~yrncskn#readme",
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"registry": "https://registry.npmjs.org/"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
62
|
+
"@eslint/compat": "^1.3.2",
|
|
63
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
64
|
+
"@eslint/js": "^9.35.0",
|
|
65
|
+
"@evilmartians/lefthook": "^1.12.3",
|
|
66
|
+
"@react-native-community/bob": "^0.17.1",
|
|
67
|
+
"@react-native-community/cli": "20.0.1",
|
|
68
|
+
"@react-native/babel-preset": "0.81.1",
|
|
69
|
+
"@react-native/eslint-config": "^0.81.1",
|
|
70
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
71
|
+
"@types/jest": "^29.5.14",
|
|
72
|
+
"@types/react": "^19.1.0",
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
|
74
|
+
"@typescript-eslint/parser": "^8.46.4",
|
|
75
|
+
"commitlint": "^19.8.1",
|
|
76
|
+
"del-cli": "^6.0.0",
|
|
77
|
+
"eslint": "^9.35.0",
|
|
78
|
+
"eslint-config-prettier": "^10.1.8",
|
|
79
|
+
"eslint-plugin-ft-flow": "^3.0.11",
|
|
80
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
81
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
82
|
+
"eslint-plugin-react-native": "^5.0.0",
|
|
83
|
+
"jest": "^29.7.0",
|
|
84
|
+
"prettier": "^3.6.2",
|
|
85
|
+
"react": "19.1.0",
|
|
86
|
+
"react-native": "0.81.1",
|
|
87
|
+
"react-native-builder-bob": "^0.40.14",
|
|
88
|
+
"release-it": "^19.0.4",
|
|
89
|
+
"turbo": "^2.5.6",
|
|
90
|
+
"typescript": "^5.9.2"
|
|
91
|
+
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"react": "*",
|
|
94
|
+
"react-native": "*"
|
|
95
|
+
},
|
|
96
|
+
"workspaces": [
|
|
97
|
+
"example"
|
|
98
|
+
],
|
|
99
|
+
"packageManager": "yarn@3.6.1",
|
|
100
|
+
"jest": {
|
|
101
|
+
"preset": "react-native",
|
|
102
|
+
"modulePathIgnorePatterns": [
|
|
103
|
+
"<rootDir>/example/node_modules",
|
|
104
|
+
"<rootDir>/lib/"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"commitlint": {
|
|
108
|
+
"extends": [
|
|
109
|
+
"@commitlint/config-conventional"
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
"release-it": {
|
|
113
|
+
"git": {
|
|
114
|
+
"commitMessage": "chore: release ${version}",
|
|
115
|
+
"tagName": "v${version}"
|
|
116
|
+
},
|
|
117
|
+
"npm": {
|
|
118
|
+
"publish": true
|
|
119
|
+
},
|
|
120
|
+
"github": {
|
|
121
|
+
"release": true
|
|
122
|
+
},
|
|
123
|
+
"plugins": {
|
|
124
|
+
"@release-it/conventional-changelog": {
|
|
125
|
+
"preset": {
|
|
126
|
+
"name": "angular"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"prettier": {
|
|
132
|
+
"quoteProps": "consistent",
|
|
133
|
+
"singleQuote": true,
|
|
134
|
+
"tabWidth": 2,
|
|
135
|
+
"trailingComma": "es5",
|
|
136
|
+
"useTabs": false
|
|
137
|
+
},
|
|
138
|
+
"react-native-builder-bob": {
|
|
139
|
+
"source": "src",
|
|
140
|
+
"output": "lib",
|
|
141
|
+
"targets": [
|
|
142
|
+
[
|
|
143
|
+
"module",
|
|
144
|
+
{
|
|
145
|
+
"esm": true
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
[
|
|
149
|
+
"typescript",
|
|
150
|
+
{
|
|
151
|
+
"project": "tsconfig.build.json"
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
"create-react-native-library": {
|
|
157
|
+
"languages": "kotlin-objc",
|
|
158
|
+
"type": "turbo-module",
|
|
159
|
+
"version": "0.54.8"
|
|
160
|
+
}
|
|
161
|
+
}
|
package/src/NativeMyUploader.ts
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
2
|
-
import type { FileInfo, DocumentPickerOptions } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
26
|
-
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
import type { FileInfo, DocumentPickerOptions } from './types';
|
|
3
|
+
|
|
4
|
+
interface MyUploaderType {
|
|
5
|
+
openDocument(options: DocumentPickerOptions): Promise<FileInfo[]>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const LINKING_ERROR =
|
|
9
|
+
`The package 'react--native-my-uploader' doesn't seem to be linked. Make sure: \n\n` +
|
|
10
|
+
'- You rebuilt the app after installing the package\n' +
|
|
11
|
+
'- You are not using Expo Go\n';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const DocumentPicker = NativeModules.DocumentPicker
|
|
15
|
+
? (NativeModules.DocumentPicker as MyUploaderType)
|
|
16
|
+
: new Proxy(
|
|
17
|
+
{},
|
|
18
|
+
{
|
|
19
|
+
get() {
|
|
20
|
+
throw new Error(LINKING_ERROR);
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
27
25
|
export default DocumentPicker;
|
package/src/index.d.ts
CHANGED
|
@@ -1,60 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Bu tip, paket kullanıcıları tarafından import edilebilir.
|
|
9
|
-
*/
|
|
10
|
-
export interface FileInfo {
|
|
11
|
-
fileName: string;
|
|
12
|
-
fileSize: number; // in bytes
|
|
13
|
-
fileType: string | null;
|
|
14
|
-
fileUri: string;
|
|
15
|
-
base64: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* `pickFile` fonksiyonuna gönderilebilecek tüm opsiyonları tanımlar.
|
|
20
|
-
* Bu tip, paket kullanıcıları tarafından import edilebilir.
|
|
21
|
-
*/
|
|
22
|
-
export interface DocumentPickerOptions {
|
|
23
|
-
/**
|
|
24
|
-
* Birden fazla dosya seçimine izin ver.
|
|
25
|
-
* @default false
|
|
26
|
-
*/
|
|
27
|
-
multipleFiles?: boolean;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Filtrelenecek dosya tipleri (MIME types).
|
|
31
|
-
* @default ['* / *']
|
|
32
|
-
*/
|
|
33
|
-
fileTypes?: string[];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* MB cinsinden maksimum dosya boyutu.
|
|
37
|
-
* @default 0 (limitsiz)
|
|
38
|
-
*/
|
|
39
|
-
maxSize?: number;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Seçilebilecek maksimum dosya sayısı. `multipleFiles: true` olmalıdır.
|
|
43
|
-
* Belirtilmezse ve `multipleFiles: true` ise varsayılan olarak 3'tür.
|
|
44
|
-
*/
|
|
45
|
-
maxFiles?: number;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Zaten seçilmiş olduğu için tekrar seçilmesi engellenecek dosyaların URI listesi.
|
|
49
|
-
*/
|
|
50
|
-
excludedUris?: string[];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ADIM 2: Fonksiyonu da DIŞA AKTARARAK (export) tanımla.
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Dosya seçiciyi açar ve seçilen dosyaların bilgilerini döndürür.
|
|
57
|
-
* @param options Dosya seçici için yapılandırma ayarları.
|
|
58
|
-
* @returns Seçilen dosya bilgilerini içeren bir Promise<FileInfo[]> döner.
|
|
59
|
-
*/
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type {FileInfo,DocumentPickerOptions, MyUploaderProps} from './types';
|
|
3
|
+
|
|
4
|
+
declare const MyUploader: React.FC<MyUploaderProps>;
|
|
5
|
+
export default MyUploader;
|
|
6
|
+
|
|
7
|
+
// Fonksiyonu hala export etmek isterseniz
|
|
60
8
|
export function pickFile(options?: DocumentPickerOptions): Promise<FileInfo[]>;
|
package/src/index.tsx
CHANGED
|
@@ -1,58 +1,127 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
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
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {NativeModules,TouchableOpacity,Text,StyleSheet} from 'react-native';
|
|
3
|
+
import type {FileInfo,DocumentPickerOptions, MyUploaderProps} from './types';
|
|
4
|
+
|
|
5
|
+
const LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;
|
|
6
|
+
|
|
7
|
+
const DocumentPicker = NativeModules.DocumentPicker
|
|
8
|
+
? NativeModules.DocumentPicker
|
|
9
|
+
: new Proxy(
|
|
10
|
+
{},
|
|
11
|
+
{
|
|
12
|
+
get() {
|
|
13
|
+
throw new Error(LINKING_ERROR);
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// Mevcut pickFile fonksiyonunu dahili (internal) olarak kullanmak üzere saklayalım.
|
|
19
|
+
// İsterseniz bunu dışa aktarmaya devam edebilirsiniz.
|
|
20
|
+
async function pickFile(
|
|
21
|
+
options: DocumentPickerOptions = {}
|
|
22
|
+
): Promise<FileInfo[]> {
|
|
23
|
+
const { multipleFiles = false, maxFiles = 0, ...rest } = options;
|
|
24
|
+
|
|
25
|
+
if (!multipleFiles && maxFiles > 1) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
'`maxFiles` cannot be greater than 1 when `multipleFiles` is false.'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
let effectiveMaxFiles = maxFiles;
|
|
31
|
+
if (multipleFiles && maxFiles === 0) {
|
|
32
|
+
effectiveMaxFiles = 3;
|
|
33
|
+
}
|
|
34
|
+
const finalOptions: DocumentPickerOptions = {
|
|
35
|
+
...rest,
|
|
36
|
+
multipleFiles,
|
|
37
|
+
maxFiles: effectiveMaxFiles,
|
|
38
|
+
excludedUris: options.excludedUris ?? [],
|
|
39
|
+
fileTypes: options.fileTypes ?? ['*/*'],
|
|
40
|
+
maxSize: options.maxSize ?? 0,
|
|
41
|
+
};
|
|
42
|
+
return DocumentPicker.openDocument(finalOptions);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// YENİ: MyUploader Component'i
|
|
46
|
+
const MyUploader: React.FC<MyUploaderProps> = ({
|
|
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: DocumentPickerOptions = {
|
|
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
|
+
|
|
79
|
+
} catch (error: any) {
|
|
80
|
+
// Kullanıcının seçimi iptal etmesi bir "hata" sayılmamalı,
|
|
81
|
+
// bu yüzden sadece konsola yazdırıp onError'ı tetiklemeyebiliriz.
|
|
82
|
+
// Native kodunuz "E_PICKER_CANCELLED" koduyla reject ediyor.
|
|
83
|
+
if (error.code !== 'E_PICKER_CANCELLED') {
|
|
84
|
+
onError(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<TouchableOpacity
|
|
91
|
+
style={[styles.button, ButtonStyle, disabled && styles.disabledButton]}
|
|
92
|
+
onPress={handlePress}
|
|
93
|
+
disabled={disabled}
|
|
94
|
+
>
|
|
95
|
+
<Text style={[styles.buttonText, ButtonTextStyle]}>
|
|
96
|
+
{buttonPlaceHolder}
|
|
97
|
+
</Text>
|
|
98
|
+
</TouchableOpacity>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Varsayılan stiller
|
|
103
|
+
const styles = StyleSheet.create({
|
|
104
|
+
button: {
|
|
105
|
+
backgroundColor: '#007AFF',
|
|
106
|
+
paddingHorizontal: 20,
|
|
107
|
+
paddingVertical: 10,
|
|
108
|
+
borderRadius: 8,
|
|
109
|
+
alignItems: 'center',
|
|
110
|
+
justifyContent: 'center',
|
|
111
|
+
},
|
|
112
|
+
buttonText: {
|
|
113
|
+
color: '#FFFFFF',
|
|
114
|
+
fontSize: 16,
|
|
115
|
+
fontWeight: 'bold',
|
|
116
|
+
},
|
|
117
|
+
disabledButton: {
|
|
118
|
+
backgroundColor: '#A9A9A9',
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// İhtiyaca göre pickFile'ı da export edebilirsiniz.
|
|
123
|
+
export { pickFile };
|
|
124
|
+
export type { FileInfo, DocumentPickerOptions, MyUploaderProps };
|
|
125
|
+
|
|
126
|
+
// Component'i varsayılan olarak export ediyoruz.
|
|
127
|
+
export default MyUploader;
|