Skip to content

Commit 5069e90

Browse files
committed
feat: introduce bottom border color interpolation
Key Highlights: - Introduce a new prop `initialBorderColor` in `Header` component to allow users to set the color of the bottom border. - Ensured that the bottom border color animates between the initial color and the final color when the scroll container is scrolled down.
1 parent 2bbb2a8 commit 5069e90

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ you should set this to `true`.
7373
An optional boolean to indicate whether the header should not have a bottom border. Defaults to
7474
`false`.
7575

76+
### initialBorderColor
77+
78+
An optional color to use for the header's bottom border color initially. When the user scrolls down,
79+
the color will animate to the supplied [borderColor](/docs/components/header#bordercolor). Defaults to `#E5E5E5`.
80+
7681
### borderColor
7782

7883
An optional color to use for the header's bottom border. Defaults to `#E5E5E5`.

example/src/screens/usage/Simple.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const HeaderComponent: React.FC<ScrollHeaderProps> = ({ showNavBar }) => {
2121
<Header
2222
showNavBar={showNavBar}
2323
headerCenterFadesIn={false}
24+
borderColor="red"
25+
initialBorderColor="blue"
2426
headerCenter={
2527
<Text style={styles.navBarTitle} numberOfLines={1}>
2628
Header
@@ -79,6 +81,8 @@ const Simple: React.FC<SimpleUsageScreenNavigationProps> = () => {
7981
HeaderComponent={HeaderComponent}
8082
LargeHeaderComponent={LargeHeaderComponent}
8183
LargeHeaderSubtitleComponent={LargeHeaderSubtitleComponent}
84+
automaticallyAdjustsScrollIndicatorInsets={false}
85+
scrollIndicatorInsets={{ bottom }}
8286
contentContainerStyle={{ paddingBottom: bottom }}
8387
refreshControl={
8488
<RefreshControl refreshing={refreshing} colors={['#8E8E93']} onRefresh={onRefresh} />

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@
151151
"singleQuote": true,
152152
"tabWidth": 2,
153153
"trailingComma": "es5",
154-
"useTabs": false
154+
"useTabs": false,
155+
"printWidth": 100
155156
},
156157
"react-native-builder-bob": {
157158
"source": "src",

src/components/headers/Header.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const Header: React.FC<HeaderProps> = ({
2323
noBottomBorder = false,
2424
ignoreTopSafeArea = false,
2525
borderColor,
26+
initialBorderColor,
2627
borderWidth,
2728
SurfaceComponent,
2829
}) => {
@@ -113,6 +114,7 @@ const Header: React.FC<HeaderProps> = ({
113114
<HeaderBottomBorder
114115
opacity={showNavBar}
115116
borderColor={borderColor}
117+
initialBorderColor={initialBorderColor}
116118
borderWidth={borderWidth}
117119
/>
118120
)}

src/components/headers/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ export interface HeaderProps {
107107
* @type {boolean}
108108
*/
109109
noBottomBorder?: boolean;
110+
/**
111+
* The color of the border when the header is not scrolled up.
112+
*
113+
* @default '#E5E5E5'
114+
* @type {string}
115+
*/
116+
initialBorderColor?: string;
110117
/**
111118
* The color of the bottom border.
112119
*

src/components/line/HeaderBottomBorder.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { StyleSheet, StyleProp, ViewStyle } from 'react-native';
3-
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
3+
import Animated, { interpolateColor, useAnimatedStyle } from 'react-native-reanimated';
44

55
interface HeaderBottomBorderProps {
66
/**
@@ -13,6 +13,10 @@ interface HeaderBottomBorderProps {
1313
* Style of the bottom border component.
1414
*/
1515
style?: StyleProp<ViewStyle>;
16+
/**
17+
*
18+
*/
19+
initialBorderColor?: string;
1620
/**
1721
* Color of the bottom border.
1822
*
@@ -30,21 +34,18 @@ interface HeaderBottomBorderProps {
3034
const HeaderBottomBorder: React.FC<HeaderBottomBorderProps> = ({
3135
opacity,
3236
style,
37+
initialBorderColor = '#E5E5E5',
3338
borderColor = '#E5E5E5',
3439
borderWidth = 1,
3540
}) => {
36-
const borderBottomStyle = useAnimatedStyle(() => ({ opacity: opacity.value }));
37-
38-
return (
39-
<Animated.View
40-
style={[
41-
styles.line,
42-
borderBottomStyle,
43-
{ height: borderWidth, backgroundColor: borderColor },
44-
style,
45-
]}
46-
/>
41+
const borderBottomStyle = useAnimatedStyle(
42+
() => ({
43+
backgroundColor: interpolateColor(opacity.value, [0, 1], [initialBorderColor, borderColor]),
44+
}),
45+
[initialBorderColor, borderColor]
4746
);
47+
48+
return <Animated.View style={[styles.line, borderBottomStyle, { height: borderWidth }, style]} />;
4849
};
4950

5051
export default HeaderBottomBorder;

0 commit comments

Comments
 (0)