BottomSheetRoot에 ref를 전달하면 open, close, snapTo, expand, collapse 메서드를 호출할 수 있습니다. 이 메서드로 바꾼 열림 상태는 onOpenChange로 알리지 않습니다. open을 제어하는 경우에는 메서드 대신 open 값을 바꾸세요.
import { useRef } from "@lynx-js/react";import { BottomSheetRoot, type BottomSheetRootRef } from "@/components/ui/bottom-sheet";export function App() { const ref = useRef<BottomSheetRootRef>(null); return ( <BottomSheetRoot ref={ref} snapPoints={["fit", "80%"]}> {/* ... */} </BottomSheetRoot> );}
The side from which the sheet enters.
bottom preserves the existing bottom-sheet behavior.
top provides top-sheet behavior.
left and right provide physical drawer behavior.
start and end provide logical drawer behavior and resolve against enableRTL.
Type
SheetSide | undefined
Default
'bottom'
enableRTL?boolean | undefined
Whether the Sheet should use RTL direction.
This sets the Sheet viewport direction to rtl by default and resolves
logical drawer sides in RTL mode.
When false, start means left and end means right.
When true, start means right and end means left.
Physical left and right sides are not affected by enableRTL.
Type
boolean | undefined
Default
false
snapPoints?SheetSnapPoint[] | undefined
The snap points of the Sheet. Can be pixel numbers, percentages, or 'fit'.
Numbers are treated as pixel values
Percentages (e.g., '50%') are relative to screen height for top / bottom,
and relative to screen width for left / right / start / end
'fit' dynamically resolves to the measured content height for top / bottom,
and the measured content width for left / right / start / end
Type
SheetSnapPoint[] | undefined
Default
['fit'] - `{ fit: true, min, max }` resolves to the measured content size clamped to `min` and `max` The index order follows the order of this array.
시트가 스냅 지점으로 움직이기 시작할 때 목표를 알린다. 애니메이션이 끝나면 onSnapChange가 이어서 불린다.
목표 index가 직전 목표와 다를 때만 불리며, 열릴 때의 첫 스냅은 항상 알린다. 닫힘은 알리지 않는다.
진행 중인 스냅이 새 스냅에 끊기면 새 목표만 알리고, 끊긴 스냅의 onSnapChange는 불리지 않는다.
value는 px로 환산한 스냅 지점이다.
배경(Backdrop)이 어두워지는 snap 지점 index다. 시트가 snapPoints[fadeFromIndex] 위치 이상이면 배경 농도가
1, 그보다 작은 snap 지점 중 가장 큰 위치(없으면 닫힌 위치) 이하이면 0이고, 그 사이에서는 위치에 비례해
바뀐다. snap 지점이 크기 순서가 아니어도 위치로 비교한다. 범위를 벗어난 index는 가까운 끝 지점으로 맞추며,
지정하지 않거나 아직 측정하지 않은 'fit' 지점이면 가장 크게 열린 크기를 기준으로 0에서 1로 바뀐다.
Type
number | undefined
screenHeight?number | undefined
The height of the Sheet container (screen height).
Used in vertical sheet mode (top / bottom) for percentage snap points
and dismissal calculations. Defaults to the measured height of the SheetView layer; percentage
snap points wait for that measurement before entering.
Type
number | undefined
screenWidth?number | undefined
The width of the Sheet container (screen width).
Used in horizontal drawer mode (left / right / start / end) for percentage snap points
and dismissal calculations. Defaults to the measured width of the SheetView layer; percentage
snap points wait for that measurement before entering.
The rubber band effect configuration.
By default, rubber band over-drag is enabled for vertical sheets
(top / bottom) and disabled for horizontal drawers
(left / right / start / end).
If true, enables default rubber band effect (coefficient 0.5).
If false, disables rubber band effect.
If number, enables rubber band effect with the specified coefficient.
If object, allows specifying coefficient and max distance.
Whether to enable dragging to close the Sheet.
If true, dragging from the lowest snap point toward the closed edge will move the sheet linearly and allow dismissal.
If false, dragging toward the closed edge will trigger rubber band effect and snap back.
Type
boolean | undefined
Default
true
flingEnabled?boolean | undefined
드래그를 놓을 때 속도로 위치를 투사해 snap 지점을 고를지 정한다. false면 놓은 위치에서 가장 가까운 snap
지점(또는 닫힘 기준선 아래면 닫힘)으로 간다.
드래그를 놓을 때 기본 판정보다 먼저 불려 결과를 정한다. main thread에서 실행되므로 함수 본문 첫 줄에
"main thread" directive가 있어야 한다. { snap }이면 fling 없이 그 index로 snap하고, { close: true }이면
놓은 자리에서 닫으며(enableDragToClose와 관계없이), undefined이면 기본 판정을 쓴다.
delta·velocity는 양수가 더 열리는 방향이다.
시트 위치(열린 크기, px)가 바뀔 때마다 불린다. 드래그, snap, 열림·닫힘 애니메이션의 매 프레임을 포함한다.
main thread에서 실행되므로 함수 본문 첫 줄에 "main thread" directive가 있어야 한다. 시트 위치에 맞춰 시트
안의 요소 크기를 바꿀 때 쓴다.
Angle ranges (in degrees) where gestures should be claimed by the Sheet.
Each entry is [minAngle, maxAngle]. Gestures within these angle ranges
will trigger sheet movement, while gestures outside these ranges are passed through.
see https://lynxjs.org/api/elements/built-in/view#consume-slide-event for more
Type
[number, number][] | undefined
children?ReactNode
children
Type
ReactNode
forceMount?boolean | undefined
Mount the sheet and render its content even when not shown. The sheet remains in closed state.
Type
boolean | undefined
Default
false
onOpen?(() => void) | undefined
Called when the sheet has fully opened and any enter animation has finished.
Type
(() => void) | undefined
onClose?(() => void) | undefined
Called when the sheet has fully closed and any exit animation has finished.
Type
(() => void) | undefined
open?boolean | undefined
Whether the sheet is open (controlled mode).
Internally mapped to show of the internal sheet engine.
Type
boolean | undefined
defaultOpen?boolean | undefined
Whether the sheet is open by default (uncontrolled mode).
Internally mapped to defaultShow.
Called once when Trigger, CloseButton, Backdrop or a drag changes the open state, with the
reason of the change. Changes made through the Root ref or the open prop are not reported.
Called when the sheet finishes opening (true) or closing (false), whatever changed the open
state. false comes after the layer is removed from the screen, so UI shown from it (such as a
snackbar) is not covered by or attached to the closing layer. With forceMount the layer stays
mounted, so false only means the close finished and the layer is still on screen.
The transition configuration for the Sheet snap animation.
Type
SheetTransition | undefined
enterAnimation?SheetTransition | undefined
The enter animation configuration.
Type
SheetTransition | undefined
exitAnimation?SheetTransition | undefined
The exit animation configuration.
Type
SheetTransition | undefined
innerClassName?string | undefined
CSS class name for the inner layer.
Use this for content layout and sizing styles. In horizontal drawer mode,
the drawer width should be set here so 'fit' can resolve from the
measured drawer width.
Type
string | undefined
innerStyle?CSSProperties | undefined
Inline styles for the inner layer.
Use this for content layout and sizing styles.
Note: Visual styles (background, borderRadius, etc.) should be set via
the main style prop which applies to the moving surface layer.
In horizontal drawer mode, set drawer width here so 'fit' can resolve
from the measured drawer width.
onOpenChange의 두 번째 인자는 { reason }입니다. Trigger로 열면 "trigger", 닫기 버튼으로 닫으면 "closeButton", 배경을 탭해 닫으면 "interactOutside", 시트를 끌어 닫으면 "drag"입니다. 닫히는 중에 시트를 다시 끌어 올리면 open이 true인 "drag"가 전달됩니다. Root ref의 메서드나 open prop으로 바꾼 상태에는 호출되지 않습니다. React 버전의 escapeKeyDown처럼 Lynx에 해당 입력이 없는 reason은 제공하지 않습니다.
onAnimationEnd는 열림 애니메이션이 끝나면 true, 닫힘 애니메이션이 끝나면 false와 함께 호출됩니다. 열림 상태를 바꾼 방법과 관계없이 호출되며, Root ref의 메서드나 open prop으로 바꾼 경우도 포함합니다. false는 시트 레이어가 화면에서 제거된 뒤에 전달됩니다. 단, forceMount를 켜면 닫힌 뒤에도 레이어가 남아 있으므로 false는 닫힘이 끝났다는 뜻일 뿐 레이어 제거를 보장하지 않습니다.
시트를 닫은 뒤 스낵바처럼 화면 위에 뜨는 native UI를 띄우려면 onOpenChange 대신 onAnimationEnd에서 호출하세요. container로 띄운 시트가 닫히는 중에 호출하면 native UI가 닫히는 overlay에 붙어 함께 사라질 수 있습니다.
시트 높이가 내용에 맞춰 정해지면 화면 높이의 90%를 넘지 않고, 위쪽 inset이 그보다 크면 inset 아래까지로 제한됩니다. 제한에 닿으면 BottomSheetBody가 스크롤됩니다. Body가 스크롤된 상태에서 시작한 제스처는 Body만 움직이고, Body가 맨 위에 있을 때 아래로 끌어야 시트가 움직입니다.
snapPoints에는 픽셀 숫자, 백분율, 콘텐츠 크기에 맞추는 "fit"을 사용할 수 있습니다. 백분율은 시트가 그려지는 BottomSheetPositioner 레이어의 높이를 기준으로 하고, screenHeight를 지정하면 그 값을 기준으로 합니다. 레이어는 container가 없으면 LynxView, container="window"이면 window를 채우므로, 내용 높이로 삽입된 LynxView에서도 시트 높이가 줄어들지 않습니다. 백분율 snap point는 레이어를 측정한 뒤 열리기 시작합니다. 배열 순서가 snap index가 되며, initialSnap으로 처음 열릴 높이를 정합니다.
onSnapChange에서는 현재 index와 픽셀로 계산된 높이를 받을 수 있습니다. ref의 snapTo 메서드를 사용하면 원하는 높이로 이동할 수 있습니다.
범위가 있는 fit({ fit: true, min, max })을 쓰면 내용 높이를 따르되 min과 max 사이로 맞춥니다. min·max에는 픽셀 숫자나 백분율을 쓸 수 있습니다. 내용이 max보다 길면 Body가 스크롤되고, min보다 짧으면 시트가 min 높이를 채웁니다. 내용 높이가 바뀌면 현재 snap index의 범위로 다시 맞춥니다. 내용이 짧아 두 snap point가 같은 높이가 되면, 드래그를 놓거나 expand·collapse를 호출해도 현재 index를 유지합니다.
<BottomSheetRoot snapPoints={[ { fit: true, min: 320, max: "50%" }, { fit: true, min: 320, max: 640 }, ]}> {/* 처음에는 화면의 절반까지, 끌어 올리면 640px까지 내용에 맞춰 열립니다. */}</BottomSheetRoot>
onActiveSnapChange는 시트가 snap point로 움직이기 시작할 때 목표 index와 높이를 받습니다. 애니메이션이 끝나면 onSnapChange가 이어서 호출되므로, 드래그를 놓는 순간 목표에 맞춰 UI를 바꿀 때 사용하세요. 목표가 직전 목표와 같으면 호출되지 않고, 시트가 열릴 때의 첫 snap은 항상 알립니다. 닫힘은 onOpenChange로 알리므로 호출되지 않습니다. 진행 중인 snap이 다른 snap으로 바뀌면 새 목표만 다시 알리고, 중단된 snap의 onSnapChange는 호출되지 않습니다.
<BottomSheetRoot>에 fadeFromIndex를 전달하면 Backdrop이 어두워지는 snap point를 정할 수 있습니다. 시트가 snapPoints[fadeFromIndex] 높이 이상이면 Backdrop이 완전히 어둡고, 그 바로 아래 snap point 높이 이하에서는 투명하며, 그 사이에서는 시트 위치에 비례해 바뀝니다. 아래 snap point가 없으면 닫힌 위치부터 어두워집니다. 범위를 벗어난 index는 가까운 끝 snap point로 맞춥니다. 지정하지 않으면 가장 크게 열린 높이를 기준으로 농도가 바뀝니다.
Lynx에는 배경 탭, 드래그, ESC 닫기를 한 번에 제어하는 dismissible prop이 없습니다. enableDragToClose={false}로 드래그 닫기만 막을 수 있으며, Registry에서는 배경 탭 닫기를 끌 수 없습니다. ESC 키 닫기도 지원하지 않습니다. 닫기 동작을 막았다면 Footer 등에 닫기 버튼을 제공하세요.
스크롤 힌트가 필요하면 Body 안에 Scroll Fog와 세로 <scroll-view>를 배치하세요. Body의 스크롤 영역 안에서는 height: "100%"가 기준으로 삼을 높이가 없으므로, ScrollFog에 고정 높이를 지정해야 합니다. fog 방향과 크기는 ScrollFog의 placement·size로, 스크롤바와 스크롤 동작은 <scroll-view> prop으로 제어합니다. 이 <scroll-view>의 스크롤을 시트 드래그와 조정하려면 useBottomSheetScrollHandoff()가 돌려준 props를 펼치세요. 펼치지 않으면 스크롤한 상태에서 아래로 끌 때 시트도 함께 움직입니다.
ScrollFog는 스크롤 위치와 관계없이 항상 효과를 표시하므로, <scroll-view>에 권장 padding인 상단 20px, 하단 80px을 지정해야 합니다.
드래그를 놓으면 기본으로 놓은 속도만큼 위치를 투사해 가장 가까운 snap point로 가거나, 닫힘 기준선을 지나면 닫힙니다. flingEnabled={false}를 전달하면 속도를 무시하고 놓은 위치에서 가장 가까운 snap point로 갑니다.
resolveRelease로 놓았을 때의 결과를 직접 정할 수 있습니다. main thread에서 실행되므로 함수 첫 줄에 "main thread" directive가 있어야 합니다. 드래그를 시작할 때의 snap index(index), 놓은 위치(offset), 시작 위치에서의 변화(delta), 속도(velocity), touchcancel 여부(canceled)를 받습니다. delta와 velocity는 양수가 더 열리는 방향입니다. { snap: index }를 반환하면 그 snap point로 가고, { close: true }를 반환하면 닫히며, undefined를 반환하면 기본 판정을 따릅니다.
onPositionChange는 시트 위치가 바뀔 때마다 시트가 열린 높이(px)를 받습니다. 드래그, snap, 열림·닫힘 애니메이션의 매 프레임에 호출됩니다. main thread에서 실행되므로 함수 첫 줄에 "main thread" directive가 있어야 합니다. 시트를 끄는 동안 시트 안의 스크롤 영역 높이를 시트 높이에 맞출 때처럼, 렌더링을 기다리지 않고 요소를 바꿀 때 사용하세요.
const listMTRef = useMainThreadRef<MainThread.Element>(null);<BottomSheetRoot snapPoints={["40%", "80%"]} onPositionChange={(position) => { "main thread"; // 헤더 높이 56px을 뺀 만큼 목록을 보여 줍니다. listMTRef.current?.setStyleProperty("height", `${Math.max(0, position - 56)}px`); }}> {/* <view main-thread:ref={listMTRef}>...</view> */}</BottomSheetRoot>
BottomSheetBody는 스크롤 영역과 시트 드래그를 조정합니다. 목록이 스크롤된 상태에서 시작한 제스처와 맨 위에서 위로 미는 제스처는 목록이 스크롤하고, 맨 위에서 아래로 끄는 제스처는 시트를 끕니다.
Body 밖에 직접 둔 <scroll-view>나 <list>에는 useBottomSheetScrollHandoff()가 돌려준 props를 펼쳐 같은 동작을 줍니다. scrollEnabled: false를 넘기면 목록이 스크롤하지 않고 세로 제스처를 시트가 모두 받습니다. topThreshold는 맨 위로 볼 scrollTop 값입니다. 슬라이더처럼 시트 드래그를 막아야 하는 영역에는 useBottomSheetNoDrag()가 돌려준 props를 펼치세요. 그 영역에서 시작한 제스처는 시트가 받지 않습니다. 두 훅은 BottomSheetContent 안에서만 판정하며, 그 밖에서는 useBottomSheetScrollHandoff()가 enable-scroll만 돌려줍니다.
<BottomSheetRoot>에 handleOnly를 전달하면 Bottom Sheet를 움직이는 세로 제스처 영역이 Handle로 제한됩니다. 이 옵션은 <BottomSheetContent showHandle>과 함께 사용하세요. 본문이 길 때는 Body 안의 스크롤 영역과 시트 드래그가 겹치지 않도록 이 조합을 권장합니다.
container를 지정하지 않으면 Bottom Sheet는 Lynx view 안에 렌더링됩니다. container="window"처럼 native container 이름을 지정하면 host 화면까지 덮는 native overlay에 렌더링됩니다. overlayLevel은 overlay의 표시 순서를 정합니다. 이 기능을 사용할 때는 앱의 Lynx Engine이 <overlay>를 지원해야 합니다. container를 지정하면 시트의 Safe Area 여백은 SeedProvider에 넘긴 windowSafeAreaInsets를 따릅니다. 값을 넘기지 않았으면 safeAreaInsets를 따릅니다.