Skip to content

API reference ​

Everything is imported from the package root:

ts
import {
  NativeSheetProvider, NativeSheet, NativeModal,
  useNativeSheet, useSheetState,
  presentAlert, presentToast,
  SheetManager, SheetRegistry, DEFAULT_MAX_STACK_DEPTH,
  VARIANTS, SIZING_SNAP_POINTS,
  resolveSnapFraction, isValidSnapPoint, CONTENT_SNAP_FRACTION,
} from 'react-native-universal-sheet';

Exports ​

ExportKindPage
NativeSheetProvidercomponentNativeSheetProvider
NativeSheetcomponentNativeSheet
NativeModalcomponentNativeModal
useNativeSheet()hookuseNativeSheet
useSheetState(id)hookuseSheetState
presentAlert(manager, options)functionpresentAlert
presentToast(manager, options)functionpresentToast
SheetManagerclassSheetManager
SheetRegistryclassSheetRegistry
DEFAULT_MAX_STACK_DEPTH5
VARIANTSRecord<SheetVariant, VariantSpec>Sheet types
SIZING_SNAP_POINTSRecord<SheetSizing, SnapPoint>Snap points
resolveSnapFraction(point, viewportHeight)functionSnap point → fraction of height (-1 for content)
isValidSnapPoint(point)functionValidates one snap point
CONTENT_SNAP_FRACTION-1

SheetConfig ​

The object passed to present(). NativeSheet takes the same options as props (without id/content, which it fills in).

OptionTypeDefault
idstringrequired, non-empty, unique among open sheets
contentReactNoderequired
variantSheetVariant'bottomSheet'
presentation'stack' | 'replace''stack'
behavior'modal' | 'nonModal' | 'persistent'from variant
side'left' | 'right''right' (only side variant)
snapPointsSnapPoint[][SIZING_SNAP_POINTS[sizing]] or ['large']
initialSnapPointSnapPointfirst snap point
sizing'peek' | 'half' | 'medium' | 'expanded' | 'full'—
enableDragbooleanfrom variant
enableBackdropbooleanvariant value if modal, else false
enableKeyboardbooleanfrom variant
enableNestedScrollbooleanfrom variant
hardwareBackDismissbooleanfrom variant (true except loadingOverlay)
autoDismissMsnumber > 0from variant
marginnumber ≥ 016 for floating placements, else 0
anchorAnchorRectrequired for anchored variants
animationSheetAnimation—
appearanceSheetAppearance—
stylesSheetStyles—
actionsSheetAction[]—
accessibilityLabelstring—
onWillPresent(id) => void—
onDidPresent(id) => void—
onWillDismiss(id) => void—
onDidDismiss(id) => void—
onSnapChange(id, index) => void—

Types ​

ts
type SnapPoint = number | `${number}%` | 'content' | 'small' | 'medium' | 'large' | 'full';

type SheetSizing = 'peek' | 'half' | 'medium' | 'expanded' | 'full';

type ModalVariant = 'center' | 'fullScreen' | 'alert' | 'popup' | 'side' | 'top' | 'floating';
type BottomSheetVariant = 'bottomSheet' | 'action' | 'share' | 'picker' | 'filter';
type OverlayVariant =
  | 'toast' | 'snackbar' | 'tooltip' | 'popover' | 'contextMenu' | 'dropdown'
  | 'coachmark' | 'spotlight' | 'loadingOverlay' | 'fullScreenViewer' | 'inAppNotification';
type SheetVariant = ModalVariant | BottomSheetVariant | OverlayVariant;

type SheetBehavior = 'modal' | 'nonModal' | 'persistent';
type SheetPresentation = 'stack' | 'replace';

interface AnchorRect { x: number; y: number; width: number; height: number }

interface SheetAnimation {
  type?: 'spring' | 'timing';
  damping?: number;
  stiffness?: number;
  mass?: number;
  durationMs?: number;
}

interface SheetAction {
  label: string;
  style?: 'default' | 'destructive' | 'cancel';
  onPress?: () => void;
}

interface SheetAppearance {
  backgroundColor?: string;   // '#RRGGBB' or '#RRGGBBAA'
  cornerRadius?: number;      // >= 0
  backdropOpacity?: number;   // 0..1
  backdropColor?: string;
  showHandle?: boolean;
  handleColor?: string;
  borderWidth?: number;       // >= 0
  borderColor?: string;
  shadowRadius?: number;      // >= 0
  shadowOpacity?: number;     // 0..1
  width?: number;             // > 0
}

interface SheetStyles {
  contentStyle?: StyleProp<ViewStyle>;
  titleStyle?: StyleProp<TextStyle>;
  messageStyle?: StyleProp<TextStyle>;
  buttonStyle?: StyleProp<ViewStyle>;
  buttonTextStyle?: StyleProp<TextStyle>;
}

type SheetConfigPatch = Partial<Omit<SheetConfig, 'id' | 'presentation' | 'variant' | 'behavior' | 'side'>>;

type SheetErrorReason =
  | 'invalid-config' | 'invalid-snap-point' | 'missing-anchor' | 'duplicate-id'
  | 'not-found' | 'stack-limit-reached' | 'replace-in-progress' | 'unknown-sheet';

type SheetResult = {ok: true} | {ok: false; reason: SheetErrorReason};

interface ActiveSheet {
  readonly id: string;
  readonly config: ResolvedSheetConfig; // SheetConfig with every default filled in
  readonly snapIndex: number;
  readonly phase: 'presented' | 'dismissing';
}

Other exported types: NativeSheetProviderProps, NativeSheetProps, SheetOptions, NativeModalProps, AlertOptions, ToastOptions, SheetManagerOptions, PresentNamedOptions, DismissAllOptions, Scheduler, SheetDefinition, SheetDefaults, VariantSpec, SheetGroup, SheetPlacement, SheetEvents, SheetPhase, ResolvedSheetConfig.

Released under the MIT License.