Declaration
import { ScrollView } from 'swiftui-react-native';nonisolated struct ScrollView<Content> where Content : ViewInitializers
One SwiftUI initializer backs <ScrollView>.
<ScrollView
axes?: SwiftUI.AxisSet
>
children?: ReactNode
</ScrollView>@export(implementation) nonisolated init(
_ axes: Axis.Set = .vertical,
@ContentBuilder content: () -> Content
)axesSwiftUI.AxisSetThe scroll view's scrollable axis. The default axis is the vertical axis.
Default
`.vertical`childrenReactNodeContent. 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 scroll view displays its content within the scrollable content region.
As the user performs platform-appropriate scroll gestures, the scroll view
adjusts what portion of the underlying content is visible. ScrollView can
scroll horizontally, vertically, or both, but does not provide zooming
functionality.
In the following example, a ScrollView allows the user to scroll through
a VStack containing 100 Text views. The image after the listing
shows the scroll view's temporarily visible scrollbar at the right; you can
disable it with the showsIndicators parameter of the ScrollView
initializer.
var body: some View {
ScrollView {
VStack(alignment: .leading) {
ForEach(0..<100) {
Text("Row \($0)")
}
}
}
}Controlling Scroll Position
You can influence where a scroll view is initially scrolled
by using the View.defaultScrollAnchor(_:) view modifier.
Provide a value of UnitPoint.center to have the scroll
view start in the center of its content when a scroll view
is scrollable in both axes.
ScrollView([.horizontal, .vertical]) {
// initially centered content
}
.defaultScrollAnchor(.center)Or provide an alignment of UnitPoint.bottom to have the
scroll view start at the bottom of its content when a scroll
view is scrollable in its vertical axes.
ScrollView {
// initially bottom aligned content
}
.defaultScrollAnchor(.bottom)After the scroll view initially renders, the user may scroll the content of the scroll view.
To perform programmatic scrolling, wrap one or more scroll views with a
ScrollViewReader.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- View
See also
More in Layout.
- AnyLayoutA type-erased instance of the layout protocol.
- GeometryReaderA container view that defines its content as a function of its own size and coordinate space.
- GlassEffectContainerA view that combines multiple glass shapes into a single shape that can morph individual shapes into one another.
- GridA container view that arranges other views in a two dimensional layout.
- GridLayoutA grid that you can use in conditional layouts.
- GridRowA horizontal row in a two dimensional grid container.
- HStackA view that arranges its subviews in a horizontal line.
- HStackLayoutA horizontal container that you can use in conditional layouts.
- LazyHGridA container view that arranges its child views in a grid that grows horizontally, creating items only as needed.
- LazyHStackA view that arranges its children in a line that grows horizontally, creating items only as needed.
- LazyVGridA container view that arranges its child views in a grid that grows vertically, creating items only as needed.
- LazyVStackA view that arranges its children in a line that grows vertically, creating items only as needed.