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

Load assets from same folder as JSbundle (Android) #4527

Closed
wants to merge 17 commits into
base: master
from
Next

Load assets from same folder as JSbundle (Android)

  • Loading branch information...
geof90 committed Dec 3, 2015
commit a28bef43bd20f46a222e8b5037ce054db28fe1b9
@@ -63,14 +63,23 @@ function getOfflinePath() {
*/
function getPathInArchive(asset) {
if (Platform.OS === 'android') {
var assetDir = getBasePath(asset);
// E.g. 'assets_awesomemodule_icon'
// The Android resource system picks the correct scale.
return (assetDir + '/' + asset.name)
.toLowerCase()
.replace(/\//g, '_') // Encode folder structure in file name
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
.replace(/^assets_/, ''); // Remove "assets_" prefix
var scriptURL = SourceCode.scriptURL;
var match = scriptURL && scriptURL.match(/^\/.*\//);
if (match) {
// scriptURL has no scheme,
// E.g. /sdcard/path/to/file.jsbundle or /data/data/path/to/file.jsbundle
return 'file://' + match[0] + getScaledAssetPath(asset);
} else {
// scriptURL has a scheme, E.g. assets://file.jsbundle
var assetDir = getBasePath(asset);
// E.g. 'assets_awesomemodule_icon'
// The Android resource system picks the correct scale.
return (assetDir + '/' + asset.name)
.toLowerCase()
.replace(/\//g, '_') // Encode folder structure in file name
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
.replace(/^assets_/, ''); // Remove "assets_" prefix
}

This comment has been minimized.

@zahanm

zahanm Dec 4, 2015

Contributor

nit: can you structure this block more like the iOS side encapsulating the offlinepath and scaledassetpath notions. Bonus points for unifying the code.

The android res handling is is going to need to be different, you can have a separate getResourcePath or something.

} else {
// E.g. 'assets/AwesomeModule/icon@2x.png'
return getOfflinePath() + getScaledAssetPath(asset);
ProTip! Use n and p to navigate between commits in a pull request.