Giter Club home page Giter Club logo

react-native-scrollable-animated-header's Issues

How to Animate the header again when we scroll upside

Hey, your repository helped me a lot and I am able to implement the animation.
Thank you very much.
But now the problem is I want to show/animate the header back when we scroll up.
The current behaviour is when the user scrolls down Header just translate to -HEADER_MAX_HEIGHT.
Here is my code
App.js

import React, {Component, useRef} from 'react';
import {Text, View, FlatList, Animated} from 'react-native';
import TestView from './TestView';
import Header from './Header';

const HEADER_MAX_HEIGHT = 55;
const HEADER_MIN_HEIGHT = 10;
const HEADER_SCROLL_DISTANCE = HEADER_MAX_HEIGHT - HEADER_MIN_HEIGHT;

export default function CollapsableHeader(props) {
  const [array, setArray] = React.useState(new Array(200).fill(10));

  const scrollY = useRef(new Animated.Value(0)).current;

  const headerTranslateY = scrollY.interpolate({
    inputRange: [0, HEADER_SCROLL_DISTANCE],
    outputRange: [0, -HEADER_SCROLL_DISTANCE],
    extrapolate: 'clamp',
  });
  return (
    <View style={{flex: 1}}>
      <Animated.FlatList
        style={{flex: 1, paddingTop: HEADER_MAX_HEIGHT}}
        onScroll={Animated.event(
          [{nativeEvent: {contentOffset: {y: scrollY}}}],
          {useNativeDriver: true},
        )}
     
        data={array}
        renderItem={({item}) => <TestView key={item} />}
        keyExtractor={(item, index) => String(index)}
      />
      <Animated.View
        style={[
          {
            height: HEADER_MAX_HEIGHT,
            position: 'absolute',
            top: 0,
            left: 0,
            right: 0,
            backgroundColor: '#62d1bc',
            overflow: 'hidden',
            height: HEADER_MAX_HEIGHT,
          },
          {
            transform: [{translateY: headerTranslateY}],
          },
        ]}>
        <Text style={{textAlign: 'center', fontSize: 20}}>
          CollapsableHeader
        </Text>
      </Animated.View>
    </View>
  );
}

Can you guide me on how can I achieve this behaviour?

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.