harmony 鸿蒙Version Compatibility Adaptation

  • 2022-12-13
  • 浏览 (587)

Version Compatibility Adaptation

As you incorporate new features into service widgets of your applications, take measures to avoid abnormal display of these features on earlier versions. You can specify the minimum SDK version in the service widget project so that service widgets incorporating new features will not be installed on incompatible systems. You can also follow the instructions in this section to implement forward compatibility during your service widget development.

Configure forward compatibility in the JSON configuration file. Specifically, set the apiVersion attribute, which is at the same level as the data and actions fields in the service widget configuration file. The content defined in apiVersion overwrites the original content in data based on the current version information.

Example:

Assume that the JS service widget framework supports WebP image sources since API version 9. Then you can implement forward compatibility as follows:

<!-- xxx.hml -->
<div>
    <image src="{{imageSrc}}" style="width: 100px;height: 100px;"></image>
</div>

JSON configuration file:

{
  "data": {
    "imageSrc": "defaultSrc.png"
  },
  "apiVersion": {
    "9": {
      "imageSrc": "newSrc.webp"
    }
  }
}

The JS service widget development framework selects the most appropriate data based on the application configuration and the current API version.

If the API version is 8 or earlier, the value of imageSrc is defaultSrc.png.

If the API version is 9, the value of imageSrc is newSrc.webp.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙JS Service Widget UI Components

harmony 鸿蒙Data Types

harmony 鸿蒙button

harmony 鸿蒙calendar

harmony 鸿蒙chart

harmony 鸿蒙clock

harmony 鸿蒙divider

harmony 鸿蒙image

harmony 鸿蒙input

harmony 鸿蒙progress

0  赞