mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Merge branch 'master' into animate-width-height
This commit is contained in:
3
AUTHORS
3
AUTHORS
@ -16,6 +16,7 @@ John Bristowe <john.bristowe@telerik.com>
|
|||||||
Joe D <joed@destefano.homelinux.com>
|
Joe D <joed@destefano.homelinux.com>
|
||||||
Kamen Velikov <kamen.velikov@telerik.com>
|
Kamen Velikov <kamen.velikov@telerik.com>
|
||||||
Lubomir Blagoev <lubomir.blagoev@telerik.com>
|
Lubomir Blagoev <lubomir.blagoev@telerik.com>
|
||||||
|
Luke Curran <luke@pepper.me>
|
||||||
Matt Donovan <unsecurepeax@gmail.com>
|
Matt Donovan <unsecurepeax@gmail.com>
|
||||||
Matthew Knight <anarchicknight@gmail.com>
|
Matthew Knight <anarchicknight@gmail.com>
|
||||||
Mihail Slavchev <mihail.slavchev@telerik.com>
|
Mihail Slavchev <mihail.slavchev@telerik.com>
|
||||||
@ -37,4 +38,4 @@ Vasil Chimev <Vasil.Chimev@telerik.com>
|
|||||||
Victor Nascimento <victormota15@gmail.com>
|
Victor Nascimento <victormota15@gmail.com>
|
||||||
Vladimir Enchev <vladimir.enchev@telerik.com>
|
Vladimir Enchev <vladimir.enchev@telerik.com>
|
||||||
Wei Zhang <sagamail@gmail.com>
|
Wei Zhang <sagamail@gmail.com>
|
||||||
Yavor Georgiev <yavor.georgiev@telerik.com>
|
Yavor Georgiev <yavor.georgiev@telerik.com>
|
||||||
|
@ -189,6 +189,9 @@ allTests["TAB-VIEW-NAVIGATION"] = tabViewNavigationTests;
|
|||||||
import * as imageTests from "./ui/image/image-tests";
|
import * as imageTests from "./ui/image/image-tests";
|
||||||
allTests["IMAGE"] = imageTests;
|
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";
|
import * as sliderTests from "./ui/slider/slider-tests";
|
||||||
allTests["SLIDER"] = sliderTests;
|
allTests["SLIDER"] = sliderTests;
|
||||||
|
|
||||||
|
@ -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 imageSource from "tns-core-modules/image-source";
|
||||||
import * as fs from "tns-core-modules/file-system";
|
import * as types from "tns-core-modules/utils/types";
|
||||||
// << image-cache-require
|
import * as TKUnit from "../../TKUnit";
|
||||||
|
|
||||||
export function test_DummyTestForSnippetOnly() {
|
export const test_ImageCache_ValidUrl = function() {
|
||||||
// >> image-cache-request-images
|
const cache = new imageCacheModule.Cache();
|
||||||
var cache = new imageCacheModule.Cache();
|
|
||||||
cache.placeholder = imageSource.fromFile(fs.path.join(__dirname, "res/no-image.png"));
|
|
||||||
cache.maxRequests = 5;
|
cache.maxRequests = 5;
|
||||||
|
|
||||||
// Enable download while not scrolling
|
let validKey: string;
|
||||||
cache.enableDownload();
|
|
||||||
|
let imgSource: imageSource.ImageSource;
|
||||||
var imgSouce: imageSource.ImageSource;
|
const url = "https://github.com/NativeScript.png";
|
||||||
var url = "https://github.com/NativeScript.png";
|
|
||||||
// Try to read the image from the cache
|
// Try to read the image from the cache
|
||||||
var image = cache.get(url);
|
const image = cache.get(url);
|
||||||
if (image) {
|
if (image) {
|
||||||
// If present -- use it.
|
// If present -- use it.
|
||||||
imgSouce = imageSource.fromNativeSource(image);
|
imgSource = imageSource.fromNativeSource(image);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If not present -- request its download.
|
// If not present -- request its download.
|
||||||
@ -28,13 +24,51 @@ export function test_DummyTestForSnippetOnly() {
|
|||||||
url: url,
|
url: url,
|
||||||
completed: (image: any, key: string) => {
|
completed: (image: any, key: string) => {
|
||||||
if (url === key) {
|
if (url === key) {
|
||||||
imgSouce = imageSource.fromNativeSource(image);
|
imgSource = imageSource.fromNativeSource(image);
|
||||||
|
validKey = key;
|
||||||
|
console.log("Valid url: ", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable download while scrolling
|
TKUnit.waitUntilReady(() => types.isDefined(validKey), 8);
|
||||||
cache.disableDownload();
|
TKUnit.assertEqual(validKey, url, "Key should equal the provided url");
|
||||||
// << image-cache-request-images
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,7 @@ export class Button extends ButtonBase {
|
|||||||
this._highlightedHandler = this._highlightedHandler || ((args: TouchGestureEventData) => {
|
this._highlightedHandler = this._highlightedHandler || ((args: TouchGestureEventData) => {
|
||||||
switch (args.action) {
|
switch (args.action) {
|
||||||
case TouchAction.up:
|
case TouchAction.up:
|
||||||
|
case TouchAction.cancel:
|
||||||
this._goToVisualState("normal");
|
this._goToVisualState("normal");
|
||||||
break;
|
break;
|
||||||
case TouchAction.down:
|
case TouchAction.down:
|
||||||
|
@ -72,7 +72,11 @@ export class Cache extends common.Cache {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
try {
|
try {
|
||||||
const image = UIImage.alloc().initWithData(response.content.raw);
|
const image = UIImage.alloc().initWithData(response.content.raw);
|
||||||
this._onDownloadCompleted(request.key, image);
|
if (image) {
|
||||||
|
this._onDownloadCompleted(request.key, image);
|
||||||
|
} else {
|
||||||
|
this._onDownloadError(request.key, new Error("No result for provided url"));
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._onDownloadError(request.key, err);
|
this._onDownloadError(request.key, err);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user