Merge branch 'master' into animate-width-height

This commit is contained in:
Martin Yankov
2019-05-08 08:52:36 +03:00
committed by GitHub
5 changed files with 65 additions and 22 deletions

View File

@ -16,6 +16,7 @@ John Bristowe <john.bristowe@telerik.com>
Joe D <joed@destefano.homelinux.com>
Kamen Velikov <kamen.velikov@telerik.com>
Lubomir Blagoev <lubomir.blagoev@telerik.com>
Luke Curran <luke@pepper.me>
Matt Donovan <unsecurepeax@gmail.com>
Matthew Knight <anarchicknight@gmail.com>
Mihail Slavchev <mihail.slavchev@telerik.com>

View File

@ -189,6 +189,9 @@ allTests["TAB-VIEW-NAVIGATION"] = tabViewNavigationTests;
import * as imageTests from "./ui/image/image-tests";
allTests["IMAGE"] = imageTests;
import * as imageCacheTests from "./ui/image-cache/image-cache-tests";
allTests["IMAGE-CACHE"] = imageCacheTests;
import * as sliderTests from "./ui/slider/slider-tests";
allTests["SLIDER"] = sliderTests;

View File

@ -1,25 +1,21 @@
// >> image-cache-require
import * as imageCacheModule from "tns-core-modules/ui/image-cache";
import * as imageCacheModule from "tns-core-modules/ui/image-cache";
import * as imageSource from "tns-core-modules/image-source";
import * as fs from "tns-core-modules/file-system";
// << image-cache-require
import * as types from "tns-core-modules/utils/types";
import * as TKUnit from "../../TKUnit";
export function test_DummyTestForSnippetOnly() {
// >> image-cache-request-images
var cache = new imageCacheModule.Cache();
cache.placeholder = imageSource.fromFile(fs.path.join(__dirname, "res/no-image.png"));
export const test_ImageCache_ValidUrl = function() {
const cache = new imageCacheModule.Cache();
cache.maxRequests = 5;
// Enable download while not scrolling
cache.enableDownload();
let validKey: string;
var imgSouce: imageSource.ImageSource;
var url = "https://github.com/NativeScript.png";
let imgSource: imageSource.ImageSource;
const url = "https://github.com/NativeScript.png";
// Try to read the image from the cache
var image = cache.get(url);
const image = cache.get(url);
if (image) {
// If present -- use it.
imgSouce = imageSource.fromNativeSource(image);
imgSource = imageSource.fromNativeSource(image);
}
else {
// If not present -- request its download.
@ -28,13 +24,51 @@ export function test_DummyTestForSnippetOnly() {
url: url,
completed: (image: any, key: string) => {
if (url === key) {
imgSouce = imageSource.fromNativeSource(image);
imgSource = imageSource.fromNativeSource(image);
validKey = key;
console.log("Valid url: ", key);
}
}
});
}
// Disable download while scrolling
cache.disableDownload();
// << image-cache-request-images
TKUnit.waitUntilReady(() => types.isDefined(validKey), 8);
TKUnit.assertEqual(validKey, url, "Key should equal the provided url");
}
export const test_ImageCache_NothingAtProvidedUrl = function() {
const cache = new imageCacheModule.Cache();
cache.maxRequests = 5;
let errorCaught = false;
let errorMessage: string;
let imgSource: imageSource.ImageSource;
const url = "https://github.com/NativeScript-NoImage.png";
// Try to read the image from the cache
const image = cache.get(url);
if (image) {
// If present -- use it.
imgSource = imageSource.fromNativeSource(image);
}
else {
// If not present -- request its download.
cache.push({
key: url,
url: url,
completed: (image: any, key: string) => {
if (url === key) {
imgSource = imageSource.fromNativeSource(image);
}
},
error: (key: string) => {
console.log("No image for key: ", key);
errorMessage = `No image for key: ${key}`;
errorCaught = true;
}
});
}
TKUnit.waitUntilReady(() => errorCaught);
TKUnit.assertEqual(`No image for key: ${url}`, errorMessage);
}

View File

@ -91,6 +91,7 @@ export class Button extends ButtonBase {
this._highlightedHandler = this._highlightedHandler || ((args: TouchGestureEventData) => {
switch (args.action) {
case TouchAction.up:
case TouchAction.cancel:
this._goToVisualState("normal");
break;
case TouchAction.down:

View File

@ -72,7 +72,11 @@ export class Cache extends common.Cache {
.then((response) => {
try {
const image = UIImage.alloc().initWithData(response.content.raw);
if (image) {
this._onDownloadCompleted(request.key, image);
} else {
this._onDownloadError(request.key, new Error("No result for provided url"));
}
} catch (err) {
this._onDownloadError(request.key, err);
}