ScrollShadow (스크롤 그림자)
ScrollShadow는 스크롤 위치와 오버플로에 따라 스크롤 가능한 콘텐츠에 동적 그라데이션 그림자를 추가하는 컴포넌트예요. 자식의 방향을 자동 감지하고, size, visibility, color prop으로 그림자의 크기, 표시 방식, 색상을 조절할 수 있어요.
출처: 문서
본문
Import
import { ScrollShadow } from 'heroui-native';
Anatomy
<ScrollShadow LinearGradientComponent={LinearGradient}>
<ScrollView>...</ScrollView>
</ScrollShadow>
- ScrollShadow: 스크롤 가능한 컴포넌트를 감싸고, 스크롤 위치와 콘텐츠 오버플로에 따라 가장자리에 동적 그라데이션 그림자를 추가하는 메인 컨테이너예요. 스크롤 방향(가로/세로)을 자동 감지하고 그림자 가시성을 관리해요.
- LinearGradientComponent: 필수 prop으로, 호환되는 라이브러리(expo-linear-gradient, react-native-linear-gradient 등)의 LinearGradient 컴포넌트를 받아 그라데이션 그림자를 렌더링해요.
Usage
Basic Usage
스크롤 가능한 컴포넌트를 감싸면 가장자리 그림자가 자동으로 추가돼요.
<ScrollShadow LinearGradientComponent={LinearGradient}>
<ScrollView>...</ScrollView>
</ScrollShadow>
Horizontal Scrolling
컴포넌트는 자식의 horizontal prop에서 가로 스크롤을 자동 감지해요.
<ScrollShadow LinearGradientComponent={LinearGradient}>
<FlatList horizontal data={data} renderItem={...} />
</ScrollShadow>
Custom Shadow Size
size prop으로 그라데이션 그림자의 높이/너비를 제어해요.
<ScrollShadow size={100} LinearGradientComponent={LinearGradient}>
<ScrollView>...</ScrollView>
</ScrollShadow>
Visibility Control
visibility prop으로 표시할 그림자를 지정해요.
<ScrollShadow visibility="top" LinearGradientComponent={LinearGradient}>
<ScrollView>...</ScrollView>
</ScrollShadow>
<ScrollShadow visibility="bottom" LinearGradientComponent={LinearGradient}>
<ScrollView>...</ScrollView>
</ScrollShadow>
<ScrollShadow visibility="none" LinearGradientComponent={LinearGradient}>
<ScrollView>...</ScrollView>
</ScrollShadow>
Custom Shadow Color
테마의 배경색을 사용하는 기본 그림자 색상을 재정의해요.
<ScrollShadow color="#ffffff" LinearGradientComponent={LinearGradient}>
<ScrollView>...</ScrollView>
</ScrollShadow>
With Custom Scroll Handler
Important: ScrollShadow는 내부적으로 자식을 Reanimated 애니메이션 컴포넌트로 변환해요. onScroll prop을 사용해야 한다면 react-native-reanimated의 useAnimatedScrollHandler를 사용해야 해요.
import { LinearGradient } from 'expo-linear-gradient';
import Animated, { useAnimatedScrollHandler } from 'react-native-reanimated';
const scrollHandler = useAnimatedScrollHandler({
onScroll: (event) => {
console.log(event.contentOffset.y);
},
});
<ScrollShadow LinearGradientComponent={LinearGradient}>
<Animated.ScrollView onScroll={scrollHandler}>...</Animated.ScrollView>
</ScrollShadow>;
Example
import { ScrollShadow, Surface } from 'heroui-native';
import { LinearGradient } from 'expo-linear-gradient';
import { FlatList, ScrollView, Text, View } from 'react-native';
export default function ScrollShadowExample() {
const horizontalData = Array.from({ length: 10 }, (_, i) => ({
id: i,
title: `Card ${i + 1}`,
}));
return (
<View className="flex-1 bg-background">
<Text className="px-5 py-3 text-lg font-semibold">Horizontal List</Text>
<ScrollShadow LinearGradientComponent={LinearGradient}>
<FlatList
data={horizontalData}
horizontal
renderItem={({ item }) => (
<Surface variant="2" className="w-32 h-24 justify-center px-4">
<Text>{item.title}</Text>
</Surface>
)}
showsHorizontalScrollIndicator={false}
contentContainerClassName="p-5 gap-4"
/>
</ScrollShadow>
<Text className="px-5 py-3 text-lg font-semibold">Vertical Content</Text>
<ScrollShadow
size={80}
className="h-48"
LinearGradientComponent={LinearGradient}
>
<ScrollView
contentContainerClassName="p-5"
showsVerticalScrollIndicator={false}
>
<Text className="mb-4 text-2xl font-bold">Long Content</Text>
<Text className="mb-4 text-base leading-6">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud exercitation ullamco laboris.
</Text>
<Text className="mb-4 text-base leading-6">
Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa
quae ab illo inventore veritatis et quasi architecto beatae vitae.
</Text>
</ScrollView>
</ScrollShadow>
</View>
);
}
GitHub 저장소에서 더 많은 예제를 볼 수 있어요.
API Reference
ScrollShadow
| prop | type | default | description |
|---|---|---|---|
children |
React.ReactElement |
- | 그림자를 추가할 스크롤 가능한 컴포넌트. 단일 React 요소여야 해요 (ScrollView, FlatList 등) |
LinearGradientComponent |
ComponentType<LinearGradientProps> |
required | 호환되는 라이브러리(expo-linear-gradient, react-native-linear-gradient 등)의 LinearGradient 컴포넌트 |
size |
number |
50 |
픽셀 단위의 그라데이션 그림자 크기(높이/너비) |
orientation |
'horizontal' | 'vertical' |
auto-detect | 스크롤 그림자의 방향. 제공하지 않으면 자식의 horizontal prop에서 자동 감지해요 |
visibility |
'auto' | 'top' | 'bottom' | 'left' | 'right' | 'both' | 'none' |
'auto' |
그림자의 표시 모드. 'auto'는 스크롤 위치와 콘텐츠 오버플로에 따라 그림자를 표시해요 |
color |
string |
theme color | 그라데이션 그림자의 커스텀 색상. 제공하지 않으면 테마의 배경색을 사용해요 |
isEnabled |
boolean |
true |
그림자 효과가 활성화되었는지 여부 |
animation |
ScrollShadowRootAnimation |
- | 애니메이션 구성 |
className |
string |
- | 컨테이너에 적용할 추가 CSS 클래스 |
...ViewProps |
ViewProps |
- | 모든 표준 React Native View prop을 지원해요 |
ScrollShadowRootAnimation
ScrollShadow 컴포넌트를 위한 애니메이션 구성이에요. 값은 다음과 같아요:
false또는"disabled": 루트 애니메이션만 비활성화"disable-all": children을 포함한 모든 애니메이션 비활성화true또는undefined: 기본 애니메이션 사용object: 커스텀 애니메이션 구성
| prop | type | default | description |
|---|---|---|---|
state |
'disabled' | 'disable-all' | boolean |
- | 속성을 커스터마이징하는 동안 애니메이션 비활성화 |
opacity.value |
[number, number] |
[0, 1] |
Opacity values [initial, active].For bottom/right shadow, this is reversed |
LinearGradientProps
LinearGradientComponent prop은 다음 prop을 받는 컴포넌트를 기대해요:
| prop | type | description |
|---|---|---|
colors |
any |
그라데이션을 위한 색상 배열 |
locations |
any (optional) |
각 그라데이션 색상 정지점의 위치를 정의하는 숫자 배열 |
start |
any (optional) |
그라데이션의 시작점 (예: { x: 0, y: 0 }) |
end |
any (optional) |
그라데이션의 끝점 (예: { x: 1, y: 0 }) |
style |
StyleProp<ViewStyle> (optional) |
그라데이션 뷰에 적용할 스타일 |
Special Notes
Important: ScrollShadow는 내부적으로 자식을 Reanimated 애니메이션 컴포넌트로 변환해요. 스크롤 가능한 컴포넌트에서 onScroll prop을 사용해야 한다면, 표준 onScroll prop 대신 react-native-reanimated의 useAnimatedScrollHandler를 사용해야 해요.