mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(image): image aspect dimensions for ImageSource.fromAsset(...) (#5556)
This commit is contained in:
@@ -141,8 +141,8 @@ export function testFromAssetWithScalingAndAspectRatio(done) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let img = imageSource.fromAsset(asset).then((source) => {
|
let img = imageSource.fromAsset(asset).then((source) => {
|
||||||
TKUnit.assertEqual(source.width, scaleWidth);
|
TKUnit.assertEqual(source.width, 18);
|
||||||
TKUnit.assertEqual(source.height, 5);
|
TKUnit.assertEqual(source.height, scaleHeight);
|
||||||
done();
|
done();
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
done(error);
|
done(error);
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ export class ImageAsset extends observable.Observable implements definition.Ima
|
|||||||
export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) {
|
export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) {
|
||||||
let widthCoef = sourceWidth / reqWidth;
|
let widthCoef = sourceWidth / reqWidth;
|
||||||
let heightCoef = sourceHeight / reqHeight;
|
let heightCoef = sourceHeight / reqHeight;
|
||||||
|
let aspectCoef = Math.min(widthCoef, heightCoef);
|
||||||
let aspectCoef = widthCoef > heightCoef ? widthCoef : heightCoef;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
width: Math.floor(sourceWidth / aspectCoef),
|
width: Math.floor(sourceWidth / aspectCoef),
|
||||||
|
|||||||
Reference in New Issue
Block a user