OneScript
UI

Overview

Arrange, layer, and scroll child views.

Import layout components from onescript/views to arrange, layer, and scroll child views.

ComponentPurpose
VStackArranges children vertically.
HStackArranges children horizontally.
ZStackLayers children on top of each other.
LazyVStackLazily lays out vertical content with pinned sections.
LazyHStackLazily lays out horizontal content with pinned sections.
ScrollViewScrolls content vertically, horizontally, or in both directions.
GridArranges children in a two-dimensional grid.
GridRowDefines a row of cells in a grid.
LazyVGrid / LazyHGridLazily lays out a grid described by GridItem values.
SectionOrganizes a header, body, and footer.
ListDisplays rows in a scrollable list.
FormGroups settings and controls in a scrollable form.

Every layout component also accepts Modifiers.

Profile layout example

import {
  Color, Font, FontWeight, HStack, Image, Modifier, Shape, Text, VStack,
} from "onescript/views"

const avatarURL = new URL(profile.avatar)

<HStack
  alignment="center"
  spacing={12}
  modifier={Modifier.padding(16)}
>
  <Image
    url={avatarURL}
    resizable
    modifier={Modifier
      .scaledToFill()
      .frame({ width: 64, height: 64 })
      .clipShape(Shape.circle)}
  />
  <VStack
    alignment="leading"
    spacing={4}
  >
    <Text modifier={Modifier
      .font(Font.headline)
      .fontWeight(FontWeight.bold)}>
      {profile.nickname}
    </Text>
    <Text modifier={Modifier.foregroundStyle(Color.secondary)}>@{profile.id}</Text>
    <HStack spacing={12}>
      <Text>{profile.followers} followers</Text>
      <Text>{profile.following} following</Text>
    </HStack>
  </VStack>
</HStack>

How is this guide?

Last updated on

On this page