Contents

AnyScrollTargetBehavior

A type-erased scroll target behavior.

Declaration

@frozen struct AnyScrollTargetBehavior

Overview

Provide this to the scrollTargetBehavior(_:) modifier. When the underlying behavior changes, the scroll view to which this behavior applies will be updated.

Use this to dynamically control the scroll target behavior at runtime. For example, you could provide a paging behavior in compact size classes and a view aligned behavior otherwise.

@Environment(\.horizontalSizeClass) var sizeClass

var body: some View {
    ScrollView { ... }
        .scrollTargetBehavior(scrollTargetBehavior)
}

 var scrollTargetBehavior: some ScrollTargetBehavior {
    sizeClass == .compact
        ? AnyScrollTargetBehavior(.paging)
        : AnyScrollTargetBehavior(.viewAligned)
}

Topics

Initializers

Instance Properties

See Also

Defining scroll targets