본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Dialog (다이얼로그)

원문 보기 위키 갱신

Dialog는 애니메이션 전환과 제스처 기반 닫기를 지원하는 모달 오버레이 컴포넌트예요. 트리거, 포털, 오버레이, 콘텐츠로 구성된 복합 구조를 통해 제목과 설명, 닫기 버튼을 갖춘 다이얼로그를 쉽게 만들 수 있어요.

출처: 문서

본문

가져오기 (Import)

import { Dialog } from 'heroui-native';

구조 (Anatomy)

<Dialog>
  <Dialog.Trigger>...</Dialog.Trigger>
  <Dialog.Portal>
    <Dialog.Overlay>...</Dialog.Overlay>
    <Dialog.Content>
      <Dialog.Close>...</Dialog.Close>
      <Dialog.Title>...</Dialog.Title>
      <Dialog.Description>...</Dialog.Description>
    </Dialog.Content>
  </Dialog.Portal>
</Dialog>
  • Dialog: 열림 상태를 관리하고 자식 컴포넌트에 컨텍스트를 제공하는 루트 컴포넌트.
  • Dialog.Trigger: 누르면 다이얼로그를 여는 Pressable 요소.
  • Dialog.Portal: 다이얼로그 콘텐츠를 중앙 정렬 레이아웃과 애니메이션 제어와 함께 포털에 렌더링해요.
  • Dialog.Overlay: 다이얼로그 콘텐츠 뒤에 나타나는 배경 오버레이. 보통 누르면 다이얼로그를 닫아요.
  • Dialog.Content: 드래그로 닫기를 지원하는 제스처를 가진 메인 다이얼로그 컨테이너.
  • Dialog.Close: 다이얼로그의 닫기 버튼. 커스텀 자식을 받거나 기본 닫기 아이콘을 사용해요.
  • Dialog.Title: 의미론적 제목 역할을 가진 다이얼로그 제목 텍스트.
  • Dialog.Description: 추가 맥락을 제공하는 다이얼로그 설명 텍스트.

사용법 (Usage)

기본 다이얼로그 (Basic Dialog)

제목, 설명, 닫기 버튼이 있는 간단한 다이얼로그예요.

<Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
  <Dialog.Trigger asChild>
    <Button>Open Dialog</Button>
  </Dialog.Trigger>
  <Dialog.Portal>
    <Dialog.Overlay />
    <Dialog.Content>
      <Dialog.Close />
      <Dialog.Title>...</Dialog.Title>
      <Dialog.Description>...</Dialog.Description>
    </Dialog.Content>
  </Dialog.Portal>
</Dialog>

스크롤 가능한 콘텐츠 (Scrollable Content)

스크롤 뷰로 긴 콘텐츠를 처리해요.

<Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
  <Dialog.Trigger>...</Dialog.Trigger>
  <Dialog.Portal>
    <Dialog.Overlay />
    <Dialog.Content>
      <Dialog.Close />
      <Dialog.Title>...</Dialog.Title>
      <View className="h-[300px]">
        <ScrollView>...</ScrollView>
      </View>
    </Dialog.Content>
  </Dialog.Portal>
</Dialog>

블러 배경 (Blur Backdrop)

애니메이션 블러 배경이 있는 오버레이예요. iOS 전용이며 선택적 expo-blur 패키지가 필요해요. 다른 플랫폼(또는 패키지가 없을 때)은 기본 불투명 배경으로 대체돼요. 라이브러리 테마가 glass일 때는 기본적으로 블러 variant가 사용돼요.

<Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
  <Dialog.Trigger>...</Dialog.Trigger>
  <Dialog.Portal>
    <Dialog.Overlay variant="blur" blurViewProps={{ intensity: 60 }} />
    <Dialog.Content>...</Dialog.Content>
  </Dialog.Portal>
</Dialog>

폼 다이얼로그 (Form Dialog)

텍스트 입력과 키보드 처리가 있는 다이얼로그예요.

<Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
  <Dialog.Trigger>...</Dialog.Trigger>
  <Dialog.Portal>
    <Dialog.Overlay />
    <KeyboardAvoidingView behavior="padding">
      <Dialog.Content>
        <Dialog.Close />
        <Dialog.Title>...</Dialog.Title>
        <TextField>...</TextField>
        <Button onPress={handleSubmit}>Submit</Button>
      </Dialog.Content>
    </KeyboardAvoidingView>
  </Dialog.Portal>
</Dialog>

예제 (Example)

import { Button, Dialog } from 'heroui-native';
import { View } from 'react-native';
import { useState } from 'react';

export default function DialogExample() {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <Dialog isOpen={isOpen} onOpenChange={setIsOpen}>
      <Dialog.Trigger asChild>
        <Button variant="primary">Open Dialog</Button>
      </Dialog.Trigger>
      <Dialog.Portal>
        <Dialog.Overlay />
        <Dialog.Content>
          <Dialog.Close variant="ghost" />
          <View className="mb-5 gap-1.5">
            <Dialog.Title>Confirm Action</Dialog.Title>
            <Dialog.Description>
              Are you sure you want to proceed with this action? This cannot be
              undone.
            </Dialog.Description>
          </View>
          <View className="flex-row justify-end gap-3">
            <Button variant="ghost" size="sm" onPress={() => setIsOpen(false)}>
              Cancel
            </Button>
            <Button size="sm">Confirm</Button>
          </View>
        </Dialog.Content>
      </Dialog.Portal>
    </Dialog>
  );
}

더 많은 예제는 GitHub 저장소에서 찾을 수 있어요.

API 참고 (API Reference)

Dialog

prop type default description
children React.ReactNode - Dialog content and trigger elements
isOpen boolean - Controlled open state of the dialog
isDefaultOpen boolean false Initial open state when uncontrolled
animation AnimationRootDisableAll - Animation configuration
onOpenChange (value: boolean) => void - Callback when open state changes
...ViewProps ViewProps - All standard React Native View props are supported

AnimationRootDisableAll

다이얼로그 루트 컴포넌트의 애니메이션 설정이에요. 값은 다음과 같아요:

  • false 또는 "disabled": 루트 애니메이션만 비활성화
  • "disable-all": 자식을 포함한 모든 애니메이션 비활성화
  • true 또는 undefined: 기본 애니메이션 사용

Dialog.Trigger

prop type default description
children React.ReactNode - Trigger element content
asChild boolean - Render as child element without wrapper
...TouchableOpacityProps TouchableOpacityProps - All standard React Native TouchableOpacity props are supported

Dialog.Portal

prop type default description
children React.ReactNode - Portal content (overlay and dialog)
disableFullWindowOverlay boolean false When true on iOS, uses View instead of FullWindowOverlay. Enables element inspector; overlay won't appear above native modals
unstable_accessibilityContainerViewIsModal boolean false Controls whether VoiceOver treats the overlay window as a modal container. When true, VoiceOver is restricted to elements inside the overlay. iOS only. Unstable: may change with react-native-screens updates
className string - Additional CSS classes for portal container
style StyleProp<ViewStyle> - Additional styles for portal container
hostName string - Optional portal host name for specific container
forceMount boolean - Force mount when closed for animation purposes

Dialog.Overlay

prop type default description
children React.ReactNode - Custom overlay content
className string - Additional CSS classes for overlay
style ViewStyle - Additional styles for overlay container
animation DialogOverlayAnimation - Animation configuration
variant 'default' | 'blur' 'default' ('blur' when the library theme is glass) Overlay variant. 'blur' renders an animated blur backdrop (iOS only, requires expo-blur; falls back to 'default' otherwise)
blurViewProps BlurViewProps - Props forwarded to the BlurView rendered by the 'blur' variant. intensity sets the maximum animated blur intensity (default: 75 dark / 50 light)
isAnimatedStyleActive boolean true (false for the 'blur' variant) Whether animated styles (react-native-reanimated) are active
isCloseOnPress boolean true Whether pressing overlay closes dialog
forceMount boolean - Force mount when closed for animation purposes
...PressableProps PressableProps - All standard React Native Pressable props are supported

