FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Image should not requestLayout when measured with 'exactly' spec by PanayotCankov · Pull Request #2198 · NativeScript/NativeScript · GitHub

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

Filter by extension

Filter by extension .js  (1) .json  (1) .ts  (7) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
99 changes: 81 additions & 18 deletions build/tsc-dev.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,88 @@ var ts = require("typescript");
var fs = require("fs");
var path = require("path");
var arg1 = process.argv.length > 2 ? process.argv[2] : "";
var isTranspile = arg1.indexOf("t") >= 0;
var isIncremental = arg1.indexOf("i") >= 0;
var isWatching = arg1.indexOf("w") >= 0;
var opts = [];
if (isTranspile) {
opts.push("transpile");
}
if (isIncremental) {
console.log("incremental");
opts.push("incremental");
}
if (isWatching) {
opts.push("watch");
}
if (opts.length > 0) {
console.log("Options: " + opts.join(", "));
}
function isTS(file) {
return file.lastIndexOf(".ts") === file.length - 3;
}
function isDTS(file) {
return file.lastIndexOf(".d.ts") === file.length - 5;
}
function getJsPath(tsPath) {
return path.join(path.dirname(tsPath), path.basename(tsPath, ".ts")) + ".js";
}
function hasChanged(tsName) {
try {
var jsName = getJsPath(tsName);
var tsTime = fs.statSync(tsName).mtime.getTime();
var jsTime = fs.statSync(jsName).mtime.getTime();
return jsTime < tsTime;
}
catch (e) {
return true;
}
}
function transpile(fileNames, options) {
console.time("transpile");
var files = fileNames.filter(function (f) { return !isDTS(f); });
if (isIncremental) {
files = files.filter(hasChanged);
}
files.forEach(function (tsPath) {
var tsSource = fs.readFileSync(tsPath, { encoding: "utf8" });
var jsSource = ts.transpile(tsSource, options);
var jsPath = getJsPath(tsPath);
fs.writeFileSync(jsPath, jsSource, { flag: "w" }, function (err) { console.log(err); });
if (isIncremental) {
console.log(" - " + tsPath);
}
});
console.timeEnd("transpile");
if (isWatching) {
console.log("Watching for changes...");
fs.watch(".", { persistent: true, recursive: true, encoding: "utf8" }, function (event, file) {
try {
if (isTS(file) && !isDTS(file)) {
var tsPath = file;
var label = " - " + tsPath;
console.time(label);
var tsSource = fs.readFileSync(tsPath, { encoding: "utf8" });
var jsSource = ts.transpile(tsSource, options);
var jsPath = getJsPath(tsPath);
fs.writeFileSync(jsPath, jsSource, { flag: "w" }, function (err) { console.log(err); });
console.timeEnd(label);
}
}
catch (e) {
}
});
}
}
function compile(fileNames, options) {
console.time("program");
var program = ts.createProgram(fileNames, options);
console.timeEnd("program");
var sourceFiles = program.getSourceFiles().filter(function (f) { return f.fileName.lastIndexOf(".d.ts") !== f.fileName.length - 5; });
var sourceFiles = program.getSourceFiles().filter(function (f) { return !isDTS(f.fileName); });
var emitResults = [];
var allDiagnostics = [];
console.time("transpile");
if (isIncremental) {
sourceFiles = sourceFiles.filter(function (srcFile) {
try {
var tsName = srcFile.fileName;
var jsName = path.join(path.dirname(tsName), path.basename(tsName, ".ts")) + ".js";
var tsTime = fs.statSync(tsName).mtime.getTime();
var jsTime = fs.statSync(jsName).mtime.getTime();
return jsTime < tsTime;
}
catch (e) {
return true;
}
});
sourceFiles = sourceFiles.filter(function (srcFile) { return hasChanged(srcFile.fileName); });
sourceFiles.forEach(function (srcFile) {
console.log(" - " + srcFile.fileName);
emitResults.push(program.emit(srcFile));
Expand All @@ -54,13 +111,19 @@ function compile(fileNames, options) {
process.exit(exitCode);
}
var files = JSON.parse(fs.readFileSync("./tsconfig.json")).files;
compile(files, {
var options = {
noEmitOnError: true,
noEmitHelpers: true,
target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
target: 1 /* ES5 */,
module: 1 /* CommonJS */,
declaration: false,
noImplicitAny: false,
noImplicitUseStrict: true,
experimentalDecorators: true
});
};
if (isTranspile) {
transpile(files, { module: 1 /* CommonJS */ });
}
else {
compile(files, options);
}
110 changes: 90 additions & 20 deletions build/tsc-dev.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,104 @@ var path = require("path");

var arg1 = process.argv.length > 2 ? process.argv[2] : "";

var isTranspile = arg1.indexOf("t") >= 0;
var isIncremental = arg1.indexOf("i") >= 0;
var isWatching = arg1.indexOf("w") >= 0;

var opts = [];

if (isTranspile) {
opts.push("transpile");
}

if (isIncremental) {
console.log("incremental");
opts.push("incremental");
}

if (isWatching) {
opts.push("watch");
}

if (opts.length > 0) {
console.log("Options: " + opts.join(", "));
}

function isTS(file: string): boolean {
return file.lastIndexOf(".ts") === file.length - 3;
}

function isDTS(file: string): boolean {
return file.lastIndexOf(".d.ts") === file.length - 5;
}

function getJsPath(tsPath: string): string {
return path.join(path.dirname(tsPath), path.basename(tsPath, ".ts")) + ".js";
}

function hasChanged(tsName: string): boolean {
try {
var jsName = getJsPath(tsName);

var tsTime = fs.statSync(tsName).mtime.getTime();
var jsTime = fs.statSync(jsName).mtime.getTime();

return jsTime < tsTime;
} catch(e) {
return true;
}
}

function transpile(fileNames: string[], options: ts.CompilerOptions) {
console.time("transpile");
var files = fileNames.filter(f => !isDTS(f));
if (isIncremental) {
files = files.filter(hasChanged);
}
files.forEach(tsPath => {
var tsSource = fs.readFileSync(tsPath, { encoding: "utf8" });
var jsSource = ts.transpile(tsSource, options);
var jsPath = getJsPath(tsPath);
fs.writeFileSync(jsPath, jsSource, { flag: "w" }, function(err) { console.log(err); });
if (isIncremental) {
console.log(" - " + tsPath);
}
});
console.timeEnd("transpile");

if (isWatching) {
console.log("Watching for changes...");
fs.watch(".", { persistent: true, recursive: true, encoding: "utf8" }, (event, file) => {
try {
if (isTS(file) && !isDTS(file)) {
var tsPath = file;
var label = " - " + tsPath;
console.time(label);
var tsSource = fs.readFileSync(tsPath, { encoding: "utf8" });
var jsSource = ts.transpile(tsSource, options);
var jsPath = getJsPath(tsPath);
fs.writeFileSync(jsPath, jsSource, { flag: "w" }, function(err) { console.log(err); });
console.timeEnd(label);
}
} catch(e) {
// console.log(e);
}
});
}
}

function compile(fileNames: string[], options: ts.CompilerOptions) {
console.time("program");
var program = ts.createProgram(fileNames, options);

console.timeEnd("program");
var sourceFiles = program.getSourceFiles().filter(f => f.fileName.lastIndexOf(".d.ts") !== f.fileName.length - 5);
var sourceFiles = program.getSourceFiles().filter(f => !isDTS(f.fileName));

var emitResults = [];
var allDiagnostics = [];

console.time("transpile");
if (isIncremental) {
sourceFiles = sourceFiles.filter(srcFile => {
try {
var tsName = srcFile.fileName;
var jsName = path.join(path.dirname(tsName), path.basename(tsName, ".ts")) + ".js";

var tsTime = fs.statSync(tsName).mtime.getTime();
var jsTime = fs.statSync(jsName).mtime.getTime();

return jsTime < tsTime;
} catch(e) {
return true;
}
});

sourceFiles = sourceFiles.filter(srcFile => hasChanged(srcFile.fileName));
sourceFiles.forEach(srcFile => {
console.log(" - " + srcFile.fileName);
emitResults.push(program.emit(srcFile));
Expand Down Expand Up @@ -66,8 +133,7 @@ function compile(fileNames: string[], options: ts.CompilerOptions) {
}

var files = JSON.parse(fs.readFileSync("./tsconfig.json")).files;
compile(files,
{
var options: ts.CompilerOptions = {
noEmitOnError: true,
noEmitHelpers: true,
target: ts.ScriptTarget.ES5,
Expand All @@ -76,5 +142,9 @@ compile(files,
noImplicitAny: false,
noImplicitUseStrict: true,
experimentalDecorators: true
});

};
if (isTranspile) {
transpile(files, { module: ts.ModuleKind.CommonJS });
} else {
compile(files, options);
}
5 changes: 5 additions & 0 deletions package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
"time-grunt": "1.3.0",
"tslint": "3.4.0",
"typescript": "1.8.2"
},
"scripts": {
"tsc-tiw": "node build/tsc-dev.js tiw",
"tsc": "tsc",
"link-tests": "cd tns-core-modules && npm link && cd ../tests && npm link tns-core-modules"
}
}
10 changes: 10 additions & 0 deletions tests/app/platform-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import TKUnit = require("./TKUnit");
import app = require("application");
import { isIOS, isAndroid } from "platform";

// >> platform-require
import platformModule = require("platform");
Expand Down Expand Up @@ -29,3 +30,12 @@ export function snippet_print_all() {
console.log("Screen scale: " + platformModule.screen.mainScreen.scale);
// << platform-current
};

export function testIsIOSandIsAndroid() {
if (isIOS) {
TKUnit.assertTrue(!!NSObject, "isIOS is true-ish but common iOS APIs are not available.");
} else if (isAndroid) {
TKUnit.assertTrue(!!android, "isAndroid is true but common 'android' package is not available.");
}
}

68 changes: 67 additions & 1 deletion tests/app/ui/image/image-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import TKUnit = require("../../TKUnit");
import {Image} from "ui/image";
import {StackLayout} from "ui/layouts/stack-layout";
import {GridLayout} from "ui/layouts/grid-layout";
import {isIOS} from "platform";
// import {target} from "../../TKUnit";

import TKUnit = require("../../TKUnit");

// >> img-require
import ImageModule = require("ui/image");
// << img-require
Expand Down Expand Up @@ -244,3 +251,62 @@ export var test_SettingStretch_none = function () {

helper.buildUIAndRunTest(image, testFunc);
}

function ios<T>(func: T): T {
return isIOS ? func : undefined;
}

export var test_SettingImageSourceWhenSizedToParentDoesNotRequestLayout = ios(() => {
let host = new GridLayout();

let image = new Image();

host.width = 300;
host.height = 300;
host.addChild(image);

let mainPage = helper.getCurrentPage();
mainPage.content = host;
TKUnit.waitUntilReady(() => host.isLoaded);

let called = false;
image.requestLayout = () => called = true;
image.src = "~/logo.png";

TKUnit.assertFalse(called, "image.requestLayout should not be called.");
});

export var test_SettingImageSourceWhenFixedWidthAndHeightDoesNotRequestLayout = ios(() => {
let host = new StackLayout();
let image = new Image();
image.width = 100;
image.height = 100;
host.addChild(image);

let mainPage = helper.getCurrentPage();
mainPage.content = host;
TKUnit.waitUntilReady(() => host.isLoaded);

let called = false;
image.requestLayout = () => called = true;
image.src = "~/logo.png";

TKUnit.assertFalse(called, "image.requestLayout should not be called.");
});

export var test_SettingImageSourceWhenSizedToContentShouldInvalidate = ios(() => {
let host = new StackLayout();
let image = new Image();
host.addChild(image);

let mainPage = helper.getCurrentPage();
mainPage.content = host;
TKUnit.waitUntilReady(() => host.isLoaded);

let called = false;
image.requestLayout = () => called = true;
image.src = "~/logo.png";

TKUnit.assertTrue(called, "image.requestLayout should be called.");
});

2 changes: 2 additions & 0 deletions tns-core-modules/platform/platform.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,5 @@ export var device: definition.Device = new Device();
export module screen {
export var mainScreen = new MainScreen();
}

export var isAndroid = true;
Loading

Back | FazBrowse Home | New Git URL