Skip to content

Commit 9017593

Browse files
authored
feat: introduce header fade-in threshold (#17)
1 parent 018a888 commit 9017593

18 files changed

+287
-21
lines changed

docs/docs/01-getting-started.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Before using this package, please make sure that you install the correct version
2121
| 0.6.x | >= 0.65 | >= 2.11.0 | >= 4.1.0 | N/A |
2222
| 0.7.x | >= 0.65 | >= 2.0.0 | >= 4.1.0 | N/A |
2323
| 0.8.x | >= 0.65 | >= 2.0.0 | >= 4.1.0 | N/A |
24-
| 0.9.x | >= 0.65 | >= 2.0.0 | >= 4.1.0 | >= 3.2.0 |
24+
| >= 0.9.x | >= 0.65 | >= 2.0.0 | >= 4.1.0 | >= 3.2.0 |
2525

2626
## Pre-requisites
2727

docs/docs/03-api-reference/01-scroll-view-with-headers.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,28 @@ want to access the layout of the large header to calculate the height of the lar
8787
This property controls whether or not the header component is absolutely positioned. This is useful
8888
if you want to render a header component that allows for transparency.
8989

90+
**Note**: This is only available in version >= 0.9.0.
91+
9092
### initialAbsoluteHeaderHeight
9193

9294
This property is used when `absoluteHeader` is true. This is the initial height of the
9395
absolute header. Since the header's height is computed on its layout event, this is used
9496
to set the initial height of the header so that it doesn't jump when it is initially rendered.
97+
98+
**Note**: This is only available in version >= 0.9.0.
99+
100+
### headerFadeInThreshold
101+
102+
A number between 0 and 1 representing at what point the header should fade in,
103+
based on the percentage of the LargeHeader's height. For example, if this is set to 0.5,
104+
the header will fade in when the scroll position is at 50% of the LargeHeader's height.
105+
106+
Defaults to `1`.
107+
108+
**Note**: This is only available in version >= 0.10.0.
109+
110+
### disableLargeHeaderFadeAnim
111+
112+
Whether or not the LargeHeaderComponent should fade in and out. Defaults to `false`.
113+
114+
**Note**: This is only available in version >= 0.10.0.

docs/docs/03-api-reference/02-flat-list-with-headers.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,28 @@ want to access the layout of the large header to calculate the height of the lar
8787
This property controls whether or not the header component is absolutely positioned. This is useful
8888
if you want to render a header component that allows for transparency.
8989

90+
**Note**: This is only available in version >= 0.9.0.
91+
9092
### initialAbsoluteHeaderHeight
9193

9294
This property is used when `absoluteHeader` is true. This is the initial height of the
9395
absolute header. Since the header's height is computed on its layout event, this is used
9496
to set the initial height of the header so that it doesn't jump when it is initially rendered.
97+
98+
**Note**: This is only available in version >= 0.9.0.
99+
100+
### headerFadeInThreshold
101+
102+
A number between 0 and 1 representing at what point the header should fade in,
103+
based on the percentage of the LargeHeader's height. For example, if this is set to 0.5,
104+
the header will fade in when the scroll position is at 50% of the LargeHeader's height.
105+
106+
Defaults to `1`.
107+
108+
**Note**: This is only available in version >= 0.10.0.
109+
110+
### disableLargeHeaderFadeAnim
111+
112+
Whether or not the LargeHeaderComponent should fade in and out. Defaults to `false`.
113+
114+
**Note**: This is only available in version >= 0.10.0.

docs/docs/03-api-reference/03-section-list-with-headers.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,28 @@ want to access the layout of the large header to calculate the height of the lar
8787
This property controls whether or not the header component is absolutely positioned. This is useful
8888
if you want to render a header component that allows for transparency.
8989

90+
**Note**: This is only available in version >= 0.9.0.
91+
9092
### initialAbsoluteHeaderHeight
9193

9294
This property is used when `absoluteHeader` is true. This is the initial height of the
9395
absolute header. Since the header's height is computed on its layout event, this is used
9496
to set the initial height of the header so that it doesn't jump when it is initially rendered.
97+
98+
**Note**: This is only available in version >= 0.9.0.
99+
100+
### headerFadeInThreshold
101+
102+
A number between 0 and 1 representing at what point the header should fade in,
103+
based on the percentage of the LargeHeader's height. For example, if this is set to 0.5,
104+
the header will fade in when the scroll position is at 50% of the LargeHeader's height.
105+
106+
Defaults to `1`.
107+
108+
**Note**: This is only available in version >= 0.10.0.
109+
110+
### disableLargeHeaderFadeAnim
111+
112+
Whether or not the LargeHeaderComponent should fade in and out. Defaults to `false`.
113+
114+
**Note**: This is only available in version >= 0.10.0.

docs/docs/03-api-reference/04-flash-list-with-headers.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,28 @@ want to access the layout of the large header to calculate the height of the lar
9292
This property controls whether or not the header component is absolutely positioned. This is useful
9393
if you want to render a header component that allows for transparency.
9494

95+
**Note**: This is only available in version >= 0.9.0.
96+
9597
### initialAbsoluteHeaderHeight
9698

9799
This property is used when `absoluteHeader` is true. This is the initial height of the
98100
absolute header. Since the header's height is computed on its layout event, this is used
99101
to set the initial height of the header so that it doesn't jump when it is initially rendered.
102+
103+
**Note**: This is only available in version >= 0.9.0.
104+
105+
### headerFadeInThreshold
106+
107+
A number between 0 and 1 representing at what point the header should fade in,
108+
based on the percentage of the LargeHeader's height. For example, if this is set to 0.5,
109+
the header will fade in when the scroll position is at 50% of the LargeHeader's height.
110+
111+
Defaults to `1`.
112+
113+
**Note**: This is only available in version >= 0.10.0.
114+
115+
### disableLargeHeaderFadeAnim
116+
117+
Whether or not the LargeHeaderComponent should fade in and out. Defaults to `false`.
118+
119+
**Note**: This is only available in version >= 0.10.0.

docs/docs/03-api-reference/05-header.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ An animated value between 0 and 1 that indicates whether the header's children s
1919

2020
An optional style object to apply to the header's root container.
2121

22-
NOTE: Do not apply an `absolute` position to this container. Instead, use the `absoluteHeader` prop
22+
**Note**: Do not apply an `absolute` position to this container. Instead, use the `absoluteHeader` prop
2323
on any of the scroll containers to absolutely position the header.
2424

2525
### headerLeft
@@ -85,6 +85,8 @@ An optional width to use for the header's bottom border. Defaults to [StyleSheet
8585

8686
An optional component that can act as the surface of the header. Please ensure that the styling applied to the component includes `StyleSheet.absoluteFill` or `StyleSheet.absoluteFillObject` to ensure that the surface component fills the header.
8787

88+
**Note**: If you want to use a [BlurView](https://github.com/Kureev/react-native-blur#blurview) as the surface and want the content below to be seen under the surface, make sure you set [absoluteHeader](/docs/components/scroll-view-with-headers#absoluteHeader) to `true` on the scroll container.
89+
8890
#### Example
8991

9092
The following example will make the header have a **cyan** background when the user scrolls the scroll container up:

example/src/navigation/AppNavigation.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
SimpleUsageScreen,
1111
SurfaceComponentUsageScreen,
1212
TwitterProfileScreen,
13-
AbsoluteHeaderBlurSurface,
13+
AbsoluteHeaderBlurSurfaceUsageScreen,
14+
ArbitraryYTransitionHeaderUsageScreen,
1415
} from '../screens';
1516

1617
const Stack = createNativeStackNavigator<RootStackParamList>();
@@ -34,7 +35,11 @@ export default () => (
3435
<Stack.Screen name="TwitterProfileScreen" component={TwitterProfileScreen} />
3536
<Stack.Screen
3637
name="AbsoluteHeaderBlurSurfaceUsageScreen"
37-
component={AbsoluteHeaderBlurSurface}
38+
component={AbsoluteHeaderBlurSurfaceUsageScreen}
39+
/>
40+
<Stack.Screen
41+
name="ArbitraryYTransitionHeaderUsageScreen"
42+
component={ArbitraryYTransitionHeaderUsageScreen}
3843
/>
3944
</Stack.Navigator>
4045
);

example/src/navigation/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type RootStackParamList = {
1111
TwitterProfileScreen: undefined;
1212
HeaderSurfaceComponentUsageScreen: undefined;
1313
AbsoluteHeaderBlurSurfaceUsageScreen: undefined;
14+
ArbitraryYTransitionHeaderUsageScreen: undefined;
1415
};
1516

1617
// Overrides the typing for useNavigation in @react-navigation/native to support the internal
@@ -59,3 +60,8 @@ export type AbsoluteHeaderBlurSurfaceUsageScreenNavigationProps = NativeStackScr
5960
RootStackParamList,
6061
'AbsoluteHeaderBlurSurfaceUsageScreen'
6162
>;
63+
64+
export type ArbitraryYTransitionHeaderUsageScreenNavigationProps = NativeStackScreenProps<
65+
RootStackParamList,
66+
'ArbitraryYTransitionHeaderUsageScreen'
67+
>;

example/src/screens/Home.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const SCREEN_LIST_CONFIG: ScreenConfigItem[] = [
5454
route: 'AbsoluteHeaderBlurSurfaceUsageScreen',
5555
description: 'An example of an absolutely-positioned header with a BlurView surface.',
5656
},
57+
{
58+
name: 'Arbitrary Y Transition Header',
59+
route: 'ArbitraryYTransitionHeaderUsageScreen',
60+
description:
61+
'An example of a header that transitions based on the scroll position of the ScrollView, instead of passing the height of the large header before animating.',
62+
},
5763
];
5864

5965
const HeaderComponent: React.FC<ScrollHeaderProps> = ({ showNavBar }) => {

example/src/screens/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export { default as FlashListUsageScreen } from './usage/FlashList';
88
export { default as SectionListUsageScreen } from './usage/SectionList';
99
export { default as SurfaceComponentUsageScreen } from './usage/SurfaceComponent';
1010
export { default as TwitterProfileScreen } from './usage/TwitterProfile';
11-
export { default as AbsoluteHeaderBlurSurface } from './usage/AbsoluteHeaderBlurSurface';
11+
export { default as AbsoluteHeaderBlurSurfaceUsageScreen } from './usage/AbsoluteHeaderBlurSurface';
12+
export { default as ArbitraryYTransitionHeaderUsageScreen } from './usage/ArbitraryYTransitionHeader';

0 commit comments

Comments
 (0)