Skip to content

Commit 47fe523

Browse files
Dmitry Zakharovfacebook-github-bot
Dmitry Zakharov
authored andcommitted
Migrate SourceCode from Native Module to a Native Extension.
Reviewed By: danzimm Differential Revision: D6848275 fbshipit-source-id: c50305018aa2bdf014f5f665f370f65866197c3b
1 parent 528bbac commit 47fe523

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Libraries/Image/resolveAssetSource.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515

1616
const AssetRegistry = require('AssetRegistry');
1717
const AssetSourceResolver = require('AssetSourceResolver');
18-
const NativeModules = require('NativeModules');
1918

2019
import type { ResolvedAssetSource } from 'AssetSourceResolver';
2120

2221
let _customSourceTransformer, _serverURL, _scriptURL;
22+
let _sourceCodeScriptURL: ?string;
2323

2424
function getDevServerURL(): ?string {
2525
if (_serverURL === undefined) {
26-
var scriptURL = NativeModules.SourceCode.scriptURL;
27-
var match = scriptURL && scriptURL.match(/^https?:\/\/.*?\//);
26+
const match = _sourceCodeScriptURL && _sourceCodeScriptURL.match(/^https?:\/\/.*?\//);
2827
if (match) {
2928
// jsBundle was loaded from network
3029
_serverURL = match[0];
@@ -54,8 +53,7 @@ function _coerceLocalScriptURL(scriptURL: ?string): ?string {
5453

5554
function getScriptURL(): ?string {
5655
if (_scriptURL === undefined) {
57-
const scriptURL = NativeModules.SourceCode.scriptURL;
58-
_scriptURL = _coerceLocalScriptURL(scriptURL);
56+
_scriptURL = _coerceLocalScriptURL(_sourceCodeScriptURL);
5957
}
6058
return _scriptURL;
6159
}
@@ -91,6 +89,13 @@ function resolveAssetSource(source: any): ?ResolvedAssetSource {
9189
return resolver.defaultAsset();
9290
}
9391

92+
let sourceCodeScriptURL: ?string = global.nativeExtensions && global.nativeExtensions.SourceCode && global.nativeExtensions.SourceCode.scriptURL;
93+
if (!sourceCodeScriptURL) {
94+
const NativeModules = require('NativeModules');
95+
sourceCodeScriptURL = NativeModules && NativeModules.SourceCode && NativeModules.SourceCode.scriptURL;
96+
}
97+
_sourceCodeScriptURL = sourceCodeScriptURL;
98+
9499
module.exports = resolveAssetSource;
95100
module.exports.pickScale = AssetSourceResolver.pickScale;
96101
module.exports.setCustomSourceTransformer = setCustomSourceTransformer;

0 commit comments

Comments
 (0)