Skip to content

Commit

Permalink
feat: introduce bottom border color interpolation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
e-younan committed Apr 15, 2024
1 parent 2bbb2a8 commit d62f91b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
5 changes: 5 additions & 0 deletions docs/docs/03-api-reference/05-header.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ you should set this to `true`.
An optional boolean to indicate whether the header should not have a bottom border. Defaults to
`false`.

### initialBorderColor

An optional color to use for the header's bottom border color initially. When the user scrolls down,
the color will animate to the supplied [borderColor](/docs/components/header#bordercolor). Defaults to `#E5E5E5`.

### borderColor

An optional color to use for the header's bottom border. Defaults to `#E5E5E5`.
Expand Down
4 changes: 4 additions & 0 deletions example/src/screens/usage/Simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const HeaderComponent: React.FC<ScrollHeaderProps> = ({ showNavBar }) => {
<Header
showNavBar={showNavBar}
headerCenterFadesIn={false}
borderColor="red"
initialBorderColor="blue"
headerCenter={
<Text style={styles.navBarTitle} numberOfLines={1}>
Header
Expand Down Expand Up @@ -79,6 +81,8 @@ const Simple: React.FC<SimpleUsageScreenNavigationProps> = () => {
HeaderComponent={HeaderComponent}
LargeHeaderComponent={LargeHeaderComponent}
LargeHeaderSubtitleComponent={LargeHeaderSubtitleComponent}
automaticallyAdjustsScrollIndicatorInsets={false}
scrollIndicatorInsets={{ bottom }}
contentContainerStyle={{ paddingBottom: bottom }}
refreshControl={
<RefreshControl refreshing={refreshing} colors={['#8E8E93']} onRefresh={onRefresh} />
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
"useTabs": false,
"printWidth": 100
},
"react-native-builder-bob": {
"source": "src",
Expand Down
2 changes: 2 additions & 0 deletions src/components/headers/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Header: React.FC<HeaderProps> = ({
noBottomBorder = false,
ignoreTopSafeArea = false,
borderColor,
initialBorderColor,
borderWidth,
SurfaceComponent,
}) => {
Expand Down Expand Up @@ -113,6 +114,7 @@ const Header: React.FC<HeaderProps> = ({
<HeaderBottomBorder
opacity={showNavBar}
borderColor={borderColor}
initialBorderColor={initialBorderColor}
borderWidth={borderWidth}
/>
)}
Expand Down
7 changes: 7 additions & 0 deletions src/components/headers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ export interface HeaderProps {
* @type {boolean}
*/
noBottomBorder?: boolean;
/**
* The color of the border when the header is not scrolled up.
*
* @default '#E5E5E5'
* @type {string}
*/
initialBorderColor?: string;
/**
* The color of the bottom border.
*
Expand Down
25 changes: 13 additions & 12 deletions src/components/line/HeaderBottomBorder.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { StyleSheet, StyleProp, ViewStyle } from 'react-native';
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
import Animated, { interpolateColor, useAnimatedStyle } from 'react-native-reanimated';

interface HeaderBottomBorderProps {
/**
Expand All @@ -13,6 +13,10 @@ interface HeaderBottomBorderProps {
* Style of the bottom border component.
*/
style?: StyleProp<ViewStyle>;
/**
*
*/
initialBorderColor?: string;
/**
* Color of the bottom border.
*
Expand All @@ -30,21 +34,18 @@ interface HeaderBottomBorderProps {
const HeaderBottomBorder: React.FC<HeaderBottomBorderProps> = ({
opacity,
style,
initialBorderColor = '#E5E5E5',
borderColor = '#E5E5E5',
borderWidth = 1,
}) => {
const borderBottomStyle = useAnimatedStyle(() => ({ opacity: opacity.value }));

return (
<Animated.View
style={[
styles.line,
borderBottomStyle,
{ height: borderWidth, backgroundColor: borderColor },
style,
]}
/>
const borderBottomStyle = useAnimatedStyle(
() => ({
backgroundColor: interpolateColor(opacity.value, [0, 1], [initialBorderColor, borderColor]),
}),
[initialBorderColor, borderColor]
);

return <Animated.View style={[styles.line, borderBottomStyle, { height: borderWidth }, style]} />;
};

export default HeaderBottomBorder;
Expand Down

0 comments on commit d62f91b

Please sign in to comment.