Skip to content

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

Merged
merged 4 commits into from
Mar 22, 2018
Merged

Conversation

rosen-vladimirov
Copy link
Contributor

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

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.
@rosen-vladimirov rosen-vladimirov added this to the 4.0.0 milestone Mar 21, 2018
@rosen-vladimirov rosen-vladimirov self-assigned this Mar 21, 2018
@@ -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;
Copy link
Contributor

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

Copy link
Contributor Author

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[]) => {
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

@Fatme Fatme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rosen-vladimirov rosen-vladimirov merged commit 542eb36 into release Mar 22, 2018
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/fix-assets branch March 22, 2018 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants