OneScript

confirmationDialog

Show a set of actions to choose from.

confirmationDialog(options) shows a system action list that slides up from the bottom on iPhone. Tapping a button runs its action first, then calls onDismiss.

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

function ShareButton() {
  const [shown, setShown] = useState(false)

  return (
    <Button
      action={() => setShown(true)}
      modifier={Modifier.confirmationDialog({
        title: "Share via",
        titleVisibility: "visible",
        isPresented: shown,
        onDismiss: () => setShown(false),
        actions: [
          <Button action={() => share("messages")}>Messages</Button>,
          <Button action={() => share("mail")}>Mail</Button>,
          <Button
            role="cancel"
            action={() => {}}
          >
            Cancel
          </Button>,
        ],
      })}
    >
      Share
    </Button>
  )
}
OptionTypeDescription
titlestringThe title.
titleVisibility"automatic" | "visible" | "hidden"Optional. Whether the title is shown. Defaults to "automatic".
messagestringOptional. Text below the title.
isPresentedbooleanWhether the dialog is shown.
onDismiss() => voidCalled when the dialog closes; set isPresented to false here.
actionsViewChildThe action buttons.

actions only accepts Button with a plain text label, and the buttons can't have a modifier.

How is this guide?

Last updated on