Permalink
Browse files

packager: assetPathUtils: @flow

Reviewed By: cpojer

Differential Revision: D4913888

fbshipit-source-id: 31ddb4b9ede65e1b6caf740a245c3a11326d15d6
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Apr 19, 2017
1 parent 0b33936 commit aef286791a968c8952f195d1001a311d3565c37a
Showing with 15 additions and 5 deletions.
  1. +15 −5 local-cli/bundle/assetPathUtils.js
@@ -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);
@@ -53,4 +63,4 @@ module.exports = {
getAndroidDrawableFolderName: getAndroidDrawableFolderName,
getAndroidResourceIdentifier: getAndroidResourceIdentifier,
getBasePath: getBasePath
};
};

0 comments on commit aef2867

Please sign in to comment.