Skip to content

Commit c06d5ba

Browse files
tbozhikovSvetoslavTsenov
authored andcommitted
chore: set keepAspectRatio to true as default in image-asset (NativeScript#5613)
* chore: set keepAspectRatio to true as default in image-asset * fix: remove empty lines
1 parent c5fa922 commit c06d5ba

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function testFromResource() {
1515
// >> imagesource-resname
1616
const img = imageSource.fromResource("icon");
1717
// << imagesource-resname
18-
18+
1919
TKUnit.assert(img.height > 0, "image.fromResource failed");
2020
}
2121

@@ -149,6 +149,22 @@ export function testFromAssetWithScalingAndAspectRatio(done) {
149149
});
150150
}
151151

152+
export function testFromAssetWithScalingAndDefaultAspectRatio(done) {
153+
let asset = new imageAssetModule.ImageAsset(splashscreenPath);
154+
let scaleWidth = 10;
155+
let scaleHeight = 11;
156+
asset.options.width = scaleWidth;
157+
asset.options.height = scaleHeight;
158+
159+
let img = imageSource.fromAsset(asset).then((source) => {
160+
TKUnit.assertEqual(source.width, 18);
161+
TKUnit.assertEqual(source.height, scaleHeight);
162+
done();
163+
}, (error) => {
164+
done(error);
165+
});
166+
}
167+
152168
export function testFromAssetWithBiggerScaling(done) {
153169
let asset = new imageAssetModule.ImageAsset(splashscreenPath);
154170
let scaleWidth = 600;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export class ImageAsset extends observable.Observable implements definition.Ima
99
ios: PHAsset;
1010
android: string;
1111

12+
constructor () {
13+
super();
14+
this._options = { keepAspectRatio: true };
15+
}
16+
1217
get options(): definition.ImageAssetOptions {
1318
return this._options;
1419
}

0 commit comments

Comments
 (0)