Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions FS.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ var RNFS = {
return RNFSManager.exists(normalizeFilePath(filepath));
},

// Android-only
existsRes(filename: string) {
if (!RNFSManager.existsRes) {
throw new Error('existsRes is not available on this platform');
}
return RNFSManager.existsRes(filename);
},

stopDownload(jobId: number): void {
RNFSManager.stopDownload(jobId);
},
Expand Down
21 changes: 21 additions & 0 deletions android/src/main/java/com/rnfs/RNFSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -976,4 +976,25 @@ public Map<String, Object> getConstants() {

return constants;
}


@ReactMethod
public void existsRes(String filename, Promise promise) {
try {
int res = getResIdentifier(filename);
if (res > 0) {
promise.resolve(true);
} else {
promise.resolve(false);
}
} catch (Exception ex) {
ex.printStackTrace();
reject(promise, filename, ex);
}
}

private int getResIdentifier(String filename) {
return getReactApplicationContext().getResources().getIdentifier(filename, "raw", getReactApplicationContext().getPackageName());
}

}