widget
小组件 API。
widget 提供小组件的配置值和显示能力。
widget.inputValue
用户在小组件配置中填写的输入值。
在主 App 预览中,该值为 undefined。在真实小组件中,该值来自小组件配置。
import { widget } from "onescript"
const inputValue = widget.inputValuewidget.family
当前小组件尺寸。
| value | Family |
|---|---|
0 | small |
1 | medium |
2 | large |
3 | extraLarge |
widget.displaySize
当前小组件显示尺寸。
import { widget } from "onescript"
const { width, height } = widget.displaySizewidget.show(options)
显示小组件视图。
import { widget } from "onescript"
widget.show({
views: {
type: "text",
props: {
text: "Hello Widget"
}
}
})使用 widget.family 可以按尺寸返回不同视图。
import { widget } from "onescript"
const isSmall = widget.family === 0
widget.show({
views: {
type: "text",
props: {
text: isSmall ? "Small" : "Widget"
}
}
})支持字段:
| Field | Description |
|---|---|
views | 要显示的 Widget view node。 |
options.refresh | 下一次请求刷新的最早时间,仅支持 Date。 |
省略 options.refresh 时,OneScript 默认在约一小时后请求刷新。refresh 表示系统最早可以刷新小组件的时间,不保证准点执行。
刷新时机由系统统一调度,并不保证准时触发。refresh 仅表示最早可刷新时间,实际更新可能晚于该时刻。
import { widget } from "onescript"
const nextRefresh = new Date()
nextRefresh.setHours(8, 0, 0, 0)
if (nextRefresh <= new Date()) {
nextRefresh.setDate(nextRefresh.getDate() + 1)
}
widget.show({
views: {
type: "text",
props: {
text: "早上好"
}
},
options: {
refresh: nextRefresh
}
})How is this guide?
最后更新于