ScrollAnchorRole

A type defining the role of a scroll anchor.

StructureiOS 18.0+macOS 15.0+tvOS 18.0+watchOS 11.0+visionOS 2.0+ScrollAnchorRole in SwiftUI

Declaration

React
type ScrollAnchorRole = 'alignment' | 'initialOffset' | 'sizeChanges';
Swift
struct ScrollAnchorRole

Pass a literal, or build one with SwiftUI.ScrollAnchorRole from import { SwiftUI } from 'swiftui-react-native'.

Type properties

  • 'alignment'SwiftUI.ScrollAnchorRole.alignment

    The role that influences how a scroll view should align its content when the size of its content is smaller than the container size of the scroll view.

  • 'initialOffset'SwiftUI.ScrollAnchorRole.initialOffset

    The role that influences where a scroll view should be initially scrolled.

  • 'sizeChanges'SwiftUI.ScrollAnchorRole.sizeChanges

    The role that influences how a scroll view should adjust its content offset when the scroll view's content or container size changes.

Overview

You can associate a UnitPoint to a ScrollView using the View.defaultScrollAnchor(_:) modifier. By default, the system uses this point for different kinds of behaviors including:

  • Where the scroll view should initially be scrolled
  • How the scroll view should handle content size or container size changes
  • How the scroll view should align content smaller than its container size

You can further customize this behavior by assigning different unit points for these different roles.

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

Used by

See also

More in Layout.