File tree Expand file tree Collapse file tree 3 files changed +16
-12
lines changed
tns-core-modules/image-source Expand file tree Collapse file tree 3 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -139,9 +139,11 @@ export class ImageSource implements ImageSourceDefinition {
139139 } ) ;
140140 }
141141
142- public setNativeSource ( source : any ) : boolean {
142+ public setNativeSource ( source : any ) : void {
143+ if ( source && ! ( source instanceof android . graphics . Bitmap ) ) {
144+ throw new Error ( "The method setNativeSource() expects android.graphics.Bitmap instance." ) ;
145+ }
143146 this . android = source ;
144- return source != null ;
145147 }
146148
147149 public saveToFile ( path : string , format : "png" | "jpeg" | "jpg" , quality = 100 ) : boolean {
@@ -239,8 +241,9 @@ export function fromBase64(source: string): ImageSource {
239241}
240242
241243export function fromNativeSource ( source : any ) : ImageSource {
242- const image = new ImageSource ( ) ;
243- return image . setNativeSource ( source ) ? image : null ;
244+ const imageSource = new ImageSource ( ) ;
245+ imageSource . setNativeSource ( source ) ;
246+ return imageSource ;
244247}
245248
246249export function fromUrl ( url : string ) : Promise < ImageSourceDefinition > {
Original file line number Diff line number Diff line change @@ -88,11 +88,11 @@ export class ImageSource {
8888 fromBase64 ( source : string ) : Promise < boolean > ;
8989
9090 /**
91- * Sets the provided native source object (typically a Bitmap).
91+ * Sets the provided native source object (typically a Bitmap or a UIImage ).
9292 * This will update either the android or ios properties, depending on the target os.
9393 * @param source The native image object. Will be either a Bitmap for Android or a UIImage for iOS.
9494 */
95- setNativeSource ( source : any ) : boolean ;
95+ setNativeSource ( source : any ) : void ;
9696
9797 /**
9898 * Saves this instance to the specified file, using the provided image format and quality.
Original file line number Diff line number Diff line change @@ -118,11 +118,11 @@ export class ImageSource implements ImageSourceDefinition {
118118 } ) ;
119119 }
120120
121- public setNativeSource ( source : any ) : boolean {
122- if ( source instanceof UIImage ) {
123- this . ios = source ;
121+ public setNativeSource ( source : any ) : void {
122+ if ( source && ! ( source instanceof UIImage ) ) {
123+ throw new Error ( "The method setNativeSource() expects UIImage instance." ) ;
124124 }
125- return source != null ;
125+ this . ios = source ;
126126 }
127127
128128 public saveToFile ( path : string , format : "png" | "jpeg" | "jpg" , quality ?: number ) : boolean {
@@ -221,8 +221,9 @@ export function fromBase64(source: string): ImageSource {
221221}
222222
223223export function fromNativeSource ( source : any ) : ImageSource {
224- const image = new ImageSource ( ) ;
225- return image . setNativeSource ( source ) ? image : null ;
224+ const imageSource = new ImageSource ( ) ;
225+ imageSource . setNativeSource ( source ) ;
226+ return imageSource ;
226227}
227228
228229export function fromUrl ( url : string ) : Promise < ImageSource > {
You can’t perform that action at this time.
0 commit comments