mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 22:00:17 +08:00
fix(core): improve strong type src of Image (#10265)
This commit is contained in:

committed by
GitHub

parent
2b64e179a5
commit
f54966707d
@ -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'>({
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
5
packages/core/ui/image/index.d.ts
vendored
5
packages/core/ui/image/index.d.ts
vendored
@ -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>;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user