DialogOverlayAnimation

다이얼로그 오버레이 컴포넌트의 애니메이션 설정이에요. 값은 다음과 같아요:

  • false 또는 "disabled": 모든 애니메이션 비활성화
  • true 또는 undefined: 기본 애니메이션 사용
  • object: 커스텀 애니메이션 설정
prop type default description
state 'disabled' | boolean - Disable animations while customizing properties
opacity.value [number, number, number] [0, 1, 0] Opacity values [idle, open, close] (progress-based, for dialog presentation)
entering EntryOrExitLayoutType FadeIn.duration(200) Custom entering animation (for popover presentation)
exiting EntryOrExitLayoutType FadeOut.duration(150) Custom exiting animation (for popover presentation)

Dialog.Content

prop type default description
children React.ReactNode - Dialog content
className string - Additional CSS classes for content container
style StyleProp<ViewStyle> - Additional styles for content container
animation DialogContentAnimation - Animation configuration
isSwipeable boolean true Whether the dialog content can be swiped to dismiss
forceMount boolean - Force mount when closed for animation purposes
...Animated.ViewProps Animated.ViewProps - All Reanimated Animated.View props are supported

DialogContentAnimation

다이얼로그 콘텐츠 컴포넌트의 애니메이션 설정이에요. 값은 다음과 같아요:

  • false 또는 "disabled": 모든 애니메이션 비활성화
  • true 또는 undefined: 기본 애니메이션 사용
  • object: 커스텀 애니메이션 설정
prop type default description
state 'disabled' | boolean - Disable animations while customizing properties
entering EntryOrExitLayoutType Keyframe with scale: 0.96→1 and opacity: 0→1 (200ms, easing: Easing.out(Easing.ease)) Custom entering animation
exiting EntryOrExitLayoutType Keyframe with scale: 1→0.96 and opacity: 1→0 (150ms, easing: Easing.in(Easing.ease)) Custom exiting animation

Dialog.Close

Dialog.Close는 CloseButton을 확장하며, 누르면 다이얼로그 닫기를 자동으로 처리해요.

Dialog.Title

prop type default description
children React.ReactNode - Title content
className string - Additional CSS classes for title
...TextProps TextProps - All standard React Native Text props are supported

Dialog.Description

prop type default description
children React.ReactNode - Description content
className string - Additional CSS classes for description
...TextProps TextProps - All standard React Native Text props are supported

훅 (Hooks)

useDialog

Dialog 프리미티브 컨텍스트에 접근하는 훅이에요.

const { isOpen, onOpenChange } = useDialog();
property type description
isOpen boolean Current open state
onOpenChange (value: boolean) => void Function to change open state

useDialogAnimation

고급 커스터마이징을 위해 다이얼로그 애니메이션 컨텍스트에 접근하는 훅이에요.

const { progress, isDragging, isGestureReleaseAnimationRunning } =
  useDialogAnimation();
property type description
progress SharedValue<number> Animation progress (0=idle, 1=open, 2=close)
isDragging SharedValue<boolean> Whether dialog is being dragged
isGestureReleaseAnimationRunning SharedValue<boolean> Whether gesture release animation is running

특별 참고 (Special Notes)

요소 검사기 (Element Inspector, iOS)

Dialog는 iOS에서 FullWindowOverlay를 사용해요. 개발 중 React Native 요소 검사기를 활성화하려면 Dialog.Portal에 disableFullWindowOverlay={true}를 설정하세요. 단점: 비활성화하면 다이얼로그가 네이티브 모달 위에 표시되지 않아요.

더 알아보기 (Learn more)

  • Button, TextField와 함께 사용하는 폼 다이얼로그 패턴을 확인해 보세요.
  • 공식 HeroUI Native Dialog 문서에서 최신 정보를 확인할 수 있어요.