File tree 3 files changed +16
-12
lines changed
tns-core-modules/image-source 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 {
139
139
} ) ;
140
140
}
141
141
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
+ }
143
146
this . android = source ;
144
- return source != null ;
145
147
}
146
148
147
149
public saveToFile ( path : string , format : "png" | "jpeg" | "jpg" , quality = 100 ) : boolean {
@@ -239,8 +241,9 @@ export function fromBase64(source: string): ImageSource {
239
241
}
240
242
241
243
export 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 ;
244
247
}
245
248
246
249
export function fromUrl ( url : string ) : Promise < ImageSourceDefinition > {
Original file line number Diff line number Diff line change @@ -88,11 +88,11 @@ export class ImageSource {
88
88
fromBase64 ( source : string ) : Promise < boolean > ;
89
89
90
90
/**
91
- * Sets the provided native source object (typically a Bitmap).
91
+ * Sets the provided native source object (typically a Bitmap or a UIImage ).
92
92
* This will update either the android or ios properties, depending on the target os.
93
93
* @param source The native image object. Will be either a Bitmap for Android or a UIImage for iOS.
94
94
*/
95
- setNativeSource ( source : any ) : boolean ;
95
+ setNativeSource ( source : any ) : void ;
96
96
97
97
/**
98
98
* 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 {
118
118
} ) ;
119
119
}
120
120
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." ) ;
124
124
}
125
- return source != null ;
125
+ this . ios = source ;
126
126
}
127
127
128
128
public saveToFile ( path : string , format : "png" | "jpeg" | "jpg" , quality ?: number ) : boolean {
@@ -221,8 +221,9 @@ export function fromBase64(source: string): ImageSource {
221
221
}
222
222
223
223
export 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 ;
226
227
}
227
228
228
229
export function fromUrl ( url : string ) : Promise < ImageSource > {
You can’t perform that action at this time.
0 commit comments