Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[file-system][android] add ability to read from bundle resources #8104

Merged
merged 2 commits into from May 4, 2020

Conversation

esamelson
Copy link
Contributor

Why

Once #8003 and #8006 land, some require bundled assets in bare workflow Android apps will be used directly from where they are embedded in the APK resources folder. (This is currently also the case for any bare workflow apps using expo-file-system without expo-updates.) These assets are inaccessible via the FileSystem API.

For such assets, the uri returned by RN's Image.resolveAssetSource is actually just the resource name with no scheme. Therefore, in the FS API, if we receive a uri without a scheme we can assume it might be a file in resources and try to access it accordingly. We first try searching the res/raw folder, and if the resource isn't found we try to find it in res/drawable.

How

Implemented the above plan for the three FileSystem methods that read data, getInfoAsync, readAsStringAsync, and copyAsync.

Test Plan

tested in an Android bare app with a required asset embedded in resources

  • FileSystem.getInfoAsync(Image.resolveAssetSource(require('./asset.png')).uri) resolves with expected info
  • FileSystem.readAsStringAsync(Image.resolveAssetSource(require('./asset.png')).uri) resolves with expected info
  • FileSystem.copyAsync({from: Image.resolveAssetSource(require('./asset.png')).uri, to: ${FileSystem.documentDirectory}test.png) resolves successfully
  • FileSystem.getInfoAsync('nonexistent-file') resolves with exists: false
  • FileSystem.readAsStringAsync(nonexistent-file) rejects with a readable error message
  • FileSystem.copyAsync({from: 'nonexistent-file, to: ${FileSystem.documentDirectory}test.png) rejects with a readable error message

@github-actions
Copy link
Contributor

Native Component List for this branch is ready



Copy link
Contributor

@sjchmiela sjchmiela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 💯 Would you care to add a CHANGELOG entry? 🙏

@esamelson
Copy link
Contributor Author

Absolutely, thank you for the reminder! 🙏

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2020

Native Component List for this branch is ready

@esamelson esamelson merged commit 41e701b into master May 4, 2020
@esamelson esamelson deleted the @eric/file-system-res branch May 4, 2020 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants