ScrollView#

ScrollView is a scrollable container. Maps to UI Toolkit's ScrollView.

Import#

import { ScrollView } from "onejs-react"

Basic Usage#

<ScrollView style={{ height: 300 }}>
    {items.map((item, i) => (
        <View key={i} style={{ padding: 10, borderBottomWidth: 1, borderColor: "#333" }}>
            <Label text={item.name} />
        </View>
    ))}
</ScrollView>

Props#

Basic Props#

PropTypeDefaultDescription
mode"Vertical", "Horizontal", "VerticalAndHorizontal""Vertical"Scroll direction
horizontalScrollerVisibility"Auto", "AlwaysVisible", "Hidden""Auto"Horizontal scrollbar visibility
verticalScrollerVisibility"Auto", "AlwaysVisible", "Hidden""Auto"Vertical scrollbar visibility
styleViewStyleInline styles
classNamestringUSS class name(s)
childrenReactNodeScrollable content

Scroll Behavior#

PropTypeDefaultDescription
elasticitynumber0.1Elasticity for elastic touch scrolling
elasticAnimationIntervalMsnumber10Interval for elastic animation in milliseconds
scrollDecelerationRatenumber0.135Deceleration rate after touch release
mouseWheelScrollSizenumber18Scroll distance per mouse wheel tick
horizontalPageSizenumberPage size for horizontal pagination
verticalPageSizenumberPage size for vertical pagination

Touch Behavior#

PropTypeDefaultDescription
touchScrollBehavior"Unrestricted", "Elastic", "Clamped""Clamped"How touch scrolling behaves at boundaries

Nested Scrolling#

PropTypeDefaultDescription
nestedInteractionKind"Default", "StopScrolling", "ForwardScrolling""Default"How nested ScrollViews interact

Scroll Modes#

// Vertical scrolling (default)
<ScrollView mode="Vertical" style={{ height: 400 }}>
    {content}
</ScrollView>

// Horizontal scrolling
<ScrollView mode="Horizontal" style={{ width: 400 }}>
    <View style={{ flexDirection: "row" }}>
        {items.map(item => <Card key={item.id} data={item} />)}
    </View>
</ScrollView>

// Both directions
<ScrollView mode="VerticalAndHorizontal" style={{ width: 400, height: 400 }}>
    {largeContent}
</ScrollView>

Scrollbar Visibility#

// Always show scrollbar
<ScrollView verticalScrollerVisibility="AlwaysVisible">
    {content}
</ScrollView>

// Hide scrollbar
<ScrollView verticalScrollerVisibility="Hidden">
    {content}
</ScrollView>

// Auto (show when needed)
<ScrollView verticalScrollerVisibility="Auto">
    {content}
</ScrollView>

Chat Log Example#

function ChatLog({ messages }) {
    return (
        <ScrollView style={{ height: 400, backgroundColor: "#1a1a1a" }}>
            <View style={{ padding: 10 }}>
                {messages.map((msg, i) => (
                    <View key={i} style={{
                        padding: 10,
                        marginBottom: 10,
                        backgroundColor: msg.isMe ? "#0066cc" : "#333",
                        borderRadius: 8,
                        alignSelf: msg.isMe ? "flex-end" : "flex-start",
                        maxWidth: "80%",
                    }}>
                        <Label text={msg.text} style={{ color: "#fff" }} />
                    </View>
                ))}
            </View>
        </ScrollView>
    )
}

List Example#

function ItemList({ items, onSelect }) {
    return (
        <ScrollView style={{ height: 300 }}>
            {items.map((item) => (
                <View
                    key={item.id}
                    style={{
                        padding: 15,
                        borderBottomWidth: 1,
                        borderColor: "#333",
                    }}
                    onClick={() => onSelect(item)}
                >
                    <Label text={item.title} style={{ fontStyle: "bold" }} />
                    <Label text={item.description} style={{ color: "#999", fontSize: 14 }} />
                </View>
            ))}
        </ScrollView>
    )
}
function ImageGallery({ images }) {
    return (
        <ScrollView mode="Horizontal" style={{ height: 150 }}>
            <View style={{ flexDirection: "row" }}>
                {images.map((url, i) => (
                    <View key={i} style={{
                        width: 120,
                        height: 120,
                        marginRight: 10,
                        backgroundColor: "#333",
                        borderRadius: 8,
                    }}>
                        {/* Image component would go here */}
                    </View>
                ))}
            </View>
        </ScrollView>
    )
}