OneScript

Button

Run an action from an App view.

Button renders a native SwiftUI button with an arbitrary OneScript view label. Its function action runs in an App view session.

import { Button, Text, useState } from "onescript/views"

function CounterButton() {
  const [count, setCount] = useState(0)

  return (
    <Button action={() => setCount(value => value + 1)}>
      <Text>Count: {count}</Text>
    </Button>
  )
}
PropTypeDescription
action() => void | Promise<void>Callback executed by an interactive App view.
role"cancel" | "destructive"Optional native SwiftUI button role.
childrenViewChildButton label.

In a Widget and the App Widget preview, the native Button is displayed in a disabled state. Tapping it does not execute the action.

Also accepts Modifiers, including buttonStyle, controlSize, and disabled.

How is this guide?

Last updated on