Scroll area
v0.0.10
mix mishka.ui.gen.mob scroll_area
The Mishka Chelekom Mob Scroll Area is a bounded region whose content scrolls vertically or horizontally on iOS and Android. It is the native port of the headless Scroll Area and runs on Mob.
Overview of the Mob Scroll Area component for iOS and Android
Scroll Area wraps Mob's native Scroll, so the platform supplies momentum, overscroll, rubber banding and the scrollbar. The web component exists mainly to replace the browser scrollbar with a styled one. A phone has nothing to replace, and a hand-drawn scrollbar would be worse than the real one.
A scroll area needs a bound. Content scrolls only when the viewport is smaller than it, so a vertical scroll area inside a page that already scrolls needs a height. Without one it grows to fit its content and never scrolls. The showcase app always sets height.
The Scroll itself takes no size or decoration. With no height, background, padding or corner_radius, Scroll Area is a single Scroll node. Otherwise it is a Box with fill_width around the Scroll.
Scroll Area keeps no state and sends no events, because the native view owns the scroll position. An id registers the native scroll view so a screen can move it without a finger. See MishkaScroller.nudge/3 on the Mob Scroller page, which is what the scroller arrows call.
Generate the scroll area component
Run this from your Mob app's root to add the component to lib/<app>/components/:
mix mishka.ui.gen.mob scroll_areaThe generator registers the <ScrollArea> tag so you can use it in ~MOB markup. The examples on this page use the mishka_ prefix of the showcase app (--module-prefix mishka_), so the tag is <MishkaScrollArea>. Without a prefix the tag is <ScrollArea>.
Vertical scroll area
height bounds the viewport. Without it, nothing scrolls. The showcase app also sets a raised background, rounded corners and padding on the area.
Vertical scroll area
<MishkaScrollArea height={200} background={:surface_raised}>{rows()}</MishkaScrollArea>Horizontal scroll area
orientation: :horizontal scrolls a wide row. Flick sideways to move through the tiles.
Horizontal scroll area
<MishkaScrollArea orientation={:horizontal}>{wide_row()}</MishkaScrollArea>Scroll area without props
With no height or styling, Scroll Area is a single Scroll node. In the showcase app, a box 120 dp tall around it supplies the bound.
Scroll area without props
<MishkaScrollArea>{content}</MishkaScrollArea>Props
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | :vertical or :horizontal | :vertical | Scroll axis. |
height | number | nil | Viewport height. Required for a vertical scroll area to scroll at all. |
id | string | nil | Registers the native scroll view so a screen can scroll it by id. |
background | color token or ARGB int | nil | Viewport fill. |
padding | spacing token or number | nil | Padding inside the viewport. |
corner_radius | radius token or number | nil | Rounds the viewport. |
Differences from the web component
orientation: "both"is not ported. Compose'sScrollscrolls one axis, and two-axis content needs a horizontal scroller nested inside a vertical one. You write that nesting yourself. The web component's third value is dropped so it never silently behaves like:vertical.- The
*_classattributes are not ported, because they style a scrollbar that the platform owns.
Attributes
| Name | Type | Default | Values | Required | Description |
|---|---|---|---|---|---|
orientation
|
:vertical :horizontal
|
:vertical
| — | No | Scroll axis. |
height
|
number
| — | — | No | Viewport height. Required for a vertical scroller to scroll at all. |
id
|
string
| — | — | No | Registers the scroller so it can be scrolled by id. |
background
|
color token / ARGB int
| — | — | No | Viewport fill. |
padding
|
spacing token / number
| — | — | No | Padding inside the viewport. |
corner_radius
|
radius token / number
| — | — | No | Rounds the viewport. |
Options
Each option takes one or more of its values, separated by commas.
| Option | Values |
|---|---|
--type
|
scroll_area
|
--module
| A module name of your own |
What it generates
mix mishka.ui.gen.mob scroll_area