OneScript Docs

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.inputValue

widget.family

The current widget family.

valueFamily
0small
1medium
2large
3extraLarge

widget.displaySize

The current widget display size.

import { widget } from "onescript"

const { width, height } = widget.displaySize

widget.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:

FieldDescription
viewsThe Widget view node to display.
options.refreshThe 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

On this page