Skip to content

WidgetStack

Stack element shown in widget.

Shows a stack in the widget.

Background color of the widget.

backgroundColor: Color

Background gradient.

backgroundGradient: LinearGradient

Background image.

backgroundImage: Image

Border color.

borderColor: Color

Color of the border around the stack. Defaults to black.

Border width.

borderWidth: number

Width of the border around the stack. Defaults to 0.

Radius of the corners.

cornerRadius: number

Radius of the rounded corners. Defaults to 0.

Size of the stack.

size: Size

Specifies the size of the stack when shown in a widget. When a dimension is set to zero or less, the widget will automatically decide a length for that dimension. Both dimensions default to 0.

Spacing between elements.

spacing: number

Specifies the spacing between elements in the stack. You can also use the addSpacer() function on the widget to add spacing between elements. Defaults to 0.

URL to open.

url: string

The URL will be opened when the text is tapped. This is only supported in medium and large widgets. Small widgets can only have a single tap target, which is specified by the url on the widget.

Add date to the widget.

addDate(date: Date): WidgetDate

Adds a date element to the widget. Use the properties on the returned element to style the date.

date Date

WidgetDate

Date element.

Add image to the stack.

addImage(image: Image): WidgetImage

Adds an image element to the stack. Use the properties on the returned element to style the image.

image Image

WidgetImage

Image element.

Add spacer.

addSpacer(length: number): WidgetSpacer

Adds a spacer to the stack. This can be used to offset the content horizontally in the stack.

length number

Length of the spacer. Pass null to create a spacer with a flexible length.

WidgetSpacer

Spacer element.

Add stack.

addStack(): WidgetStack

Adds a stack to the widget. Stacks layout elements horizontally by default.

WidgetStack

Stack element.

Add a progress indicator to the widget.

addProgress(value: number, options: dictionary?): WidgetStack

Adds a progress indicator with a value from 0 to 100. Values outside that range are clamped. Use the returned stack to size the indicator or add content centered on top of it.

value number

Progress from 0 to 100.

options dictionary?

Optional dictionary with style (“circular” or “linear”), progressColor, trackColor, and thickness in points. The default style is circular. Thickness sets the ring stroke or the initial height of a linear bar.

WidgetStack

A stack sized to 40 by 40 points for a ring or 120 points wide for a bar.

Add a button that runs a widget action.

addButton(title: string, options: {[key: string]: string})

Tapping the button runs the configured script in the widget and reloads the widget. Read args.widgetAction.id to handle the action. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.

title string

The label shown on the control.

options {[key: string]: string}

A dictionary with a non-empty string id.

Add a button that refreshes the widget.

addRefreshButton(title: string)

Tapping the button reloads the widget and runs its normal render. The render receives no widget action. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.

title string

The label shown on the control.

Add a toggle that runs a widget action.

addToggle(title: string, isOn: boolean, options: {[key: string]: string})

Read args.widgetAction.isOn to get the requested state. Save the state before the script finishes and read it when rendering the widget again. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.

title string

The label shown on the control.

isOn boolean

The current saved state of the toggle.

options {[key: string]: string}

A dictionary with a non-empty string id.

Run a widget action when the stack is tapped.

setAction(title: string?, options: dictionary?)

Uses the stack contents as the action’s appearance on iOS or iPadOS 17 or later. Controls inside the stack take precedence over a stack action.

title string?

Accessibility label, or null to clear the action.

options dictionary?

A dictionary with a non-empty string id.

Add text to the stack.

addText(text: string): WidgetText

Adds a text element to the stack. Use the properties on the returned element to style the text.

text string

WidgetText

Text element.

Bottom aligns the content.

bottomAlignContent()

Specifies that content should be bottom aligned.

Center aligns the content.

centerAlignContent()

Specifies that content should be center aligned.

Layout elements horizontally.

layoutHorizontally()

Specifies that the stack should layout elements horizontally. This is the default.

Layout elements vertically.

layoutVertically()

Specifies that the stack should layout elements vertically.

setPadding(top, leading, bottom, trailing)

Section titled “setPadding(top, leading, bottom, trailing)”

Set padding.

setPadding(top: number, leading: number, bottom: number, trailing: number)

Sets the padding on each side of the stack.

top number

Padding on the top edge.

leading number

Padding on the leading edge.

bottom number

Padding on the bottom edge.

trailing number

Padding on the trailing edge.

Top aligns the content.

topAlignContent()

Specifies that content should be top aligned. This is the default.

Use the default padding.

useDefaultPadding()

Configure the stack to use the default padding. Any padding previously defined with setPadding() will be discarded.