Skip to content

Commit 7506905

Browse files
authored
fix(image): image aspect dimensions for ImageSource.fromAsset(...) (NativeScript#5556)
1 parent c02bb28 commit 7506905

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

tests/app/image-source/image-source-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ export function testFromAssetWithScalingAndAspectRatio(done) {
141141
};
142142

143143
let img = imageSource.fromAsset(asset).then((source) => {
144-
TKUnit.assertEqual(source.width, scaleWidth);
145-
TKUnit.assertEqual(source.height, 5);
144+
TKUnit.assertEqual(source.width, 18);
145+
TKUnit.assertEqual(source.height, scaleHeight);
146146
done();
147147
}, (error) => {
148148
done(error);

tns-core-modules/image-asset/image-asset-common.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export class ImageAsset extends observable.Observable implements definition.Ima
3333
export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) {
3434
let widthCoef = sourceWidth / reqWidth;
3535
let heightCoef = sourceHeight / reqHeight;
36-
37-
let aspectCoef = widthCoef > heightCoef ? widthCoef : heightCoef;
36+
let aspectCoef = Math.min(widthCoef, heightCoef);
3837

3938
return {
4039
width: Math.floor(sourceWidth / aspectCoef),

0 commit comments

Comments
 (0)