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.
@@ -0,0 +1,106 @@
1
+ import React, { useState } from 'react';
2
+ import { NativeModules, TouchableOpacity, Text, StyleSheet, ActivityIndicator } from 'react-native';
3
+ import type { DownloadFileProps, DownloadResult } from '../types';
4
+
5
+ const { DownloadFile: DownloadFileModule } = NativeModules;
6
+
7
+ const DownloadFile: React.FC<DownloadFileProps> = ({
8
+ files,
9
+ multipleLoad = false,
10
+ disabled = false,
11
+ debug = false,
12
+ maxSize = 0,
13
+ fileTypes = ['*/*'],
14
+ buttonPlaceHolder = 'Dosyaları İndir',
15
+ buttonIcon,
16
+ ButtonStyle,
17
+ ButtonTextStyle,
18
+ onSuccess = () => {},
19
+ onError = (error) => console.error('DownloadFile Error:', error),
20
+ }) => {
21
+ const [isLoading, setIsLoading] = useState(false);
22
+
23
+ const handlePress = async () => {
24
+ if (!DownloadFileModule) {
25
+ onError(new Error("DownloadFile native module is not available."));
26
+ return;
27
+ }
28
+
29
+ setIsLoading(true);
30
+ const downloadOptions = { maxSize, fileTypes, debug };
31
+
32
+ try {
33
+ const filesToProcess = multipleLoad ? files : files.slice(0, 1);
34
+ const downloadPromises = filesToProcess.map(url =>
35
+ DownloadFileModule.downloadFile(url, downloadOptions)
36
+ );
37
+
38
+ const settledResults = await Promise.allSettled(downloadPromises);
39
+
40
+ const finalResult: DownloadResult = { successful: [], skipped: [] };
41
+
42
+ settledResults.forEach((result, index) => {
43
+ // DÜZELTME: `filesToProcess[index]` ifadesinin sonuna `!` ekleyerek
44
+ // TypeScript'e bu değerin asla undefined olmayacağını bildiriyoruz.
45
+ const originalUrl = filesToProcess[index]!;
46
+
47
+ if (result.status === 'fulfilled') {
48
+ finalResult.successful.push({
49
+ originalUrl, // Artık hata vermeyecek
50
+ localUri: result.value,
51
+ });
52
+ } else {
53
+ finalResult.skipped.push({
54
+ originalUrl, // Artık hata vermeyecek
55
+ reason: result.reason.message,
56
+ });
57
+ }
58
+ });
59
+
60
+ onSuccess(finalResult);
61
+
62
+ } catch (error: any) {
63
+ onError(error);
64
+ } finally {
65
+ setIsLoading(false);
66
+ }
67
+ };
68
+
69
+ const content = isLoading ? (
70
+ <ActivityIndicator color="#FFFFFF" />
71
+ ) : (
72
+ buttonIcon || <Text style={[styles.buttonText, ButtonTextStyle]}>{buttonPlaceHolder}</Text>
73
+ );
74
+
75
+ return (
76
+ <TouchableOpacity
77
+ style={[styles.button, ButtonStyle, (disabled || isLoading) && styles.disabledButton]}
78
+ onPress={handlePress}
79
+ disabled={disabled || isLoading}
80
+ >
81
+ {content}
82
+ </TouchableOpacity>
83
+ );
84
+ };
85
+
86
+ const styles = StyleSheet.create({
87
+ button: {
88
+ backgroundColor: '#008CBA',
89
+ paddingHorizontal: 20,
90
+ paddingVertical: 10,
91
+ borderRadius: 8,
92
+ alignItems: 'center',
93
+ justifyContent: 'center',
94
+ flexDirection: 'row',
95
+ },
96
+ buttonText: {
97
+ color: '#FFFFFF',
98
+ fontSize: 16,
99
+ fontWeight: 'bold',
100
+ },
101
+ disabledButton: {
102
+ backgroundColor: '#A9A9A9',
103
+ },
104
+ });
105
+
106
+ export default DownloadFile;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import {NativeModules,TouchableOpacity,Text,StyleSheet} from 'react-native';
3
- import type {FileInfo,DocumentPickerOptions, MyUploaderProps} from './types';
3
+ import type {FileInfo,DocumentPickerOptions, MyUploaderProps} from '../types';
4
4
 
