packager: assetPathUtils: @flow

Reviewed By: cpojer

Differential Revision: D4913888

fbshipit-source-id: 31ddb4b9ede65e1b6caf740a245c3a11326d15d6
This commit is contained in:
Jean Lauliac 2017-04-19 10:37:31 -07:00 committed by Facebook Github Bot
parent 0b339362ff
commit aef286791a
1 changed files with 15 additions and 5 deletions

View File

@ -5,10 +5,19 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
'use strict';
function getAndroidAssetSuffix(scale) {
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';
/**
* FIXME: using number to represent discrete scale numbers is fragile in essence because of
* floating point numbers imprecision.
*/
function getAndroidAssetSuffix(scale: number): string {
switch (scale) {
case 0.75: return 'ldpi';
case 1: return 'mdpi';
@ -17,9 +26,10 @@ function getAndroidAssetSuffix(scale) {
case 3: return 'xxhdpi';
case 4: return 'xxxhdpi';
}
throw new Error('no such scale');
}
function getAndroidDrawableFolderName(asset, scale) {
function getAndroidDrawableFolderName(asset: PackagerAsset, scale: number) {
var suffix = getAndroidAssetSuffix(scale);
if (!suffix) {
throw new Error(
@ -31,7 +41,7 @@ function getAndroidDrawableFolderName(asset, scale) {
return androidFolder;
}
function getAndroidResourceIdentifier(asset) {
function getAndroidResourceIdentifier(asset: PackagerAsset) {
var folderPath = getBasePath(asset);
return (folderPath + '/' + asset.name)
.toLowerCase()
@ -40,7 +50,7 @@ function getAndroidResourceIdentifier(asset) {
.replace(/^assets_/, ''); // Remove "assets_" prefix
}
function getBasePath(asset) {
function getBasePath(asset: PackagerAsset) {
var basePath = asset.httpServerLocation;
if (basePath[0] === '/') {
basePath = basePath.substr(1);