FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor(image-source): fromNativeSource and setNativeSource methods · NativeScript/NativeScript@17d04e8 · GitHub

Commit 17d04e8

Browse files
committed
refactor(image-source): fromNativeSource and setNativeSource methods
1 parent 823bf7b commit 17d04e8

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎tns-core-modules/image-source/image-source.android.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,11 @@ export class ImageSource implements ImageSourceDefinition {
139139
});
140140
}
141141

142-
public setNativeSource(source: any): boolean {
143-
if (!(source instanceof android.graphics.Bitmap)) {
142+
public setNativeSource(source: any): void {
143+
if (source && !(source instanceof android.graphics.Bitmap)) {
144144
throw new Error("The method setNativeSource() expects android.graphics.Bitmap instance.");
145145
}
146146
this.android = source;
147-
return source != null;
148147
}
149148

150149
public saveToFile(path: string, format: "png" | "jpeg" | "jpg", quality = 100): boolean {
@@ -242,8 +241,9 @@ export function fromBase64(source: string): ImageSource {
242241
}
243242

244243
export function fromNativeSource(source: any): ImageSource {
245-
const image = new ImageSource();
246-
return image.setNativeSource(source) ? image : null;
244+
const imageSource = new ImageSource();
245+
imageSource.setNativeSource(source);
246+
return imageSource;
247247
}
248248

249249
export function fromUrl(url: string): Promise<ImageSourceDefinition> {

‎tns-core-modules/image-source/image-source.ios.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ export class ImageSource implements ImageSourceDefinition {
118118
});
119119
}
120120

121-
public setNativeSource(source: any): boolean {
122-
if (!(source instanceof UIImage)) {
121+
public setNativeSource(source: any): void {
122+
if (source && !(source instanceof UIImage)) {
123123
throw new Error("The method setNativeSource() expects UIImage instance.");
124124
}
125125
this.ios = source;
126-
return source != null;
127126
}
128127

129128
public saveToFile(path: string, format: "png" | "jpeg" | "jpg", quality?: number): boolean {
@@ -222,8 +221,9 @@ export function fromBase64(source: string): ImageSource {
222221
}
223222

224223
export function fromNativeSource(source: any): ImageSource {
225-
const image = new ImageSource();
226-
return image.setNativeSource(source) ? image : null;
224+
const imageSource = new ImageSource();
225+
imageSource.setNativeSource(source);
226+
return imageSource;
227227
}
228228

229229
export function fromUrl(url: string): Promise<ImageSource> {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL