Skip to content

Commit

Permalink
Added: informational error message on getting Android drawable folder… (
Browse files Browse the repository at this point in the history
#17751)

Summary:
… suffix for asset

Better informational error message on getting Android drawable folder suffix error using the asset name scale.

<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

I've got an not well described error when trying to bundle my React Native project package.

You can test the React Native bundle command like this:

node node_modules/react-native/local-cli/cli.js bundle --platform android --dev false --reset-cache --entry-file index.android.js --bundle-output /project/android/app/build/intermediates/assets/release/index.android.bundle --assets-dest /project/android/app/build

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/react-native-website, and link to your PR here.)

<!--
Help reviewers and the release process by writing your own release notes

**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

  CATEGORY
[----------]        TYPE
[ CLI      ]   [-------------]      LOCATION
[ DOCS     ]   [ BREAKING    ]   [-------------]
[ GENERAL  ]   [ BUGFIX      ]   [-{Component}-]
[ INTERNAL ]   [ ENHANCEMENT ]   [ {File}      ]
[ IOS      ]   [ FEATURE     ]   [ {Directory} ]   |-----------|
[ ANDROID  ]   [ MINOR       ]   [ {Framework} ] - | {Message} |
[----------]   [-------------]   [-------------]   |-----------|

[CATEGORY] [TYPE] [LOCATION] - MESSAGE

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Pull Request resolved: #17751

Differential Revision: D13840597

Pulled By: cpojer

fbshipit-source-id: f755ef665b76ce3dd9c96e575fbc71e9aaf43a44
  • Loading branch information
BrunoVillanova authored and facebook-github-bot committed Jan 28, 2019
1 parent 46aaa02 commit a159a33
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Libraries/Image/assetPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit a159a33

Please sign in to comment.