Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce47e56

Browse files
franticfacebook-github-bot-8
authored and
facebook-github-bot-8
committed
Attach platform to asset url
Summary: Depends on D2420548 Reviewed By: @martinbigio Differential Revision: D2421696
1 parent c4305fe commit ce47e56

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

Libraries/Image/__tests__/resolveAssetSource-test.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function expectResolvesAsset(input, expectedSource) {
2525
describe('resolveAssetSource', () => {
2626
beforeEach(() => {
2727
jest.resetModuleRegistry();
28+
__DEV__ = true;
2829
AssetRegistry = require('AssetRegistry');
2930
Platform = require('Platform');
3031
SourceCode = require('NativeModules').SourceCode;
@@ -64,6 +65,7 @@ describe('resolveAssetSource', () => {
6465
describe('bundle was loaded from network (DEV)', () => {
6566
beforeEach(() => {
6667
SourceCode.scriptURL = 'http://10.0.0.1:8081/main.bundle';
68+
Platform.OS = 'ios';
6769
});
6870

6971
it('uses network image', () => {
@@ -81,7 +83,7 @@ describe('resolveAssetSource', () => {
8183
isStatic: false,
8284
width: 100,
8385
height: 200,
84-
uri: 'http://10.0.0.1:8081/assets/module/a/logo.png?hash=5b6f00f',
86+
uri: 'http://10.0.0.1:8081/assets/module/a/logo.png?platform=ios&hash=5b6f00f',
8587
});
8688
});
8789

@@ -100,29 +102,19 @@ describe('resolveAssetSource', () => {
100102
isStatic: false,
101103
width: 100,
102104
height: 200,
103-
uri: 'http://10.0.0.1:8081/assets/module/a/[email protected]?hash=5b6f00f',
105+
uri: 'http://10.0.0.1:8081/assets/module/a/[email protected]?platform=ios&hash=5b6f00f',
104106
});
105107
});
106108

107109
});
108110

109111
describe('bundle was loaded from file (PROD) on iOS', () => {
110-
var originalDevMode;
111-
var originalPlatform;
112-
113112
beforeEach(() => {
114113
SourceCode.scriptURL = 'file:///Path/To/Simulator/main.bundle';
115-
originalDevMode = __DEV__;
116-
originalPlatform = Platform.OS;
117114
__DEV__ = false;
118115
Platform.OS = 'ios';
119116
});
120117

121-
afterEach(() => {
122-
__DEV__ = originalDevMode;
123-
Platform.OS = originalPlatform;
124-
});
125-
126118
it('uses pre-packed image', () => {
127119
expectResolvesAsset({
128120
__packager_asset: true,
@@ -144,22 +136,12 @@ describe('resolveAssetSource', () => {
144136
});
145137

146138
describe('bundle was loaded from file (PROD) on Android', () => {
147-
var originalDevMode;
148-
var originalPlatform;
149-
150139
beforeEach(() => {
151140
SourceCode.scriptURL = 'file:///Path/To/Simulator/main.bundle';
152-
originalDevMode = __DEV__;
153-
originalPlatform = Platform.OS;
154141
__DEV__ = false;
155142
Platform.OS = 'android';
156143
});
157144

158-
afterEach(() => {
159-
__DEV__ = originalDevMode;
160-
Platform.OS = originalPlatform;
161-
});
162-
163145
it('uses pre-packed image', () => {
164146
expectResolvesAsset({
165147
__packager_asset: true,

Libraries/Image/resolveAssetSource.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function getPathInArchive(asset) {
6363
* from the devserver
6464
*/
6565
function getPathOnDevserver(devServerUrl, asset) {
66-
return devServerUrl + getScaledAssetPath(asset) + '?hash=' + asset.hash;
66+
return devServerUrl + getScaledAssetPath(asset) + '?platform=' + Platform.OS +
67+
'&hash=' + asset.hash;
6768
}
6869

6970
/**

0 commit comments

Comments
 (0)