Drawer
nativeui/drawerFreeComponent
A drawer component for React Native applications.
Live preview
live · rendered by the registry
Rendered by nativeui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://nativeui.ribbi.ch/r/drawer.jsonSource
1import { cn } from "@/lib/utils";2import * as React from "react";3import {4 Animated,5 Dimensions,6 Easing,7 KeyboardAvoidingView,8 Modal,9 PanResponder,10 Platform,11 StyleSheet,12 Text,13 TouchableWithoutFeedback,14 View,15} from "react-native";16import { SafeAreaView } from "react-native-safe-area-context";1718// Animation config constants19const ANIMATION = {20 OPEN: {21 BACKDROP_DURATION: 180,22 SPRING_VELOCITY: 3,23 SPRING_TENSION: 120,24 SPRING_FRICTION: 22,25 },26 CLOSE: {27 SPRING_FRICTION: 26,28 SPRING_TENSION: 100,29 SPRING_VELOCITY: 0.5,30 BACKDROP_DURATION: 280,31 BACKDROP_DELAY: 100,32 },33 SNAP: {34 SPRING_TENSION: 120,35 SPRING_FRICTION: 22,36 },37};3839// Drag behavior constants40const DRAG = {41 THRESHOLD: 5,42 CLOSE_DISTANCE: 100,43 VELOCITY_THRESHOLD: {44 UP: 0.3,45 DOWN: 0.5,46 },47 RESISTANCE: 0.1,48};4950// Drawer sizes - Definition of preset snap points51const DRAWER_SIZES = {52 SMALL: [0.3, 0.5], // Small drawer that can be extended to 50%53 MEDIUM: [0.5, 0.8], // Medium drawer that can be extended to 80%54 LARGE: [0.6, 0.8, 0.95], // Large drawer with size options55 FULL: [0.8, 0.95], // Full screen with reduced option56};5758const { height: SCREEN_HEIGHT } = Dimensions.get("window");5960export type DrawerSize = "small" | "medium" | "large" | "full" | number[];6162const resolveSnapPoints = (size: DrawerSize): number[] => {63 if (Array.isArray(size)) return size;6465 switch (size) {66 case "small":67 return DRAWER_SIZES.SMALL;68 case "medium":69 return DRAWER_SIZES.MEDIUM;70 case "large":71 return DRAWER_SIZES.LARGE;72 case "full":73 return DRAWER_SIZES.FULL;74 default:75 return DRAWER_SIZES.MEDIUM;76 }77};7879interface DrawerProps {80 open: boolean;81 onClose: () => void;82 children: React.ReactNode;83 title?: string;84 size?: DrawerSize;85 initialSnapIndex?: number;86 snapPoints?: number[];87 contentClassName?: string;88 avoidKeyboard?: boolean;89 closeOnBackdropPress?: boolean;90 disableBackHandler?: boolean;91}9293interface DrawerContextValue {94 close: () => void;95 snapTo: (index: number) => void;96 currentSnapIndex: number;97 snapPoints: number[];98 isClosing: boolean;99 isAnimating: boolean;100 position: Animated.Value;101}102103export const DrawerContext = React.createContext<DrawerContextValue>({104 close: () => { },105 snapTo: () => { },106 currentSnapIndex: 0,107 snapPoints: DRAWER_SIZES.MEDIUM,108 isClosing: false,109 isAnimating: false,110 position: new Animated.Value(0),111});112113// … truncated
What it pulls in
npm packages
Files it writes
More from nativeui
All 29 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | nativeui | Components | Free | 2 deps | |
| Alertalert | nativeui | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | nativeui | Components | Free | 1 dep | |
| Avataravatar | nativeui | Components | Free | 1 dep | |
| Badgebadge | nativeui | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | nativeui | Components | Free | 2 deps | |
| Buttonbutton | nativeui | Components | Free | 2 deps | |
| Calendarcalendar | nativeui | Components | Free | 4 deps |
