Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ tns-core-modules.es6.d.ts
tests/platforms/
tests/lib/
*.log

.DS_Store
Binary file added tests/app/ui/image/700x50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions tests/app/ui/image/image-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {StackLayout} from "ui/layouts/stack-layout";
import {GridLayout} from "ui/layouts/grid-layout";
import {isIOS} from "platform";
import {PropertyChangeData} from "data/observable";
import utils = require("utils/utils");

// import {target} from "../../TKUnit";

Expand Down Expand Up @@ -334,3 +335,25 @@ export var test_SettingImageSourceWhenSizedToContentShouldInvalidate = ios(() =>
TKUnit.assertTrue(called, "image.requestLayout should be called.");
});

export var test_DimensionsAreRoundedAfterScale = function() {
let host = new StackLayout();
let image = new Image();
image.src = "~/ui/image/700x50.png";
let imageWidth = 700;
let imageHeight = 50;

let density = utils.layout.getDisplayDensity();
let hostWidth = 320;
host.width = hostWidth / density;
host.height = hostWidth / density;
host.addChild(image);
let mainPage = helper.getCurrentPage();
mainPage.content = host;
TKUnit.waitUntilReady(() => host.isLoaded);
TKUnit.waitUntilReady(() => image.isLayoutValid);

let scale = hostWidth / imageWidth;
let expectedHeight = Math.round(imageHeight * scale);
TKUnit.assertEqual(image.getMeasuredWidth(), hostWidth, "Actual width is different from expected width.");
TKUnit.assertEqual(image.getMeasuredHeight(), expectedHeight, "Actual height is different from expected height.");
};
4 changes: 2 additions & 2 deletions tns-core-modules/ui/image/image.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export class Image extends imageCommon.Image {

if (nativeWidth !== 0 && nativeHeight !== 0 && (finiteWidth || finiteHeight)) {
var scale = Image.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.stretch);
var resultW = Math.floor(nativeWidth * scale.width);
var resultH = Math.floor(nativeHeight * scale.height);
var resultW = Math.round(nativeWidth * scale.width);
var resultH = Math.round(nativeHeight * scale.height);

measureWidth = finiteWidth ? Math.min(resultW, width) : resultW;
measureHeight = finiteHeight ? Math.min(resultH, height) : resultH;
Expand Down