Lynx

Used to display images

Attributes

auto-size

Android
iOS
Clay
Harmony

2.6

// @defaultValue: false
'auto-size'?: boolean;

When set to true and the <image> element has no width or height, the size of the <image> will be automatically adjusted to match the image's original dimensions after the image is successfully loaded, ensuring that the aspect ratio is maintained.

autoplay

Android
iOS
Clay
Harmony

2.11

// @defaultValue: true
autoplay?: boolean;

Specifies whether the animated image should start playing automatically once it is loaded.

blur-radius

Android
iOS
Clay
Harmony

0.2

'blur-radius'?: string;

Image blur radius

cap-insets

Android
iOS
Clay
Harmony

1.4

'cap-insets'?: string;

Stretchable area for 9patch images, in percentage or decimal, four values for top, right, bottom, left

Note

Using cap-insets does not require the original image to be a 9-patch image.

cap-insets-scale

Android
iOS
Clay
Harmony

1.4

// @defaultValue: 1
'cap-insets-scale'?: number;

Adjust the scale of stretchable area for 9patch images

defer-src-invalidation

Android
iOS
Clay
Harmony

2.7

// @defaultValue: false
'defer-src-invalidation'?: boolean;

When set to true, the <image> will only clear the previously displayed image resource after a new image has successfully loaded. The default behavior is to clear the image resource before starting a new load. This can resolve flickering issues when the image src is switched and reloaded. It is not recommended to enable this in scenarios where there is node reuse in views like lists.

image-config

Android
Clay
1.4
// @defaultValue: "ARGB_8888"
'image-config'?: 'ARGB_8888' | 'RGB_565';

ARGB_8888 : 32-bit memory per pixel, supports semi-transparent images.

RGB_565 : 16-bit memory per pixel, reduces memory usage but loses transparency.

Support PC platform since 3.5

Note

Affects the actual memory usage of the image bitmap.

Taking an image with a resolution of 1024*768 as an example, the actual memory usage is (1024 * 768 * bits per pixel / 8) Bytes.

The default is ARGB_8888. Frontend developers can optimize image memory usage by setting it to RGB_565.

ARGB_8888 : Each pixel occupies 32 bits of memory and includes an alpha channel.

RGB_565 : Each pixel occupies 16 bits of memory, which reduces memory usage but results in the loss of transparency.

Setting RGB_565 may affect the display of <image> 's border-radius. You can set border-radius on the parent view of the <image> and add the clip-radius attribute to the parent view.

It is not recommended to use RGB_565 when mode="aspectFit", as it may cause black borders in the cropped area.

loop-count

Android
iOS
Clay
Harmony

1.4

// @defaultValue: 0
'loop-count'?: number;

Number of times an animated image plays, 0 stands for infinite

mode

Android
iOS
Clay
Harmony

0.2

// @defaultValue: 'scaleToFill'
mode?: 'scaleToFill' | 'aspectFit' | 'aspectFill' | 'center';

Specifies image cropping/scaling mode

scaleToFill : Scales the image without preserving the aspect ratio, stretching the image to fill the element.

aspectFit : Scales the image while preserving aspect ratio so that the long side is fully visible.

aspectFill : Scales the image while preserving aspect ratio, ensuring the short side fills the element.

center : Does not scale the image; image is centered.

placeholder

Android
iOS
Clay
Harmony

1.4

placeholder?: string;

Placeholder image, used same as src

prefetch-height

Android
iOS
1.4
// @defaultValue: "0px"
'prefetch-height'?: string;

Image won't load if its size is 0, but will load if prefetch-height is set

prefetch-width

Android
iOS
1.4
// @defaultValue: "0px"
'prefetch-width'?: string;

Image won't load if its size is 0, but will load if prefetch-width is set

src

Android
iOS
Clay
Harmony

0.2

// @defaultValue: undefined
src?: string;

Supports http/https/base64

tint-color

Android
iOS
Clay
Harmony

2.12

'tint-color'?: string;

Changes the color of all non-transparent pixels to the tint-color specified. The value is a <color> .

Events

Frontend can bind corresponding event callbacks to listen for runtime behaviors of the element, as shown below.

bindcurrentloopcomplete

Android
iOS
Harmony
3.7
bindcurrentloopcomplete = (e: BaseEvent) => {};

Triggered when one loop of the animated image finishes playing.

binderror

Android
iOS
Clay
Harmony

0.2

binderror = (e: ErrorEvent) => {};

Image load error event

bindfinalloopcomplete

Android
iOS
Harmony
3.7
bindfinalloopcomplete = (e: BaseEvent) => {};

Triggered when the animated image finishes playing all loop-count loops. If loop-count is not set, this callback will not be triggered.

bindload

Android
iOS
Clay
Harmony

0.2

bindload = (e: LoadEvent) => {};

Image load success event

bindstartplay

Android
iOS
Harmony
3.7
bindstartplay = (e: BaseEvent) => {};

Triggered when the animated image starts playing.

Methods

Frontend can invoke component methods via the SelectorQuery API.

pauseAnimation

Android
iOS
Clay
Harmony

2.11


lynx.createSelectorQuery()
.select('#id')
.invoke({
method: 'pauseAnimation',
success: function (res) {},
fail: function (res) {},
})
.exec();

Pauses the animation, without resetting the loop-count.

resumeAnimation

Android
iOS
Clay
Harmony
2.11

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'resumeAnimation',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

Resumes the animation, without resetting the loop-count.

startAnimate

Android
iOS
Clay
Harmony
Deprecated

lynx.createSelectorQuery()
.select('#id')
.invoke({
method: 'startAnimate',
success: function (res) {},
fail: function (res) {},
})
.exec();

Restart the animation playback method controlled by the front end, and the animation playback progress and loop count will be reset.

stopAnimation

Android
iOS
Clay
Harmony
2.11

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'stopAnimation',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

Stops the animation, and it will reset the loop-count.

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.