fix(core): improve strong type src of Image (#10265)

This commit is contained in:
Juan de Dios Martínez Vallejo
2023-04-11 07:59:57 +02:00
committed by GitHub
parent 2b64e179a5
commit f54966707d
4 changed files with 8 additions and 6 deletions

View File

@ -14,7 +14,7 @@ import { Trace } from '../../trace';
@CSSType('Image')
export abstract class ImageBase extends View implements ImageDefinition {
public imageSource: ImageSource;
public src: string | ImageSource;
public src: string | ImageSource | ImageAsset;
public isLoading: boolean;
public stretch: CoreTypes.ImageStretchType;
public loadMode: 'sync' | 'async';
@ -134,7 +134,7 @@ export const imageSourceProperty = new Property<ImageBase, ImageSource>({
});
imageSourceProperty.register(ImageBase);
export const srcProperty = new Property<ImageBase, any>({ name: 'src' });
export const srcProperty = new Property<ImageBase, string | ImageSource | ImageAsset>({ name: 'src' });
srcProperty.register(ImageBase);
export const loadModeProperty = new Property<ImageBase, 'sync' | 'async'>({

View File

@ -186,7 +186,7 @@ export class Image extends ImageBase {
[srcProperty.getDefault](): any {
return undefined;
}
[srcProperty.setNative](value: any) {
[srcProperty.setNative](value: string | ImageSource | ImageAsset) {
this._createImageSourceFromSrc(value);
}
}

View File

@ -1,6 +1,7 @@
import { View } from '../core/view';
import { Style } from '../styling/style';
import { ImageSource } from '../../image-source';
import { ImageAsset } from '../../image-asset';
import { Color } from '../../color';
import { Property, InheritedCssProperty } from '../core/properties';
import { CoreTypes } from '../../core-types';
@ -27,7 +28,7 @@ export class Image extends View {
/**
* Gets or sets the source of the Image. This can be either an URL string or a native image instance.
*/
src: any;
src: string | ImageSource | ImageAsset;
/**
* Gets a value indicating if the image is currently loading.
@ -66,7 +67,7 @@ export class Image extends View {
}
export const imageSourceProperty: Property<Image, ImageSource>;
export const srcProperty: Property<Image, any>;
export const srcProperty: Property<Image, string | ImageSource | ImageAsset>;
export const isLoadingProperty: Property<Image, string>;
export const loadMode: Property<Image, 'sync' | 'async'>;
export const stretchProperty: Property<Image, CoreTypes.ImageStretchType>;

View File

@ -1,5 +1,6 @@
import { ImageBase, stretchProperty, imageSourceProperty, tintColorProperty, srcProperty } from './image-common';
import { ImageSource } from '../../image-source';
import { ImageAsset } from '../../image-asset';
import { Color } from '../../color';
import { Trace } from '../../trace';
import { layout, queueGC } from '../../utils';
@ -190,7 +191,7 @@ export class Image extends ImageBase {
this._setNativeImage(value ? value.ios : null);
}
[srcProperty.setNative](value: any) {
[srcProperty.setNative](value: string | ImageSource | ImageAsset) {
this._createImageSourceFromSrc(value);
}
}