Always return `scale` from resolveAssetSource
Reviewed By: @nicklockwood Differential Revision: D2532565 fb-gh-sync-id: 113b8318a8f1a9b0dac4fab389a98ddd51d00e17
This commit is contained in:
parent
144f8598c2
commit
393ead59dc
|
@ -132,6 +132,7 @@ describe('resolveAssetSource', () => {
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 200,
|
height: 200,
|
||||||
uri: 'assets/module/a/logo.png',
|
uri: 'assets/module/a/logo.png',
|
||||||
|
scale: 1,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -160,6 +161,7 @@ describe('resolveAssetSource', () => {
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 200,
|
height: 200,
|
||||||
uri: 'awesomemodule_subdir_logo1_',
|
uri: 'awesomemodule_subdir_logo1_',
|
||||||
|
scale: 1,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,11 +7,21 @@
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*
|
*
|
||||||
* @providesModule resolveAssetSource
|
* @providesModule resolveAssetSource
|
||||||
|
* @flow
|
||||||
*
|
*
|
||||||
* Resolves an asset into a `source` for `Image`.
|
* Resolves an asset into a `source` for `Image`.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
export type ResolvedAssetSource = {
|
||||||
|
__packager_asset: boolean,
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
uri: string,
|
||||||
|
isStatic: boolean,
|
||||||
|
scale: number,
|
||||||
|
};
|
||||||
|
|
||||||
var AssetRegistry = require('AssetRegistry');
|
var AssetRegistry = require('AssetRegistry');
|
||||||
var PixelRatio = require('PixelRatio');
|
var PixelRatio = require('PixelRatio');
|
||||||
var Platform = require('Platform');
|
var Platform = require('Platform');
|
||||||
|
@ -86,7 +96,7 @@ function getScaledAssetPath(asset) {
|
||||||
return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;
|
return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pickScale(scales, deviceScale) {
|
function pickScale(scales: Array<number>, deviceScale: number): number {
|
||||||
// Packager guarantees that `scales` array is sorted
|
// Packager guarantees that `scales` array is sorted
|
||||||
for (var i = 0; i < scales.length; i++) {
|
for (var i = 0; i < scales.length; i++) {
|
||||||
if (scales[i] >= deviceScale) {
|
if (scales[i] >= deviceScale) {
|
||||||
|
@ -100,7 +110,7 @@ function pickScale(scales, deviceScale) {
|
||||||
return scales[scales.length - 1] || 1;
|
return scales[scales.length - 1] || 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveAssetSource(source) {
|
function resolveAssetSource(source: any): ?ResolvedAssetSource {
|
||||||
if (typeof source === 'object') {
|
if (typeof source === 'object') {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +123,7 @@ function resolveAssetSource(source) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function assetToImageSource(asset) {
|
function assetToImageSource(asset): ResolvedAssetSource {
|
||||||
var devServerURL = getDevServerURL();
|
var devServerURL = getDevServerURL();
|
||||||
if (devServerURL) {
|
if (devServerURL) {
|
||||||
return {
|
return {
|
||||||
|
@ -131,6 +141,7 @@ function assetToImageSource(asset) {
|
||||||
height: asset.height,
|
height: asset.height,
|
||||||
uri: getPathInArchive(asset),
|
uri: getPathInArchive(asset),
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
|
scale: pickScale(asset.scales, PixelRatio.get()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue