LazyVStack

A view that arranges its children in a line that grows vertically, creating items only as needed.

ComponentiOS 14.0+macOS 11.0+tvOS 14.0+watchOS 7.0+LazyVStack in SwiftUI

Declaration

React
import { LazyVStack } from 'swiftui-react-native';
Swift
nonisolated struct LazyVStack<Content> where Content : View

Initializers

One SwiftUI initializer backs <LazyVStack>.

React
<LazyVStack
  alignment?: SwiftUI.HorizontalAlignment
  spacing?: number | null
  pinnedViews?: SwiftUI.PinnedScrollableViews
>
  children?: ReactNode
</LazyVStack>
Swift
nonisolated init(
    alignment: HorizontalAlignment = .center,
    spacing: CGFloat? = nil,
    pinnedViews: PinnedScrollableViews = .init(),
    @ContentBuilder content: () -> Content
)
  • The guide for aligning the subviews in this stack. All child views have the same horizontal screen coordinate.

    Default `.center`

  • spacingnumber | null

    The distance between adjacent subviews, or nil if you want the stack to choose a default distance for each pair of subviews.

    Default `nil`

  • The kinds of child views that will be pinned.

    Default `.init()`

  • childrenReactNode

    Content. Strings become Text; React Native views are laid out by Yoga and placed by SwiftUI.

    Swift content: () -> Content

Also takes the common view props: modifiers, style and testID.

Overview

The stack is "lazy," in that the stack view doesn't create items until it needs to render them onscreen.

In the following example, a ScrollView contains a LazyVStack that consists of a vertical row of text views. The stack aligns to the leading edge of the scroll view, and uses default spacing between the text views.

ScrollView {
    LazyVStack(alignment: .leading) {
        ForEach(1...100, id: \.self) {
            Text("Row \($0)")
        }
    }
}

From Apple’s SwiftUI documentation. Code samples there are Swift.

Relationships

Conforms to

  • View

See also

More in Layout.