Skip to content

Scroll View

A scroll view shows a single child which may be larger than the scroll view itself and lets the user scroll it, vertically by default or horizontally. Give the scroll view a size through its Frame, otherwise it simply grows with its content.

Scroll View

numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

return ScrollView(
	HStack(
		ForEach(numbers, func(n int) core.View {
			return Text(fmt.Sprintf("Item %d", n)).
				BackgroundColor("#C9E7F8").
				Frame(Frame{}.Size(L120, L80))
		})...,
	).Gap(L8),
).Axis(ScrollViewAxisHorizontal).
	BackgroundColor(ColorCardBody).
	Padding(Padding{}.All(L8)).
	Frame(Frame{Width: L480})

For chat-like views, ScrollBehavior controls whether the view follows content which is appended at the end, and ScrollToView scrolls to the child with the given ID.

Constructors

ConstructorDescription
ScrollView(content core.View) TScrollViewCreates a vertical scroll view around the given content.

Methods

MethodDescription
Axis(axis ScrollViewAxis) TScrollViewSets the scroll direction, ScrollViewAxisVertical or ScrollViewAxisHorizontal.
BackgroundColor(color Color) TScrollViewSets the background color of the scroll view.
Border(border Border) TScrollViewApplies a border around the scroll view.
Content(content core.View) TScrollViewReplaces the scrollable content.
Frame(frame Frame) TScrollViewSets the layout frame for the scroll view.
FullWidth() TScrollViewSets the width to the full available width.
ListLength(length int) TScrollViewSets the length of the content list; optional, but use it if the content is based on a list.
Padding(padding Padding) TScrollViewSets the inner padding of the scroll view.
Position(position Position) TScrollViewSets the position of the scroll view.
ScrollAlignment(alignment ScrollAlignment) TScrollViewDefines how the component should align the scroll target when scrolling into view.
ScrollBehavior(behavior ScrollBehavior) TScrollViewDefines how the component should behave when the scrollable content grows.
ScrollButtonLabel(label string) TScrollViewSets the label of the scroll button when the component asks whether to scroll.
ScrollToView(scrollToView string, animation ScrollAnimation) TScrollViewScrolls to the view with the given ID, smoothly or instantly.

Related