-
-
Notifications
You must be signed in to change notification settings - Fork 197
fix(assets): Fix asset genration #3485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix the generation of asset - the filter is incorrect and fails with `Cannot read property 'splashImages' of null, TypeError: Cannot read property 'splashImages' of null` Also fix the scale - it has been incorrectly declared as number, when it is string (1x, 2x, etc.). Use the scale correctly by parsing it and use it when generate the image. Also fix the using of resizeOperation property - it was not passed correctly for iOS assets.
@@ -55,7 +56,14 @@ export class AssetsGenerationService implements IAssetsGenerationService { | |||
|
|||
for (const assetItem of assetItems) { | |||
const operation = assetItem.resizeOperation || Operations.Resize; | |||
const scale = assetItem.scale || 0.8; | |||
let tempScale: number = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case when assetItem.scale
is a number, scale
will always be 0.8
and assetItem.scale
will be disregarded. Is it the desired behaviour?
If not it should be let tempScale = assetItem.scale
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks , I've fixed it in the code below
image.height = assetItem.height; | ||
image.size = `${assetItem.width}${AssetConstants.sizeDelimiter}${assetItem.height}`; | ||
// Find the image size based on the hardcoded values in the image-definitions.json | ||
_.each(imageDefinitions, (assetSubGroup: IAssetItem[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion (not a merge stopper), not sure if it is working correctly.
_(imageDefinitions)
.filter((assetSubGroup: IAssetItem[]) => _.find(assetSubGroup, assetElement => assetElement.filename === image.filename && path.basename(assetElement.directory) === path.basename(dirPath)))
.map((assetItem: IAssetItem) => {
if (image.size) {
// size is basically <width>x<height>
const [width, height] = image.size.toString().split(AssetConstants.sizeDelimiter);
if (width && height) {
image.width = +width;
image.height = +height;
}
}
if (!image.width || !image.height) {
image.width = assetItem.width;
image.height = assetItem.height;
image.size = image.size || `${assetItem.width}${AssetConstants.sizeDelimiter}${assetItem.height}`;
}
});
tempScale = splittedElements && splittedElements.length && splittedElements[0] && +splittedElements[0]; | ||
} | ||
|
||
const scale = tempScale || 0.8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scale must be applied to all resize operations.
Set correct sizes for iOS images in image-definitions.json. Also fix the code that resizes the images and overlay images. Add option to have overlayImageScale in the json. We've not set it now, but the code will respect it in case we decide to add it.
} | ||
} | ||
|
||
const scale = tempScale || 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 can be extracted as a constant.
|
||
switch (operation) { | ||
case Operations.OverlayWith: | ||
const imageResize = Math.round(Math.min(assetItem.width, assetItem.height) * scale); | ||
const overlayImageScale = assetItem.overlayImageScale || 0.8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also 0.8 can be extracted as a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix the generation of asset - the filter is incorrect and fails with
Cannot read property 'splashImages' of null, TypeError: Cannot read property 'splashImages' of null
Also fix the scale - it has been incorrectly declared as number, when it is string (1x, 2x, etc.). Use the scale correctly by parsing it and use it when generate the image.
Also fix the using of resizeOperation property - it was not passed correctly for iOS assets.
chore: Update to latest common lib