npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@farfarawaylabs/react-native-animatable-header

v0.1.0

Published

Animatable and collapsible screen header based on attached scroll behavior for React Native

Downloads

5

Readme

@farfarawaylabs/react-native-animatable-header

Animatable and collapsible screen header based on attached scroll behavior for React Native

Installation

This library is dependant on a few other libraries in order to run animations in a performant way and only on the native thread.

npm install react-native-reanimated react-native-gesture-handler react-native-redash
npm install @farfarawaylabs/react-native-animatable-header

Architecture and design choices

This componenet was design as a composite control. Although this pattern is more verbose in code, it give you a lot more flexibility. You can use all the built in componenets or replace just some of them with your own implementation. It also prefers coding in a declarative way instead of having just one component with a list of tens of props for customization. That said, each of the coponents in this library accepts also a style and {...rest} props so you can easily customize them as well.

Basic Usage Example

import * as React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import {
  AnimatableHeader,
  CollapsedHeader,
  CollapsedHeaderTitle,
  CollapsedHeaderSection,
  HeaderBackground,
  ScrollableContent,
} from '@farfarawaylabs/react-native-animatable-header';

export default function App() {
  return (
    <View style={styles.container}>
      <AnimatableHeader backgroundColor="#000">
        <HeaderBackground image={bgOne} />
        <ScrollableContent
          title="Great Title"
          titleColor="#FFF"
          titleStyle={{ fontSize: 48 }}
        >
          {items.map((currItem, index) => {
            return (
              <Text style={[styles.item]} key={`item${index}`}>
                {currItem.title}
              </Text>
            );
          })}
        </ScrollableContent>
        <CollapsedHeader>
          <CollapsedHeaderSection />
          <CollapsedHeaderTitle title="Great Title" />
          <CollapsedHeaderSection />
        </CollapsedHeader>
      </AnimatableHeader>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  item: {
    color: 'white',
    fontSize: 30,
    paddingVertical: 15,
  },
});

Components

AnimatableHeader

This is the parent component that holds both the expanded header, the collapsed header and the scrollbar with all the content. Inside it you should put the rest of the components this library exposes, or replace some with your own implementation. The AnimatableHeader will inject two props to each of its children:

  • scrollY. An animatable value which reflects the current scroll location of scrollbar.
  • headerHeight: The full header height. This prop is used internally to calculate the different animations

Props

  • headerHeight: header height. Defaults to 30% of the window height
  • backgroundColor: Set the background color for all the child components. Not set by default
  • style: Additional styles or styles to override default style

HeaderBackground

This compoenent holds the background image of the expanded header as well as gradiant overlay and controls their animations.

Props

  • image: image to use as background of the header
  • backgroundColor: The background color to use. Defaults to '#000'
  • style: Additional styles or styles to override default style

ScrollableContent

This component is the container scrollbar that knows to report it's scroll location and allow all other components to animate accordingly.

Props

  • backgroundColor: The background color to use. Defaults to '#000'
  • title: The expanded header title
  • titleColor: The title color. Defaults to '#FFF'
  • titleStyle: Additional styles or override default styles for the header title
  • titleContainerStyle: Additional or overide default style for the container of the title. By default it centers the title horizontally and put it on the bottom vertically
  • style: Additional styles or styles to override default style

CollapsedHeader

This is the container for the header when it is in the collapsed mode. You can use the two provided components (CollapsedHeaderSection and CollapsedHeaderTitle) as children or provide your own header implementation. If you use the CollapsedHeaderTitle as a child component, the CollapsedHeader will provide it with the scroll position automatically in order for it to animate the title better.

Props

  • backgroundColor: The background color to use. Defaults to '#000'
  • collapsedHeight: The height of the header when it is collapsed. Defaults to 30% of the header height
  • style: Additional styles or styles to override default style

CollapsedHeaderSection

Container component to be used only as a child of CollapsedHeader. You will mostly use it in order to add buttons or other controls to the left or righ side of the collapsed header.

CollapsedHeaderTitle

Displays a title on the collpased header and controls animations for it.

Props

  • title: The expanded header title
  • titleColor: The title color. Defaults to '#FFF'
  • titleStyle: Additional styles or override default styles for the header title

License

MIT