Skip to content

Commit 08ccf28

Browse files
authored
Merge pull request joltup#222 from j-piasecki/patch-1
Add legacy constants to the module spec
2 parents 90196f2 + 5a66451 commit 08ccf28

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,11 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
355355
} else {
356356
res.put("SDCardApplicationDir", "");
357357
}
358+
} else {
359+
res.put("SDCardDir", "");
360+
res.put("SDCardApplicationDir", "");
358361
}
362+
359363
res.put("MainBundleDir", ctx.getApplicationInfo().dataDir);
360364

361365
// TODO Change me with the correct path
@@ -376,7 +380,20 @@ static Map<String, Object> getSystemfolders(ReactApplicationContext ctx) {
376380
static Map<String, Object> getLegacySystemfolders(ReactApplicationContext ctx) {
377381
Map<String, Object> res = new HashMap<>();
378382

379-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) return ReactNativeBlobUtilFS.getSystemfolders(ctx);
383+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
384+
res = ReactNativeBlobUtilFS.getSystemfolders(ctx);
385+
386+
// Include legacy folders anyway, since on the new arch compatibility between the spec and the turbomodule is enforced
387+
res.put("LegacyDCIMDir", "");
388+
res.put("LegacyPictureDir", "");
389+
res.put("LegacyMusicDir", "");
390+
res.put("LegacyDownloadDir", "");
391+
res.put("LegacyMovieDir", "");
392+
res.put("LegacyRingtoneDir", "");
393+
res.put("LegacySDCardDir", "");
394+
395+
return res;
396+
}
380397

381398
res.put("LegacyDCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
382399
res.put("LegacyPictureDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
@@ -388,6 +405,8 @@ static Map<String, Object> getLegacySystemfolders(ReactApplicationContext ctx) {
388405
String state = Environment.getExternalStorageState();
389406
if (state.equals(Environment.MEDIA_MOUNTED)) {
390407
res.put("LegacySDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
408+
} else {
409+
res.put("LegacySDCardDir", "");
391410
}
392411

393412
return res;

codegenSpecs/NativeBlobUtils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export interface Spec extends TurboModule {
1818
SDCardDir: string,
1919
SDCardApplicationDir: string,
2020
DCIMDir: string,
21+
// Android Only Legacy Constants
22+
LegacyDCIMDir: string,
23+
LegacyPictureDir: string,
24+
LegacyMusicDir: string,
25+
LegacyDownloadDir: string,
26+
LegacyMovieDir: string,
27+
LegacyRingtoneDir: string,
28+
LegacySDCardDir: string,
2129
|};
2230

2331
+fetchBlobForm: (options: Object, taskId: string, method: string, url: string, headers: Object, form: Array<any>, callback: (value: Array<any>) => void) => void;

ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ - (NSDictionary *)constantsToExport
9595
@"SDCardDir": @"",
9696
@"SDCardApplicationDir": @"",
9797
@"DCIMDir": @"",
98+
// Android only legacy constants
99+
@"LegacyDCIMDir": @"",
100+
@"LegacyPictureDir": @"",
101+
@"LegacyMusicDir": @"",
102+
@"LegacyDownloadDir": @"",
103+
@"LegacyMovieDir": @"",
104+
@"LegacyRingtoneDir": @"",
105+
@"LegacySDCardDir": @"",
98106
};
99107
}
100108

0 commit comments

Comments
 (0)