Coder Social home page Coder Social logo

oguzturker8 / header Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 0.0 1.59 MB

A header library for react-native. Uses power of ReAnimated 2.

Home Page: https://www.npmjs.com/package/@oguzturker8/header

License: MIT License

JavaScript 24.48% TypeScript 75.52%
react-native mobile animation reanimated2 header

header's Introduction

@oguzturker8/header

A header library for react-native. Uses power of reanimated2.

Installation

npm install @oguzturker8/header

Usage

Basic Header Usage

Navigation.tsx
import Header from '@oguzturker8/header';

// ...

<NavigationContainer>
  // ....
  <Stack.Navigator>
    // ...
    <Stack.Screen
      name="Screen1"
      component={Screen1}
      options={{
        header: (props) => <Header {...props} title="title1337" />,
      }}
    />
    // ...
  </Stack.Navigator>
</NavigationContainer>;

// ...

Header Scroll Animation

Navigation.tsx
import Header from '@oguzturker8/header';

// ...

<NavigationContainer>
  // ....
  <Stack.Navigator>
    // ...
    <Stack.Screen
      name="Screen4"
      component={Screen4}
      //  Declare it in Screen Component
      //  options={{
      //    header: (props) => (
      //      <Header {...props} title="Screen 04" type={{ right: 'close' }} />
      //    ),
      //  }}
    />
    // ...
  </Stack.Navigator>
</NavigationContainer>;

// ...
Screen4.tsx
import {
  AnimatedScrollView,
  Header,
  useHeaderAnimation,
} from '@oguzturker8/header';

function Screen4({ navigation }: screenNavigation) {
  const { scrollOffset, scrollHandler } = useHeaderAnimation();
  React.useLayoutEffect(() => {
    navigation.setOptions({
      header: (props) => (
        <Header
          {...props}
          title="Screen 04"
          type={{ right: 'close' }}
          animation={{
            animatedValue: scrollOffset,
            background: {
              colorRange: ['blue', 'red'],
              slidingRange: [0, 100],
            },
          }}
        />
      ),
    });
  }, [navigation]);

  return (
    <AnimatedScrollView onScroll={scrollHandler}>
      <View style={styles.container}>
        <Text>Screen4</Text>
        <Button title="Reset stack" onPress={() => navigation.popToTop()} />
        <Text>Screen4</Text>
        {Array.from({ length: 100 }, (_, i) => (
          <Text key={i}>{`${i + 1}. Text`}</Text>
        ))}
      </View>
    </AnimatedScrollView>
  );
}

Properties

Header

Prop Description Type
style Header container style prop.
Includes 5 parts
leftStyle
rightStyle
centerStyle
wrapperStyle
titleStyle
leftStyle?: ViewStyle
rightStyle?: ViewStyle
centerStyle?: ViewStyle
wrapperStyle?: ViewStyle
titleStyle?: TextStyle
title Header title text string
type Decides left and right parts' types LeftType = 'back' - 'close'
RightType = 'back' - 'close'
callback Parts' onPress callbacks onLeft?: () => any
onRight?: () => any
onCenter?: () => any
size Parts' text sizes left?: number
right?: number
center?: number
animation Header animations Described below section

Animation

Animations Description Type
background Header backgroundColor interpolation animation based on ScrollView's scrollOffset. colorRange: string[]
slidingRange: string[]

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

header's People

Contributors

turker0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.