From 7506905770ced0797d46a65464f6f0666549abfe Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Mon, 19 Mar 2018 17:01:26 +0200 Subject: [PATCH] fix(image): image aspect dimensions for ImageSource.fromAsset(...) (#5556) --- tests/app/image-source/image-source-tests.ts | 4 ++-- tns-core-modules/image-asset/image-asset-common.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/app/image-source/image-source-tests.ts b/tests/app/image-source/image-source-tests.ts index 352a4d4a3..1209a3390 100644 --- a/tests/app/image-source/image-source-tests.ts +++ b/tests/app/image-source/image-source-tests.ts @@ -141,8 +141,8 @@ export function testFromAssetWithScalingAndAspectRatio(done) { }; let img = imageSource.fromAsset(asset).then((source) => { - TKUnit.assertEqual(source.width, scaleWidth); - TKUnit.assertEqual(source.height, 5); + TKUnit.assertEqual(source.width, 18); + TKUnit.assertEqual(source.height, scaleHeight); done(); }, (error) => { done(error); diff --git a/tns-core-modules/image-asset/image-asset-common.ts b/tns-core-modules/image-asset/image-asset-common.ts index b50f6594a..56dac6850 100644 --- a/tns-core-modules/image-asset/image-asset-common.ts +++ b/tns-core-modules/image-asset/image-asset-common.ts @@ -33,8 +33,7 @@ export class ImageAsset extends observable.Observable implements definition.Ima export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) { let widthCoef = sourceWidth / reqWidth; let heightCoef = sourceHeight / reqHeight; - - let aspectCoef = widthCoef > heightCoef ? widthCoef : heightCoef; + let aspectCoef = Math.min(widthCoef, heightCoef); return { width: Math.floor(sourceWidth / aspectCoef),