widget
Widget APIs.
widget provides the widget configuration value and display API used by widgets.
widget.inputValue
The input value configured by the user for the widget.
In the main app preview, this value is undefined. In a real widget, it comes from the widget configuration.
import { widget } from "onescript"
const inputValue = widget.inputValuewidget.family
The current widget family.
| value | Family |
|---|---|
0 | small |
1 | medium |
2 | large |
3 | extraLarge |
widget.displaySize
The current widget display size.
import { widget } from "onescript"
const { width, height } = widget.displaySizewidget.show(options)
Displays a widget view.
import { widget } from "onescript"
widget.show({
views: {
type: "text",
props: {
text: "Hello Widget"
}
}
})Use widget.family to choose a different view for different widget sizes.
import { widget } from "onescript"
const isSmall = widget.family === 0
widget.show({
views: {
type: "text",
props: {
text: isSmall ? "Small" : "Widget"
}
}
})Supported fields:
| Field | Description |
|---|---|
views | The Widget view node to display. |
options.refresh | The earliest time to request the next refresh. Only Date is supported. |
When options.refresh is omitted, OneScript requests a refresh about one hour later by default. refresh is the earliest time the system may refresh the widget. It does not guarantee exact execution at that time.
Refresh timing is scheduled by the system and is not guaranteed to occur on time. refresh only sets the earliest time a refresh may happen; the widget may update later than that.
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: "Good morning"
}
},
options: {
refresh: nextRefresh
}
})How is this guide?
Last updated on