OneScript

LazyHStack

Lazily lay out horizontally arranged child views.

LazyHStack uses SwiftUI's native lazy container to lay out content horizontally. It works well inside a horizontal ScrollView that displays long content.

OneScript currently resolves the complete TypeScript/TSX child-node tree before committing the view. SwiftUI creates the corresponding views on demand during layout and display.

import {
  LazyHStack, PinnedScrollableViews, ScrollView, Section, Text,
} from "onescript/views"

<ScrollView axes="horizontal">
  <LazyHStack
    alignment="top"
    spacing={12}
    pinnedViews={[PinnedScrollableViews.sectionHeaders]}
  >
    <Section header={<Text>Featured</Text>}>
      <Text>Project A</Text>
      <Text>Project B</Text>
    </Section>
    <Section header={<Text>Recent</Text>}>
      <Text>Project C</Text>
    </Section>
  </LazyHStack>
</ScrollView>
PropTypeDescription
alignment"top" | "center" | "bottom"Vertical child alignment. Defaults to "center".
spacingnumberSpace between children in pt. Uses the system spacing when omitted.
pinnedViewsPinnedScrollableView[]Section headers or footers that remain pinned while scrolling.
childrenview or view arrayChild views displayed from left to right.

PinnedScrollableViews.sectionHeaders pins headers and PinnedScrollableViews.sectionFooters pins footers. Pinning takes effect inside a horizontal ScrollView.

How is this guide?

Last updated on