diff --git a/Libraries/Image/assetPathUtils.js b/Libraries/Image/assetPathUtils.js index 0b49343518d620..402680cef72779 100644 --- a/Libraries/Image/assetPathUtils.js +++ b/Libraries/Image/assetPathUtils.js @@ -12,26 +12,25 @@ import type {PackagerAsset} from './AssetRegistry'; +const androidScaleSuffix = { + '0.75': 'ldpi', + '1': 'mdpi', + '1.5': 'hdpi', + '2': 'xhdpi', + '3': 'xxhdpi', + '4': 'xxxhdpi', +}; + /** * 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'; - case 1.5: - return 'hdpi'; - case 2: - return 'xhdpi'; - case 3: - return 'xxhdpi'; - case 4: - return 'xxxhdpi'; + if (scale.toString() in androidScaleSuffix) { + return androidScaleSuffix[scale.toString()]; } - throw new Error('no such scale'); + + throw new Error('no such scale ' + scale.toString()); } // See https://developer.android.com/guide/topics/resources/drawable-resource.html @@ -52,8 +51,12 @@ function getAndroidResourceFolderName(asset: PackagerAsset, scale: number) { var suffix = getAndroidAssetSuffix(scale); if (!suffix) { throw new Error( - "Don't know which android drawable suffix to use for asset: " + - JSON.stringify(asset), + "Don't know which android drawable suffix to use for scale: " + + scale + + '\nAsset: ' + + JSON.stringify(asset, null, '\t') + + '\nPossible scales are:' + + JSON.stringify(androidScaleSuffix, null, '\t'), ); } const androidFolder = 'drawable-' + suffix;