OneScript
UI

Overview

Navigation stacks, tab bars, toolbars, and navigation titles.

Navigation APIs are imported from onescript/views and are available in App and Action views. Widgets do not support them.

APIPurpose
NavigationStackPush and pop pages driven by a path.
NavigationLinkPush a value onto the enclosing stack.
TabViewSwitch between pages with a bottom tab bar.
toolbarAdd ToolbarItem, ToolbarItemGroup, and ToolbarSpacer to the navigation bar or bottom bar.
navigationTitleModifiers that set the page title and title display mode.

app.show() always presents views inside a navigation bar. The Close and Console buttons stay on the root page. If the root view is not a NavigationStack or TabView, OneScript wraps it in a stack that shows the project name as the title.

import { app } from "onescript"
import {
  Button, Modifier, NavigationLink, NavigationStack, Symbol, Text, ToolbarItem, VStack,
} from "onescript/views"

await app.show(
  <NavigationStack destination={(id: string) => <Text>Item {id}</Text>}>
    <VStack
      spacing={12}
      modifier={Modifier
        .navigationTitle("Inbox")
        .toolbar(
          <ToolbarItem placement="topBarTrailing">
            <Button action={() => console.log("compose")}>
              <Symbol name="square.and.pencil" />
            </Button>
          </ToolbarItem>
        )}
    >
      <NavigationLink value="1">Open item 1</NavigationLink>
      <NavigationLink value="2">Open item 2</NavigationLink>
    </VStack>
  </NavigationStack>
)

How is this guide?

Last updated on