Skip to content

Commit 5fd721a

Browse files
authored
feat: enable standalone foreground component prop (#3)
* feat: render only foreground * feat: setup example
1 parent fea985c commit 5fd721a

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

example/src/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SafeAreaViewExample } from './screens/SafeAreaViewExample';
77
import { SafeAreaProvider } from 'react-native-safe-area-context';
88
import type { RootStackParamList } from './types';
99
import { ImageForegroundExample } from './screens/ImageForegroundExample';
10+
import { OnlyForegroundExample } from './screens/OnlyForegroundExample';
1011

1112
const App = () => {
1213
const Stack = createNativeStackNavigator<RootStackParamList>();
@@ -31,6 +32,10 @@ const App = () => {
3132
name="ImageForegroundExample"
3233
component={ImageForegroundExample}
3334
/>
35+
<Stack.Screen
36+
name="OnlyForegroundExample"
37+
component={OnlyForegroundExample}
38+
/>
3439
</Stack.Navigator>
3540
</NavigationContainer>
3641
</SafeAreaProvider>

example/src/screens/ExamplesDirectory.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const ExamplesDirectory = ({ navigation }: Props) => {
1414
{ screen: SCREENS.OVERFLOW_HEADER_EXAMPLE },
1515
{ screen: SCREENS.SAFE_AREA_VIEW_EXAMPLE },
1616
{ screen: SCREENS.IMAGE_FOREGROUND_EXAMPLE },
17+
{ screen: SCREENS.ONLY_FOREGROUND_EXAMPLE },
1718
];
1819

1920
return (
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { AnimatedScrollView } from '@kanelloc/react-native-animated-header-scroll-view';
2+
import { Card, Header, OverflowHeaderComponent } from '../components';
3+
import * as React from 'react';
4+
import { ForegroundComponent } from '../components/ForegroundComponent';
5+
import { data, isIOS } from '../utils';
6+
7+
export const OnlyForegroundExample = () => {
8+
return (
9+
<AnimatedScrollView
10+
ForegroundComponent={<ForegroundComponent />}
11+
headerHeight={isIOS ? 90 : 70}
12+
OverflowHeaderComponent={<OverflowHeaderComponent />}
13+
HeaderComponent={<Header />}
14+
>
15+
{data.map((e) => {
16+
return <Card item={e} key={e} />;
17+
})}
18+
</AnimatedScrollView>
19+
);
20+
};

example/src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export type RootStackParamList = {
44
SafeAreaViewExample: undefined;
55
SimpleExample: undefined;
66
ImageForegroundExample: undefined;
7+
OnlyForegroundExample: undefined;
78
};

example/src/utils/enums.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export enum SCREENS {
33
OVERFLOW_HEADER_EXAMPLE = 'OverflowHeaderExample',
44
SAFE_AREA_VIEW_EXAMPLE = 'SafeAreaViewExample',
55
IMAGE_FOREGROUND_EXAMPLE = 'ImageForegroundExample',
6+
ONLY_FOREGROUND_EXAMPLE = 'OnlyForegroundExample',
67
}

src/components/AnimatedScrollView.tsx

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,40 @@ export const AnimatedScrollView = ({
4747
]}
4848
>
4949
{ForegroundComponent ? (
50-
<AnimatedImageBackground
51-
source={headerImage}
52-
style={[
53-
{ height: imageHeight, width: width * 1.2 },
54-
{
55-
transform: [
56-
{ scale },
57-
{ translateY: translateYUp },
58-
{ translateY: translateYDown },
59-
],
60-
},
61-
]}
62-
>
63-
{ForegroundComponent}
64-
</AnimatedImageBackground>
50+
<>
51+
{headerImage ? (
52+
<AnimatedImageBackground
53+
source={headerImage}
54+
style={[
55+
{ height: imageHeight, width: width * 1.2 },
56+
{
57+
transform: [
58+
{ scale },
59+
{ translateY: translateYUp },
60+
{ translateY: translateYDown },
61+
],
62+
},
63+
]}
64+
>
65+
{ForegroundComponent}
66+
</AnimatedImageBackground>
67+
) : (
68+
<Animated.View
69+
style={[
70+
{ height: imageHeight, width: width * 1.2 },
71+
{
72+
transform: [
73+
{ scale },
74+
{ translateY: translateYUp },
75+
{ translateY: translateYDown },
76+
],
77+
},
78+
]}
79+
>
80+
{ForegroundComponent}
81+
</Animated.View>
82+
)}
83+
</>
6584
) : (
6685
<Animated.Image
6786
source={headerImage}

0 commit comments

Comments
 (0)