Dialog
nativeui/dialogFreeComponent
A dialog 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/dialog.jsonSource
1import * as React from "react";2import {3 View,4 Text,5 Pressable,6 Modal,7 TouchableWithoutFeedback,8 Platform,9 Animated,10 Dimensions,11 KeyboardAvoidingView,12 ScrollView,13} from "react-native";14import { cn } from "@/lib/utils";15import { Ionicons } from "@expo/vector-icons";1617interface DialogProps {18 children: React.ReactNode;19 className?: string;20 open?: boolean;21 onOpenChange?: (open: boolean) => void;22}2324interface DialogTriggerProps {25 children: React.ReactNode;26 className?: string;27 disabled?: boolean;28 asChild?: boolean;29}3031interface DialogContentProps {32 children: React.ReactNode;33 className?: string;34 showCloseButton?: boolean;35 onInteractOutside?: () => void;36}3738interface DialogHeaderProps {39 className?: string;40 children: React.ReactNode;41}4243interface DialogFooterProps {44 className?: string;45 children: React.ReactNode;46}4748interface DialogTitleProps {49 className?: string;50 children: React.ReactNode;51}5253interface DialogDescriptionProps {54 className?: string;55 children: React.ReactNode;56}5758interface DialogCloseProps {59 children: React.ReactElement<{ onPress?: (e: any) => void }>;60 className?: string;61}6263const DialogContext = React.createContext<{64 open: boolean;65 setOpen: (open: boolean) => void;66 handleClose?: () => void;67}>({68 open: false,69 setOpen: () => { },70});7172const Dialog = React.forwardRef<View, DialogProps>(73 ({ children, className, open = false, onOpenChange, ...props }, ref) => {74 const [internalOpen, setInternalOpen] = React.useState(false);7576 const isControlled = open !== undefined;77 const isOpen = isControlled ? open : internalOpen;7879 const setOpen = React.useCallback(80 (value: boolean) => {81 if (!isControlled) {82 setInternalOpen(value);83 }84 onOpenChange?.(value);85 },86 [isControlled, onOpenChange]87 );8889 return (90 <DialogContext.Provider value={{ open: isOpen, setOpen }}>91 <View ref={ref} className={cn("", className)} {...props}>92 {children}93 </View>94 </DialogContext.Provider>95 );96 }97);9899Dialog.displayName = "Dialog";100101const DialogTrigger = React.forwardRef<View, DialogTriggerProps>(102 (103 { children, className, disabled = false, asChild = false, ...props },104 ref105 ) => {106 const { setOpen } = React.useContext(DialogContext);107108 if (asChild) {109 const child = React.Children.only(children) as React.ReactElement<{110 onPress?: (e: any) => void;111 ref?: React.Ref<any>;112// … 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 |
