diff --git a/Libraries/Image/__tests__/resolveAssetSource-test.js b/Libraries/Image/__tests__/resolveAssetSource-test.js index 6c1029ed7..81fdb2b08 100644 --- a/Libraries/Image/__tests__/resolveAssetSource-test.js +++ b/Libraries/Image/__tests__/resolveAssetSource-test.js @@ -107,7 +107,7 @@ describe('resolveAssetSource', () => { describe('bundle was loaded from file on iOS', () => { beforeEach(() => { NativeModules.SourceCode.scriptURL = - 'file:///Path/To/Simulator/main.bundle'; + 'file:///Path/To/Sample.app/main.bundle'; Platform.OS = 'ios'; }); @@ -126,7 +126,7 @@ describe('resolveAssetSource', () => { __packager_asset: true, width: 100, height: 200, - uri: 'assets/module/a/logo.png', + uri: '/Path/To/Sample.app/assets/module/a/logo.png', scale: 1, }); }); diff --git a/Libraries/Image/resolveAssetSource.js b/Libraries/Image/resolveAssetSource.js index a278a708f..638b72ce0 100644 --- a/Libraries/Image/resolveAssetSource.js +++ b/Libraries/Image/resolveAssetSource.js @@ -26,7 +26,7 @@ var PixelRatio = require('PixelRatio'); var Platform = require('Platform'); var SourceCode = require('NativeModules').SourceCode; -var _serverURL; +var _serverURL, _offlinePath; function getDevServerURL() { if (_serverURL === undefined) { @@ -44,6 +44,20 @@ function getDevServerURL() { return _serverURL; } +function getOfflinePath() { + if (_offlinePath === undefined) { + var scriptURL = SourceCode.scriptURL; + var match = scriptURL && scriptURL.match(/^file:\/\/(\/.*\/)/); + if (match) { + _offlinePath = match[1]; + } else { + _offlinePath = ''; + } + } + + return _offlinePath; +} + /** * Returns the path at which the asset can be found in the archive */ @@ -59,7 +73,7 @@ function getPathInArchive(asset) { .replace(/^assets_/, ''); // Remove "assets_" prefix } else { // E.g. 'assets/AwesomeModule/icon@2x.png' - return getScaledAssetPath(asset); + return getOfflinePath() + getScaledAssetPath(asset); } }