Command palette

@yasinsensoy/native

React Native · Components

ResizablePanels

Panels resized by dragging (the same rules as web): sidebar + list + detail on a tablet, code/output panes.

6 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

  • Ayşe YılmazSprint planI added the agenda for tomorrow's meeting.
  • Mehmet KayaInvoice #2041The October invoice is attached.
  • Zeynep DemirDesign feedbackThe new dashboard design is great.
  • Can ÖztürkServer maintenanceShort outage on Saturday at 02:00.
  • Elif ŞahinLunch?Shall we go to the new place today?

Sprint plan

Ayşe Yılmaz · 09:42

Hi team, I added the agenda for tomorrow's meeting. You can resize the panels by dragging, double clicking the handle, or focusing it with Tab and using the arrow keys.

Code

import { ResizablePanels, Folders, Mesajlar, Mesaj } from "@yasinsensoy/native";

<ResizablePanels className="h-96 rounded-lg border" storageKey="playground-mail"
  panels={[
    {
      id: "folders",
      label: "Folders",
      defaultSize: 22,
      minSize: "180px",
      maxSize: 35,
      collapsible: true,
      collapsedSize: "56px",
      content: ({ collapsed }) => <Folders kompakt={collapsed} />,
    },
    { id: "list", label: "Mesajlar", defaultSize: 33, minSize: 20, content: <Mesajlar /> },
    { id: "okuma", minSize: 20, content: <Mesaj /> },
  ]}
/>

Events

  1. Events appear here when you interact with the preview.

A sidebar collapsed with a button (controlled collapsed)

Content

Nested: files | code / terminal

  • src/
  • app.tsx
  • index.css
  • package.json
export function App() {
  return <h1>Merhaba</h1>;
}
$ pnpm dev
✓ Ready in 812ms

Three equal panels, overflow when they hit the limit

A
B
C

Import

import { ResizablePanels } from "@yasinsensoy/native";

Panels resized by dragging (the same rules as web): sidebar + list + detail on a tablet, code/output panes. No external library.

  • The handle is dragged with a finger; the touch area is wider than the visible line.
  • Double-tapping the handle collapses/expands a collapsible panel; without a collapsible panel the two panels return to their initial size.
  • Screen reader: the handle is "adjustable"; swiping up/down resizes by step, and a double tap collapses/expands.
  • When a panel hits its limit, the shrinking carries over to the next panels.
  • Limits can be percentages or pixels (minSize: "240px"); pixel limits are kept when a tablet is rotated.
  • The layout is stored with storageKey + storage.
  • Panels can be nested.
ResizablePanels({ ref, panels, orientation, sizes: sizesProp, onSizesChange, onResizeEnd, storageKey, storage, handle, step, disabled, style, styles: parts, testID, }: ResizablePanelsProps): JSX.Element

Examples

<ResizablePanels
  style={{ flex: 1 }}
  storageKey="mail"
  storage={storage}
  panels={[
    {
      id: "menu",
      label: "Folders",
      defaultSize: 25,
      minSize: "180px",
      collapsible: true,
      collapsedSize: "56px",
      content: ({ collapsed }) => <Folders compact={collapsed} />,
    },
    { id: "list", label: "Messages", minSize: 25, content: <Messages /> },
  ]}
/>

State received when a function is given as panel content.

NameTypeDescription
collapsedbooleanWhether the panel is collapsed.
sizenumberThe panel's percentage of the container.

Panel size: a number is a percentage of the container (25 = 25%); a string can be pixels ("240px") or a percentage ("25%").

type PanelSize = number | `${number}%` | `${number}px`

A panel in ResizablePanels (same fields as on web).

NameTypeDefaultDescription
id?stringStable id of the panel. Used to find which layout to use when the layout is stored with storageKey and the panel list changes. Defaults to its index.
content?ReactNode | ((state: ResizablePanelState) => ReactNode)Content of the panel. To show a different view when collapsed (e.g. only icons) give a function: ({ collapsed }) => collapsed ? <Icons /> : <Menu />.
defaultSize?numberInitial size, as a percentage of the container. Panels without one share the remaining space equally.
minSize?PanelSize0Minimum size: a percentage (20) or pixels ("240px"). A pixel limit is kept as the container size changes (e.g. when a tablet is rotated).
maxSize?PanelSize100Maximum size: a percentage or pixels.
collapsible?booleanCollapsible. When shrunk below half of minSize it collapses to collapsedSize; pulling back expands it. Double-tapping the handle also collapses/expands.
collapsedSize?PanelSize0Size left when collapsed (e.g. "56px" for an icon strip).
defaultCollapsed?booleanThe panel starts collapsed.
collapsed?booleanCollapsed state (controlled). Changing it collapses the panel smoothly or expands it to its last size. The user collapsing it is reported via onCollapsedChange.
onCollapsedChange?(collapsed: boolean) => voidCalled when the panel is collapsed/expanded by the user or via collapsed.
label?stringName of the panel; becomes the accessible name of the handle after it (e.g. "Sidebar"). A screen reader reads "Sidebar, adjustable, 25%".
style?StyleProp<ViewStyle>Style of the panel box.

Styles of the inner parts of ResizablePanels.

NameTypeDescription
panel?StyleProp<ViewStyle>Each panel box.
handle?StyleProp<ViewStyle>Each handle between panels (the visible line).

Props of the ResizablePanels component.

NameTypeDefaultDescription
ref?Ref<ViewRef>Reference to the root view.
panelsreadonly ResizablePanel[]Panels, left to right (top to bottom when vertical).
orientation?"horizontal" | "vertical""horizontal"horizontal: panels side by side, the handle a vertical line. vertical: panels stacked; the container must have a height.
sizes?readonly number[]Sizes (controlled), a percentage per panel; they sum to 100.
onSizesChange?(sizes: number[]) => voidCalled whenever the sizes change (every frame while dragging).
onResizeEnd?(sizes: number[]) => voidCalled once with the final sizes when a drag, an accessibility action or a collapse ends.
storageKey?stringWhen given, the layout is stored in storage under this name and restored when the component reopens. Only applies in uncontrolled use.
storage?PreferenceStorageStorage for storageKey (e.g. @yasinsensoy/native/storage). Defaults to memory.
handle?"line" | "grip""grip"Look of the handle. grip: a grip bump in the middle (the default on touch). line: only a thin line; the grab area is still wide.
step?number5How many percent an accessibility action (increment/decrement) moves.
disabled?booleanResizing is disabled.
style?StyleProp<ViewStyle>Root style. The width (horizontal) or height (vertical) comes from the container.
styles?ResizablePanelsStylesStyles of the inner parts.
testID?stringTest id.