From a063f23ed9f0b4bf1ee4457112c1da2ee0d21e22 Mon Sep 17 00:00:00 2001 From: Martin Chase Date: Thu, 31 Mar 2016 10:20:52 -0700 Subject: [PATCH 1/2] connected ExternalDirectoryPath constant to getExternalFilesDir (null for iOS) --- FS.common.js | 1 + IntegrationTests/FSTest.js | 2 +- README.md | 1 + RNFSManager.m | 1 + android/src/main/java/com/rnfs/RNFSManager.java | 7 +++++++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/FS.common.js b/FS.common.js index 31f6d11..074cdf4 100644 --- a/FS.common.js +++ b/FS.common.js @@ -189,6 +189,7 @@ var RNFS = { MainBundlePath: RNFSManager.MainBundlePath, CachesDirectoryPath: RNFSManager.NSCachesDirectoryPath, DocumentDirectoryPath: RNFSManager.NSDocumentDirectoryPath, + ExternalDirectoryPath: RNFSManager.NSExternalDirectoryPath, LibraryDirectoryPath: RNFSManager.NSLibraryDirectoryPath, PicturesDirectoryPath: RNFSManager.NSPicturesDirectoryPath }; diff --git a/IntegrationTests/FSTest.js b/IntegrationTests/FSTest.js index dd91208..4586ec4 100644 --- a/IntegrationTests/FSTest.js +++ b/IntegrationTests/FSTest.js @@ -63,7 +63,7 @@ function testWriteAndReadFile() { function testCreateAndDeleteFile() { - var path = RNFS.DocumentDirectoryPath + '/test.txt'; + var path = RNFS.ExternalDirectoryPath + '/test.txt'; var text = 'Lorem ipsum dolor sit amet'; var readText; diff --git a/README.md b/README.md index a1811c2..0d10b41 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ The following constants are available on the `RNFS` export: `MainBundlePath` (`String`) The absolute path to the main bundle directory `CachesDirectoryPath` (`String`) The absolute path to the caches directory `DocumentDirectoryPath` (`String`) The absolute path to the document directory +`ExternalDirectoryPath` (`String`) The absolute path to the external, shared directory (android only) ### `promise readDir(path)` diff --git a/RNFSManager.m b/RNFSManager.m index ca0b59b..907f48a 100644 --- a/RNFSManager.m +++ b/RNFSManager.m @@ -278,6 +278,7 @@ RCT_EXPORT_METHOD(pathForBundle:(NSString *)bundleNamed @"MainBundlePath": [[NSBundle mainBundle] bundlePath], @"NSCachesDirectoryPath": [self getPathForDirectory:NSCachesDirectory], @"NSDocumentDirectoryPath": [self getPathForDirectory:NSDocumentDirectory], + @"NSExternalDirectoryPath": [NSNull null], @"NSLibraryDirectoryPath": [self getPathForDirectory:NSLibraryDirectory], @"NSFileTypeRegular": NSFileTypeRegular, @"NSFileTypeDirectory": NSFileTypeDirectory diff --git a/android/src/main/java/com/rnfs/RNFSManager.java b/android/src/main/java/com/rnfs/RNFSManager.java index 787f67f..0571b4e 100644 --- a/android/src/main/java/com/rnfs/RNFSManager.java +++ b/android/src/main/java/com/rnfs/RNFSManager.java @@ -38,6 +38,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule; public class RNFSManager extends ReactContextBaseJavaModule { private static final String NSDocumentDirectoryPath = "NSDocumentDirectoryPath"; + private static final String NSExternalDirectoryPath = "NSExternalDirectoryPath"; private static final String NSPicturesDirectoryPath = "NSPicturesDirectoryPath"; private static final String NSCachesDirectoryPath = "NSCachesDirectoryPath"; private static final String NSDocumentDirectory = "NSDocumentDirectory"; @@ -308,6 +309,12 @@ public class RNFSManager extends ReactContextBaseJavaModule { final Map constants = new HashMap<>(); constants.put(NSDocumentDirectory, 0); constants.put(NSDocumentDirectoryPath, this.getReactApplicationContext().getFilesDir().getAbsolutePath()); + File externalDirectory = this.getReactApplicationContext().getExternalFilesDir(null); + if (externalDirectory != null) { + constants.put(NSExternalDirectoryPath, externalDirectory.getAbsolutePath()); + } else { + constants.put(NSExternalDirectoryPath, null); + } constants.put(NSPicturesDirectoryPath, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()); constants.put(NSCachesDirectoryPath, this.getReactApplicationContext().getCacheDir().getAbsolutePath()); constants.put(NSFileTypeRegular, 0); From c3f8a1e1fab1b8e017610b8589312bb51a97ac6d Mon Sep 17 00:00:00 2001 From: Martin Chase Date: Mon, 11 Apr 2016 10:17:12 -0700 Subject: [PATCH 2/2] Update FSTest.js Cannot use external in tests; iOS lacks analogous directory. --- IntegrationTests/FSTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IntegrationTests/FSTest.js b/IntegrationTests/FSTest.js index 4586ec4..dd91208 100644 --- a/IntegrationTests/FSTest.js +++ b/IntegrationTests/FSTest.js @@ -63,7 +63,7 @@ function testWriteAndReadFile() { function testCreateAndDeleteFile() { - var path = RNFS.ExternalDirectoryPath + '/test.txt'; + var path = RNFS.DocumentDirectoryPath + '/test.txt'; var text = 'Lorem ipsum dolor sit amet'; var readText;