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

View File

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

View File

@ -1,6 +1,7 @@
import { View } from '../core/view'; import { View } from '../core/view';
import { Style } from '../styling/style'; import { Style } from '../styling/style';
import { ImageSource } from '../../image-source'; import { ImageSource } from '../../image-source';
import { ImageAsset } from '../../image-asset';
import { Color } from '../../color'; import { Color } from '../../color';
import { Property, InheritedCssProperty } from '../core/properties'; import { Property, InheritedCssProperty } from '../core/properties';
import { CoreTypes } from '../../core-types'; 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. * 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. * 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 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 isLoadingProperty: Property<Image, string>;
export const loadMode: Property<Image, 'sync' | 'async'>; export const loadMode: Property<Image, 'sync' | 'async'>;
export const stretchProperty: Property<Image, CoreTypes.ImageStretchType>; export const stretchProperty: Property<Image, CoreTypes.ImageStretchType>;

View File

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