Skip to content

Commit 01f930c

Browse files
committed
feat: allow src to be a promise
1 parent 9cb2c1c commit 01f930c

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/image.android.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,13 @@ export class Img extends ImageBase {
487487
// this.initImage();
488488
// }
489489

490-
private initImage() {
490+
private async initImage() {
491491
if (this.nativeViewProtected) {
492492
// this.nativeViewProtected.setImageURI(null);
493-
const src = this.src;
493+
let src = this.src;
494+
if (src instanceof Promise) {
495+
src = await src;
496+
}
494497
if (src) {
495498
let drawable: android.graphics.drawable.BitmapDrawable;
496499
if (src instanceof ImageSource) {

src/image.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageSource, View } from '@nativescript/core';
1+
import { ImageAsset, ImageSource, View } from '@nativescript/core';
22

33

44
/**
@@ -75,7 +75,7 @@ export class Img extends View {
7575
/**
7676
* String value used for the image URI.
7777
*/
78-
src: string | ImageSource;
78+
src: string | ImageSource | ImageAsset | Promise<string | ImageSource | ImageAsset> ;
7979

8080
/**
8181
* String value used for the lower res image URI.

src/image.ios.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,12 @@ export class Img extends ImageBase {
357357
return image;
358358
}
359359

360-
private initImage() {
360+
private async initImage() {
361361
if (this.nativeViewProtected) {
362-
const src = this.src;
362+
let src = this.src;
363+
if (src instanceof Promise) {
364+
src = await src;
365+
}
363366
if (src) {
364367
const animate = this.fadeDuration > 0;
365368
if (src instanceof ImageSource) {

0 commit comments

Comments
 (0)