팝오버 (Popover)
Popover 컴포넌트는 트리거 요소 위에 떠 있는 콘텐츠 패널을 표시하는 오버레이 컴포넌트예요. 포지셔닝, 충돌 감지, 화살표, 타이틀/설명, 그리고 모바일 친화적인 바텀 시트 표현까지 다양한 기능을 제공해요.
출처: 문서
본문
Import
import { Popover } from 'heroui-native';
Anatomy
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content>
<Popover.Arrow />
<Popover.Close />
<Popover.Title>...</Popover.Title>
<Popover.Description>...</Popover.Description>
</Popover.Content>
</Popover.Portal>
</Popover>
- Popover: 열림/닫힘 상태와 포지셔닝을 관리하고 자식 컴포넌트에 컨텍스트를 제공하는 메인 컨테이너예요.
- Popover.Trigger: 팝오버 표시 여부를 토글하는 클릭 가능한 요소예요. press 핸들러로 모든 자식 요소를 감싸요.
- Popover.Portal: 팝오버 콘텐츠를 다른 콘텐츠 위의 포털 레이어에 렌더링해요. 올바른 스태킹과 포지셔닝을 보장해요.
- Popover.Overlay: 선택적 배경 오버레이예요. 바깥 클릭을 캡처하도록 투명하거나 반투명할 수 있어요.
- Popover.Content: 포지셔닝, 스타일링, 충돌 감지를 포함한 팝오버 콘텐츠 컨테이너예요. popover와 bottom-sheet 두 가지 표현을 모두 지원해요.
- Popover.Arrow: 트리거를 가리키는 선택적 화살표 요소예요. placement에 따라 자동으로 배치됩니다.
- Popover.Close: 팝오버의 닫기 버튼이에요. 커스텀 자식 또는 기본 닫기 아이콘을 사용할 수 있어요.
- Popover.Title: 미리 스타일링된 타이포그래피가 있는 선택적 타이틀 텍스트예요.
- Popover.Description: muted 스타일링이 있는 선택적 설명 텍스트예요.
Usage
기본 사용법 (Basic Usage)
Popover 컴포넌트는 복합 파트를 사용해 떠 있는 콘텐츠 패널을 만들어요.
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover">...</Popover.Content>
</Popover.Portal>
</Popover>
타이틀과 설명과 함께 (With Title and Description)
팝오버 콘텐츠를 타이틀과 설명으로 구성해 정보 계층을 더 잘 만드세요.
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover">
<Popover.Close />
<Popover.Title>...</Popover.Title>
<Popover.Description>...</Popover.Description>
</Popover.Content>
</Popover.Portal>
</Popover>
화살표와 함께 (With Arrow)
더 나은 시각적 연결을 위해 트리거 요소를 가리키는 화살표를 추가해요.
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover" placement="top">
<Popover.Arrow />
...
</Popover.Content>
</Popover.Portal>
</Popover>
참고: 를 사용할 때는
Popover.Content에 테두리를 적용해야 해요. 예를 들어border border-border클래스를 사용하세요. 이렇게 해야 화살표가 콘텐츠 테두리와 시각적으로 올바르게 연결돼요.
너비 제어 (Width Control)
width prop으로 팝오버 콘텐츠의 너비를 제어해요.
{
/* Fixed width in pixels */
}
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover" width={320}>
...
</Popover.Content>
</Popover.Portal>
</Popover>;
{
/* Match trigger width */
}
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover" width="trigger">
...
</Popover.Content>
</Popover.Portal>
</Popover>;
{
/* Full width (100%) */
}
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover" width="full">
...
</Popover.Content>
</Popover.Portal>
</Popover>;
{
/* Auto-size to content (default) */
}
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover" width="content-fit">
...
</Popover.Content>
</Popover.Portal>
</Popover>;
바텀 시트 표현 (Bottom Sheet Presentation)
모바일에 최적화된 상호작용 패턴을 위해 바텀 시트 표현을 사용해요.
중요:
Popover.Content의presentationprop은Popover.Root의presentationprop과 일치해야 해요. 개발 모드에서 불일치하면 오류가 발생합니다.
<Popover presentation="bottom-sheet">
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="bottom-sheet">
<Popover.Title>...</Popover.Title>
<Popover.Description>...</Popover.Description>
<Button>Close</Button>
</Popover.Content>
</Popover.Portal>
</Popover>
배치 옵션 (Placement Options)
트리거 요소를 기준으로 팝오버가 나타나는 위치를 제어해요.
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Content presentation="popover" placement="left">
...
</Popover.Content>
</Popover.Portal>
</Popover>
정렬 옵션 (Alignment Options)
배치 축을 따라 콘텐츠 정렬을 미세 조정해요.
<Popover>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Content presentation="popover" placement="top" align="start">
...
</Popover.Content>
</Popover.Portal>
</Popover>
커스텀 애니메이션 (Custom Animation)
Popover.Root의 animation prop을 사용해 열림/닫힘 전환에 커스텀 애니메이션을 구성해요.
<Popover
animation={{
entering: {
type: 'spring',
config: { damping: 15, stiffness: 300 },
},
exiting: {
type: 'timing',
config: { duration: 200 },
},
}}
>
<Popover.Trigger>...</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover">...</Popover.Content>
</Popover.Portal>
</Popover>
프로그래매틱 제어 (Programmatic control)
// Open or close popover programmatically using ref
const popoverRef = useRef<PopoverTriggerRef>(null);
// Open programmatically
popoverRef.current?.open();
// Close programmatically
popoverRef.current?.close();
// Full example
<Popover>
<Popover.Trigger ref={popoverRef} asChild>
<Button>Trigger</Button>
</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content presentation="popover">
<Text>Content</Text>
<Button onPress={() => popoverRef.current?.close()}>Close</Button>
</Popover.Content>
</Popover.Portal>
</Popover>;
Example
import { Ionicons } from '@expo/vector-icons';
import { Button, Popover, useThemeColor } from 'heroui-native';
import { Text, View } from 'react-native';
export default function PopoverExample() {
const themeColorMuted = useThemeColor('muted');
return (
<Popover>
<Popover.Trigger asChild>
<Button variant="tertiary" size="sm">
<Ionicons
name="information-circle"
size={20}
color={themeColorMuted}
/>
<Button.Label>Show Info</Button.Label>
</Button>
</Popover.Trigger>
<Popover.Portal>
<Popover.Overlay />
<Popover.Content
presentation="popover"
width={320}
className="gap-1 rounded-xl px-6 py-4"
>
<Popover.Close className="absolute top-3 right-3 z-50" />
<Popover.Title>Information</Popover.Title>
<Popover.Description>
This popover includes a title and description to provide more
structured information to users.
</Popover.Description>
</Popover.Content>
</Popover.Portal>
</Popover>
);
}
더 많은 예시는 GitHub 저장소에서 찾을 수 있어요.
API Reference
Popover
| prop | type | default | description |
|---|---|---|---|
children |
ReactNode |
- | 팝오버 안에 렌더링할 자식 요소 |
isOpen |
boolean |
- | 팝오버가 열렸는지 여부 (제어 모드) |
isDefaultOpen |
boolean |
- | 처음 렌더링될 때 팝오버의 열린 상태 (비제어 모드) |
onOpenChange |
(isOpen: boolean) => void |
- | 팝오버 열림 상태가 변경될 때의 콜백 |
animation |
AnimationRootDisableAll |
- | 애니메이션 구성. false, "disabled", "disable-all", true, undefined가 될 수 있음 |
presentation |
'popover' | 'bottom-sheet' |
'popover' |
팝오버 콘텐츠의 표현 모드 |
asChild |
boolean |
false |
자식 요소로 렌더링할지 여부 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
AnimationRootDisableAll
팝오버 루트 컴포넌트의 애니메이션 구성이에요. 값으로는:
false또는"disabled": 루트 애니메이션만 비활성화"disable-all": 자식을 포함한 모든 애니메이션 비활성화true또는undefined: 기본 애니메이션 사용
Popover.Trigger
| prop | type | default | description |
|---|---|---|---|
children |
ReactNode |
- | 트리거 요소 콘텐츠 |
className |
string |
- | 트리거의 추가 CSS 클래스 |
asChild |
boolean |
true |
자식 요소로 렌더링할지 여부 |
...PressableProps |
PressableProps |
- | 모든 표준 React Native Pressable props 지원 |
Popover.Portal
| prop | type | default | description |
|---|---|---|---|
children |
ReactNode |
- | 포털 콘텐츠 (필수) |
disableFullWindowOverlay |
boolean |
false |
iOS에서 true면 FullWindowOverlay 대신 View 사용. 요소 검사기 활성화; 네이티브 모달 위에 오버레이가 나타나지 않음 |
unstable_accessibilityContainerViewIsModal |
boolean |
false |
VoiceOver가 오버레이 창을 모달 컨테이너로 취급할지 제어. true면 VoiceOver가 오버레이 안의 요소로 제한됨. iOS 전용. 불안정: react-native-screens 업데이트로 변경될 수 있음 |
hostName |
string |
- | 포털 호스트 요소의 선택적 이름 |
forceMount |
boolean |
- | DOM에서 컴포넌트를 강제 마운트할지 여부 |
className |
string |
- | 포털 컨테이너의 추가 CSS 클래스 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
Popover.Overlay
| prop | type | default | description |
|---|---|---|---|
className |
string |
- | 오버레이의 추가 CSS 클래스 |
closeOnPress |
boolean |
true |
오버레이를 누를 때 팝오버를 닫을지 여부 |
forceMount |
boolean |
- | DOM에서 컴포넌트를 강제 마운트할지 여부 |
animation |
PopoverOverlayAnimation |
- | 애니메이션 구성 |
isAnimatedStyleActive |
boolean |
true |
애니메이션 스타일(react-native-reanimated) 활성화 여부 |
asChild |
boolean |
false |
자식 요소로 렌더링할지 여부 |
...Animated.ViewProps |
Animated.ViewProps |
- | 모든 Reanimated Animated.View props 지원 |
PopoverOverlayAnimation
팝오버 오버레이 컴포넌트의 애니메이션 구성이에요. 값으로는:
false또는"disabled": 모든 애니메이션 비활성화true또는undefined: 기본 애니메이션 사용object: 커스텀 애니메이션 구성
| prop | type | default | description |
|---|---|---|---|
state |
'disabled' | boolean |
- | 속성을 커스터마이징하는 동안 애니메이션 비활성화 |
opacity.value |
[number, number, number] |
[0, 1, 0] |
opacity 값 [idle, open, close] - bottom-sheet/dialog 표현에 적용됨 |
entering |
EntryOrExitLayoutType |
FadeIn with duration 200ms | 등장 전환용 커스텀 Keyframe 애니메이션 - popover 표현에 적용됨 |
exiting |
EntryOrExitLayoutType |
FadeOut with duration 150ms | 퇴장 전환용 커스텀 Keyframe 애니메이션 - popover 표현에 적용됨 |
Popover.Content (Popover 표현)
| prop | type | default | description |
|---|---|---|---|
children |
ReactNode |
- | 팝오버 콘텐츠 |
presentation |
'popover' |
'popover' |
표현 모드 - Popover.Root presentation prop과 일치해야 함. 제공되지 않으면 'popover' 기본값 |
width |
number | 'trigger' | 'content-fit' | 'full' |
'content-fit' |
콘텐츠의 너비 크기 전략 |
placement |
'top' | 'bottom' | 'left' | 'right' |
'bottom' |
트리거 기준 팝오버의 배치 |
align |
'start' | 'center' | 'end' |
'center' |
배치 축을 따른 정렬 |
avoidCollisions |
boolean |
true |
뷰포트 가장자리에 가까울 때 배치를 뒤집을지 여부 |
offset |
number |
9 |
트리거 요소로부터의 거리(픽셀) |
alignOffset |
number |
0 |
정렬 축을 따른 오프셋(픽셀) |
disablePositioningStyle |
boolean |
false |
자동 포지셔닝 스타일을 비활성화할지 여부 |
forceMount |
boolean |
- | DOM에서 컴포넌트를 강제 마운트할지 여부 |
insets |
Insets |
- | 포지셔닝 시 존중할 화면 가장자리 인셋 |
className |
string |
- | 콘텐츠 컨테이너의 추가 CSS 클래스 |
animation |
PopupPopoverContentAnimation |
- | 애니메이션 구성 |
isAnimatedStyleActive |
boolean |
true |
애니메이션 스타일(react-native-reanimated) 활성화 여부 |
asChild |
boolean |
false |
자식 요소로 렌더링할지 여부 |
...Animated.ViewProps |
Animated.ViewProps |
- | 모든 Reanimated Animated.View props 지원 |
Popover.Content (Bottom Sheet 표현)
| prop | type | default | description |
|---|---|---|---|
children |
ReactNode |
- | 바텀 시트 콘텐츠 |
presentation |
'bottom-sheet' |
- | 표현 모드 - 'bottom-sheet'여야 하며 Popover.Root presentation prop과 일치해야 함 (필수) |
contentContainerClassName |
string |
- | 콘텐츠 컨테이너의 추가 CSS 클래스 |
contentContainerProps |
BottomSheetViewProps |
- | 콘텐츠 컨테이너의 props |
enablePanDownToClose |
boolean |
true |
아래로 패닝 제스처로 시트를 닫을지 여부 |
backgroundStyle |
ViewStyle |
- | 바텀 시트 배경 스타일 |
handleIndicatorStyle |
ViewStyle |
- | 바텀 시트 핸들 표시기 스타일 |
...BottomSheetProps |
BottomSheetProps |
- | 모든 @gorhom/bottom-sheet props 지원 |
PopupPopoverContentAnimation
팝오버 콘텐츠 컴포넌트(popover 표현)의 애니메이션 구성이에요. 값으로는:
false또는"disabled": 모든 애니메이션 비활성화true또는undefined: 기본 애니메이션 사용object: 커스텀 애니메이션 구성
| prop | type | default | description |
|---|---|---|---|
state |
'disabled' | boolean |
- | 속성을 커스터마이징하는 동안 애니메이션 비활성화 |
entering |
EntryOrExitLayoutType |
translateY/translateX, scale, opacity 포함 Keyframe (200ms) | 등장 전환용 커스텀 Keyframe 애니메이션 |
exiting |
EntryOrExitLayoutType |
등장 애니메이션을 미러링하는 Keyframe (150ms) | 퇴장 전환용 커스텀 Keyframe 애니메이션 |
Popover.Arrow
| prop | type | default | description |
|---|---|---|---|
className |
string |
- | 화살표의 추가 CSS 클래스 |
height |
number |
12 |
화살표 높이(픽셀) |
width |
number |
20 |
화살표 너비(픽셀) |
fill |
string |
- | 화살표 채우기 색상 (기본: 콘텐츠 배경) |
stroke |
string |
- | 화살표 테두리(stroke) 색상 (기본: 콘텐츠 테두리 색상) |
strokeWidth |
number |
1 |
화살표 테두리 두께(픽셀) |
strokeBaselineInset |
number |
1 |
stroke 정렬을 위한 기준선 인셋(픽셀) |
placement |
'top' | 'bottom' | 'left' | 'right' |
- | 팝오버의 배치 (콘텐츠에서 상속) |
children |
ReactNode |
- | 커스텀 화살표 콘텐츠 (기본 SVG 화살표 대체) |
style |
StyleProp |
- | 화살표 컨테이너의 추가 스타일 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View props 지원 |
Popover.Close
Popover.Close는 CloseButton을 확장하고, 눌리면 팝오버 닫기를 자동으로 처리해요.
Popover.Title
| prop | type | default | description |
|---|---|---|---|
children |
ReactNode |
- | 타이틀 텍스트 콘텐츠 |
className |
string |
- | 타이틀의 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 React Native Text props 지원 |
Popover.Description
| prop | type | default | description |
|---|---|---|---|
children |
ReactNode |
- | 설명 텍스트 콘텐츠 |
className |
string |
- | 설명의 추가 CSS 클래스 |
...TextProps |
TextProps |
- | 모든 표준 React Native Text props 지원 |
Hooks
usePopover
커스텀 컴포넌트 또는 복합 컴포넌트에서 팝오버 컨텍스트 값에 접근하는 훅이에요.
import { usePopover } from 'heroui-native';
const CustomContent = () => {
const { isOpen, onOpenChange, triggerPosition } = usePopover();
// ... your implementation
};
반환: UsePopoverReturn
| property | type | description |
|---|---|---|
isOpen |
boolean |
팝오버가 현재 열렸는지 여부 |
onOpenChange |
(open: boolean) => void |
팝오버 열림 상태를 변경하는 콜백 함수 |
isDefaultOpen |
boolean | undefined |
팝오버가 기본적으로 열려 있어야 하는지 여부 (비제어 모드) |
isDisabled |
boolean | undefined |
팝오버가 비활성화되었는지 여부 |
triggerPosition |
LayoutPosition | null |
뷰포트 기준 트리거 요소의 위치 |
setTriggerPosition |
(triggerPosition: LayoutPosition | null) => void |
트리거 요소의 위치를 업데이트하는 함수 |
contentLayout |
LayoutRectangle | null |
팝오버 콘텐츠의 레이아웃 측정값 |
setContentLayout |
(contentLayout: LayoutRectangle | null) => void |
콘텐츠 레이아웃 측정값을 업데이트하는 함수 |
nativeID |
string |
팝오버 인스턴스의 고유 식별자 |
참고: 이 훅은 Popover 컴포넌트 안에서 사용해야 해요. 팝오버 컨텍스트 밖에서 호출하면 오류가 발생합니다.
usePopoverAnimation
커스텀 컴포넌트 또는 복합 컴포넌트에서 팝오버 애니메이션 상태 값에 접근하는 훅이에요.
import { usePopoverAnimation } from 'heroui-native';
const CustomContent = () => {
const { progress, isDragging } = usePopoverAnimation();
// ... your implementation
};
반환: UsePopoverAnimationReturn
| property | type | description |
|---|---|---|
progress |
SharedValue<number> |
팝오버 애니메이션의 진행 값 (0=idle, 1=open, 2=close) |
isDragging |
SharedValue<boolean> |
드래그 상태 공유 값 |
참고: 이 훅은 Popover 컴포넌트 안에서 사용해야 해요. 팝오버 애니메이션 컨텍스트 밖에서 호출하면 오류가 발생합니다.
특별 참고 사항 (Special Notes)
요소 검사기 (Element Inspector, iOS)
Popover는 iOS에서 FullWindowOverlay를 사용해요. 개발 중 React Native 요소 검사기를 활성화하려면 Popover.Portal에 disableFullWindowOverlay={true}를 설정해요. 단점: 비활성화하면 팝오버가 네이티브 모달 위에 나타나지 않아요.
네이티브 모달 (Native Modal, iOS)
Popover가 네이티브 모달(presentation: 'modal' | 'formSheet' | 'pageSheet')로 표시된 화면 안에서 열리면, 팝오버 콘텐츠가 위로 이동해 렌더링될 수 있어요. 새 아키텍처(Fabric)에서 react-native-screens는 RNSModalScreen을 Fabric 루트로 표시하므로, 트리거의 위치는 모달의 원점을 기준으로 보고되는 반면 FullWindowOverlay(팝오버가 마운트되는 곳)는 iOS 애플리케이션 창에 고정됩니다. safeAreaInsets.top을 offset에 더해 보정해요:
import { useSafeAreaInsets } from 'react-native-safe-area-context';
const insets = useSafeAreaInsets();
<Popover.Content presentation="popover" offset={insets.top + 20}>
...
</Popover.Content>;