mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
2
.gitignore
vendored
2
.gitignore
vendored
@ -42,3 +42,5 @@ tns-core-modules.es6.d.ts
|
||||
tests/platforms/
|
||||
tests/lib/
|
||||
*.log
|
||||
|
||||
.DS_Store
|
BIN
tests/app/ui/image/700x50.png
Normal file
BIN
tests/app/ui/image/700x50.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 808 B |
@ -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";
|
||||
|
||||
@ -334,3 +335,23 @@ 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 density = utils.layout.getDisplayDensity();
|
||||
let limit = 414;
|
||||
host.width = limit / density;
|
||||
host.height = limit / density;
|
||||
host.addChild(image);
|
||||
let mainPage = helper.getCurrentPage();
|
||||
mainPage.content = host;
|
||||
TKUnit.waitUntilReady(() => host.isLoaded);
|
||||
TKUnit.waitUntilReady(() => image.isLayoutValid);
|
||||
|
||||
let scale = limit / 700;
|
||||
let expectedHeight = Math.round(50 * scale);
|
||||
TKUnit.assertEqual(image.getMeasuredWidth(), limit, "Actual width is different from expected width.");
|
||||
TKUnit.assertEqual(image.getMeasuredHeight(), expectedHeight, "Actual height is different from expected height.");
|
||||
};
|
@ -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;
|
||||
|
Reference in New Issue
Block a user