5
5
  const LINKING_ERROR = `The package 'react-native-my-uploader' doesn't seem to be linked.`;
6
6
 
@@ -121,7 +121,7 @@ const styles = StyleSheet.create({
121
121
 
122
122
  // İhtiyaca göre pickFile'ı da export edebilirsiniz.
123
123
  export { pickFile };
124
- export type { FileInfo, DocumentPickerOptions, MyUploaderProps } from './types';
124
+ export type { FileInfo, DocumentPickerOptions, MyUploaderProps } from "../types";
125
125
 
126
126
  // Component'i varsayılan olarak export ediyoruz.
127
127
  export default MyUploaderAndroid;
package/src/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as React from 'react';
2
- import type { DocumentPickerOptions, MyUploaderProps,FileInfo } from './types';
2
+ import type { DocumentPickerOptions, MyUploaderProps,FileInfo,DownloadFileProps } from './types';
3
3
 
4
4
  export * from './types';
5
5
 
6
6
  declare const MyUploader: React.FC<MyUploaderProps>;
7
-
8
7
  export default MyUploader;
9
8
 
9
+ export declare const DownloadFile: React.FC<DownloadFileProps>;
10
10
  export function pickFile(options?: DocumentPickerOptions): Promise<FileInfo[]>;
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ import MyUploaderAndroid from "./components/MyUploader";
2
+ import DownloadFileAndroid from "./components/DownloadFile";
3
+ import { pickFile } from './components/MyUploader';
4
+
5
+ // Component'leri ve fonksiyonları dışa aktar
6
+ export { DownloadFileAndroid, pickFile };
7
+ export * from './types';
8
+ export default MyUploaderAndroid;
9
+
10
+
package/src/types.ts CHANGED
@@ -23,4 +23,42 @@ export interface MyUploaderProps extends DocumentPickerOptions {
23
23
  ButtonStyle?: StyleProp<ViewStyle>;
24
24
  ButtonTextStyle?: StyleProp<TextStyle>;
25
25
  disabled?: boolean;
26
+ }
27
+
28
+ //download File Module Props
29
+ export interface DownloadedFileInfo {
30
+ originalUrl: string;
31
+ localUri: string; // Cihazdaki dosyanın URI'si
32
+ }
33
+
34
+ // YENİ: Atlanan dosyalar hakkında bilgi vermek için arayüz
35
+ export interface SkippedFileInfo {
36
+ originalUrl: string;
37
+ reason: string; // Neden atlandığı (örn: "Dosya çok büyük")
38
+ }
39
+
40
+ // YENİ: onSUCCESS callback'inin döndüreceği sonuç nesnesi
41
+ export interface DownloadResult {
42
+ successful: DownloadedFileInfo[];
43
+ skipped: SkippedFileInfo[];
44
+ }
45
+
46
+ // GÜNCELLENDİ: DownloadFileProps arayüzü
47
+ export interface DownloadFileProps {
48
+ files: string[];
49
+ // YENİ PROPLAR
50
+ multipleLoad?: boolean;
51
+ disabled?: boolean;
52
+ debug?: boolean; // Mevcut debug prop'u
53
+
54
+ maxSize?: number;
55
+ fileTypes?: string[];
56
+ buttonPlaceHolder?: string;
57
+ buttonIcon?: React.ReactNode;
58
+ ButtonStyle?: StyleProp<ViewStyle>;
59
+ ButtonTextStyle?: StyleProp<TextStyle>;
60
+
61
+ // GÜNCELLENDİ: Callback daha zengin bir nesne döndürecek
62
+ onSuccess?: (result: DownloadResult) => void;
63
+ onError?: (error: Error) => void;
26
64
  }