From 4f79d2e2a13cd727b94eb1e334e73606125c9d44 Mon Sep 17 00:00:00 2001 From: Luke Curran Date: Tue, 7 May 2019 13:44:12 -0500 Subject: [PATCH 1/2] fix(iOS): Image cache module not longer sets null in NSCache (#7171) * Image cache module fix * Cla verified | use const instead of let * Image cache module fix * Cla verified | use const instead of let * Improve tests --- AUTHORS | 3 +- tests/app/testRunner.ts | 3 + tests/app/ui/image-cache/image-cache-tests.ts | 74 ++++++++++++++----- .../ui/image-cache/image-cache.ios.ts | 6 +- 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/AUTHORS b/AUTHORS index ab42c6100..80999269b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,6 +16,7 @@ John Bristowe Joe D Kamen Velikov Lubomir Blagoev +Luke Curran Matt Donovan Matthew Knight Mihail Slavchev @@ -37,4 +38,4 @@ Vasil Chimev Victor Nascimento Vladimir Enchev Wei Zhang -Yavor Georgiev \ No newline at end of file +Yavor Georgiev diff --git a/tests/app/testRunner.ts b/tests/app/testRunner.ts index aef985b13..7ca909f71 100644 --- a/tests/app/testRunner.ts +++ b/tests/app/testRunner.ts @@ -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; diff --git a/tests/app/ui/image-cache/image-cache-tests.ts b/tests/app/ui/image-cache/image-cache-tests.ts index c70fe9161..c6237b8ac 100644 --- a/tests/app/ui/image-cache/image-cache-tests.ts +++ b/tests/app/ui/image-cache/image-cache-tests.ts @@ -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(); - - var imgSouce: imageSource.ImageSource; - var url = "https://github.com/NativeScript.png"; + + let validKey: string; + + 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); } diff --git a/tns-core-modules/ui/image-cache/image-cache.ios.ts b/tns-core-modules/ui/image-cache/image-cache.ios.ts index f82391381..595cc0657 100644 --- a/tns-core-modules/ui/image-cache/image-cache.ios.ts +++ b/tns-core-modules/ui/image-cache/image-cache.ios.ts @@ -72,7 +72,11 @@ export class Cache extends common.Cache { .then((response) => { try { 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) { this._onDownloadError(request.key, err); } From 2a023609f5fc515589bd50d00c9fb9b9cd763083 Mon Sep 17 00:00:00 2001 From: Yurii Cherniavskyi Date: Wed, 8 May 2019 08:51:40 +0300 Subject: [PATCH 2/2] fix(android/button): possible incorrect button visual state (#7190) --- tns-core-modules/ui/button/button.android.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tns-core-modules/ui/button/button.android.ts b/tns-core-modules/ui/button/button.android.ts index ef9e8bbcc..66db08e2d 100644 --- a/tns-core-modules/ui/button/button.android.ts +++ b/tns-core-modules/ui/button/button.android.ts @@ -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: