| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,7 +69,7 @@ export class ImageSource implements ImageSourceDefinition { | |||
| 69 | 69 | this._rotationAngle = value; | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | - constructor(nativeSource?: any) { | ||
| 72 | + constructor(nativeSource?: android.graphics.Bitmap | android.graphics.drawable.Drawable) { | ||
| 73 | 73 | if (nativeSource) { | |
| 74 | 74 | this.setNativeSource(nativeSource); | |
| 75 | 75 | } | |
@@ -301,16 +301,20 @@ export class ImageSource implements ImageSourceDefinition { | |||
| 301 | 301 | return !!this.android; | |
| 302 | 302 | } | |
| 303 | 303 | ||
| 304 | - public setNativeSource(source: any): void { | ||
| 305 | - if (source && !(source instanceof android.graphics.Bitmap)) { | ||
| 306 | - if (source instanceof android.graphics.drawable.Drawable) { | ||
| 307 | - this.android = org.nativescript.widgets.Utils.getBitmapFromDrawable(source); | ||
| 308 | - return; | ||
| 309 | - } | ||
| 304 | + public getNativeSource(): android.graphics.Bitmap | android.graphics.drawable.Drawable { | ||
| 305 | + return this.android; | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + public setNativeSource(source: android.graphics.Bitmap | android.graphics.drawable.Drawable): void { | ||
| 309 | + if (!source) { | ||
| 310 | + this.android = null; | ||
| 311 | + } else if (source instanceof android.graphics.Bitmap) { | ||
| 312 | + this.android = source; | ||
| 313 | + } else if (source instanceof android.graphics.drawable.Drawable) { | ||
| 314 | + this.android = org.nativescript.widgets.Utils.getBitmapFromDrawable(source); | ||
| 315 | + } else { | ||
| 310 | 316 | throw new Error('The method setNativeSource() expects an android.graphics.Bitmap or android.graphics.drawable.Drawable instance.'); | |
| 311 | 317 | } | |
| 312 | - | ||
| 313 | - this.android = source; | ||
| 314 | 318 | } | |
| 315 | 319 | ||
| 316 | 320 | public saveToFile(path: string, format: 'png' | 'jpeg' | 'jpg', quality = 100): boolean { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,6 +201,11 @@ export class ImageSource { | |||
| 201 | 201 | */ | |
| 202 | 202 | loadFromFontIconCode(source: string, font: Font, color: Color): boolean; | |
| 203 | 203 | ||
| 204 | + /** | ||
| 205 | + * Gets the native source object (typically a Bitmap or a UIImage). | ||
| 206 | + */ | ||
| 207 | + getNativeSource(): any; | ||
| 208 | + | ||
| 204 | 209 | /** | |
| 205 | 210 | * Sets the provided native source object (typically a Bitmap or a UIImage). | |
| 206 | 211 | * This will update either the android or ios properties, depending on the target os. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,7 +49,7 @@ export class ImageSource implements ImageSourceDefinition { | |||
| 49 | 49 | // compatibility with Android | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | - constructor(nativeSource?: any) { | ||
| 52 | + constructor(nativeSource?: UIImage) { | ||
| 53 | 53 | if (nativeSource) { | |
| 54 | 54 | this.setNativeSource(nativeSource); | |
| 55 | 55 | } | |
@@ -343,14 +343,20 @@ export class ImageSource implements ImageSourceDefinition { | |||
| 343 | 343 | return !!this.ios; | |
| 344 | 344 | } | |
| 345 | 345 | ||
| 346 | - public setNativeSource(source: any): void { | ||
| 347 | - if (source && !(source instanceof UIImage)) { | ||
| 346 | + public getNativeSource(): UIImage { | ||
| 347 | + return this.ios; | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + public setNativeSource(source: UIImage): void { | ||
| 351 | + if (!source) { | ||
| 352 | + this.ios = null; | ||
| 353 | + } else if (source instanceof UIImage) { | ||
| 354 | + this.ios = source; | ||
| 355 | + } else { | ||
| 348 | 356 | if (Trace.isEnabled()) { | |
| 349 | 357 | Trace.write('The method setNativeSource() expects UIImage instance.', Trace.categories.Binding, Trace.messageType.error); | |
| 350 | 358 | } | |
| 351 | - return; | ||
| 352 | 359 | } | |
| 353 | - this.ios = source; | ||
| 354 | 360 | } | |
| 355 | 361 | ||
| 356 | 362 | public saveToFile(path: string, format: 'png' | 'jpeg' | 'jpg', quality?: number): boolean { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,7 +125,9 @@ export abstract class ImageBase extends View implements ImageDefinition { | |||
| 125 | 125 | } | |
| 126 | 126 | } else if (value instanceof ImageSource) { | |
| 127 | 127 | // Support binding the imageSource trough the src property | |
| 128 | - this.imageSource = value; | ||
| 128 | + | ||
| 129 | + // This will help avoid cleanup on the actual provided image source in case view gets disposed | ||
| 130 | + this.imageSource = new ImageSource(value.getNativeSource()); | ||
| 129 | 131 | this.isLoading = false; | |
| 130 | 132 | } else if (value instanceof ImageAsset) { | |
| 131 | 133 | ImageSource.fromAsset(value).then((result) => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments