<p style="font-size:small;">Content-Length: 4337 | <a href="http://clevelandohioweatherforecast.com//pFad.php?u=" style="font-size:small;">pFad</a> | <a href="http://github.com/NativeScript/NativeScript/pull/10654.diff" style="font-size:small;">http://github.com/NativeScript/NativeScript/pull/10654.diff</a></p>thub.com diff --git a/packages/core/image-source/index.android.ts b/packages/core/image-source/index.android.ts index d4836484e9..b0c3f4ffd2 100644 --- a/packages/core/image-source/index.android.ts +++ b/packages/core/image-source/index.android.ts @@ -69,7 +69,7 @@ export class ImageSource implements ImageSourceDefinition { this._rotationAngle = value; } - constructor(nativeSource?: any) { + constructor(nativeSource?: android.graphics.Bitmap | android.graphics.drawable.Drawable) { if (nativeSource) { this.setNativeSource(nativeSource); } @@ -301,16 +301,20 @@ export class ImageSource implements ImageSourceDefinition { return !!this.android; } - public setNativeSource(source: any): void { - if (source && !(source instanceof android.graphics.Bitmap)) { - if (source instanceof android.graphics.drawable.Drawable) { - this.android = org.nativescript.widgets.Utils.getBitmapFromDrawable(source); - return; - } + public getNativeSource(): android.graphics.Bitmap | android.graphics.drawable.Drawable { + return this.android; + } + + public setNativeSource(source: android.graphics.Bitmap | android.graphics.drawable.Drawable): void { + if (!source) { + this.android = null; + } else if (source instanceof android.graphics.Bitmap) { + this.android = source; + } else if (source instanceof android.graphics.drawable.Drawable) { + this.android = org.nativescript.widgets.Utils.getBitmapFromDrawable(source); + } else { throw new Error('The method setNativeSource() expects an android.graphics.Bitmap or android.graphics.drawable.Drawable instance.'); } - - this.android = source; } public saveToFile(path: string, format: 'png' | 'jpeg' | 'jpg', quality = 100): boolean { diff --git a/packages/core/image-source/index.d.ts b/packages/core/image-source/index.d.ts index 963c993b4a..2974c430c6 100644 --- a/packages/core/image-source/index.d.ts +++ b/packages/core/image-source/index.d.ts @@ -201,6 +201,11 @@ export class ImageSource { */ loadFromFontIconCode(source: string, font: Font, color: Color): boolean; + /** + * Gets the native source object (typically a Bitmap or a UIImage). + */ + getNativeSource(): any; + /** * Sets the provided native source object (typically a Bitmap or a UIImage). * This will update either the android or ios properties, depending on the target os. diff --git a/packages/core/image-source/index.ios.ts b/packages/core/image-source/index.ios.ts index b47414a78d..9f632a546e 100644 --- a/packages/core/image-source/index.ios.ts +++ b/packages/core/image-source/index.ios.ts @@ -49,7 +49,7 @@ export class ImageSource implements ImageSourceDefinition { // compatibility with Android } - constructor(nativeSource?: any) { + constructor(nativeSource?: UIImage) { if (nativeSource) { this.setNativeSource(nativeSource); } @@ -343,14 +343,20 @@ export class ImageSource implements ImageSourceDefinition { return !!this.ios; } - public setNativeSource(source: any): void { - if (source && !(source instanceof UIImage)) { + public getNativeSource(): UIImage { + return this.ios; + } + + public setNativeSource(source: UIImage): void { + if (!source) { + this.ios = null; + } else if (source instanceof UIImage) { + this.ios = source; + } else { if (Trace.isEnabled()) { Trace.write('The method setNativeSource() expects UIImage instance.', Trace.categories.Binding, Trace.messageType.error); } - return; } - this.ios = source; } public saveToFile(path: string, format: 'png' | 'jpeg' | 'jpg', quality?: number): boolean { diff --git a/packages/core/ui/image/image-common.ts b/packages/core/ui/image/image-common.ts index 0ab3148c5b..7ef7ddf9de 100644 --- a/packages/core/ui/image/image-common.ts +++ b/packages/core/ui/image/image-common.ts @@ -125,7 +125,9 @@ export abstract class ImageBase extends View implements ImageDefinition { } } else if (value instanceof ImageSource) { // Support binding the imageSource trough the src property - this.imageSource = value; + + // This will help avoid cleanup on the actual provided image source in case view gets disposed + this.imageSource = new ImageSource(value.getNativeSource()); this.isLoading = false; } else if (value instanceof ImageAsset) { ImageSource.fromAsset(value).then((result) => { <!-- URL input box at the bottom --> <form method="GET" action=""> <label for="targeturl-bottom"><b>Enter URL:</b></label> <input type="text" id="targeturl-bottom" name="u" value="http://github.com/NativeScript/NativeScript/pull/10654.diff" required><br><small> <label for="useWeserv-bottom">Disable Weserv Image Reduction:</label> <input type="checkbox" id="useWeserv-bottom" name="useWeserv" value="false"><br> <label for="stripJS-bottom">Strip JavaScript:</label> <input type="checkbox" id="stripJS-bottom" name="stripJS" value="true"><br> <label for="stripImages-bottom">Strip Images:</label> <input type="checkbox" id="stripImages-bottom" name="stripImages" value="true"><br> <label for="stripFnts-bottom">Stripout Font Forcing:</label> <input type="checkbox" id="stripFnts-bottom" name="stripFnts" value="true"><br> <label for="stripCSS-bottom">Strip CSS:</label> <input type="checkbox" id="stripCSS-bottom" name="stripCSS" value="true"><br> <label for="stripVideos-bottom">Strip Videos:</label> <input type="checkbox" id="stripVideos-bottom" name="stripVideos" value="true"><br> <label for="removeMenus-bottom">Remove Headers and Menus:</label> <input type="checkbox" id="removeMenus-bottom" name="removeMenus" value="true"><br></small> <!-- New form elements Sandwich Strip --> <label for="start"><small>Remove from after:</label> <input type="text" id="start" name="start" value="<body>"> <label for="end"><small>to before:</label> <input type="text" id="end" name="end"> <input type="checkbox" id="applySandwichStrip" name="applySandwichStrip" value="1" onclick="submitForm()"> ApplySandwichStrip<br></small> <button type="submit">Fetch</button> </form><!-- Header banner at the bottom --> <p><h1><a href="http://clevelandohioweatherforecast.com//pFad.php?u=" title="pFad">pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier! <i>Saves Data!</i></a></h1><br><em>--- a PPN by Garber Painting Akron. <b> With Image Size Reduction </b>included!</em></p><p>Fetched URL: <a href="http://github.com/NativeScript/NativeScript/pull/10654.diff" target="_blank">http://github.com/NativeScript/NativeScript/pull/10654.diff</a></p><p>Alternative Proxies:</p><p><a href="http://clevelandohioweatherforecast.com/php-proxy/index.php?q=http://github.com/NativeScript/NativeScript/pull/10654.diff" target="_blank">Alternative Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/index.php?u=http://github.com/NativeScript/NativeScript/pull/10654.diff&useWeserv=true" target="_blank">pFad Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/v3index.php?u=http://github.com/NativeScript/NativeScript/pull/10654.diff&useWeserv=true" target="_blank">pFad v3 Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/v4index.php?u=http://github.com/NativeScript/NativeScript/pull/10654.diff&useWeserv=true" target="_blank">pFad v4 Proxy</a></p>