Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
React Native- reseting scroll animation

I have a component that is moved up on scrolling.

  const [topBarHeight, setTopBarHeight] = useState(0);

  const scrollY = useRef(new Animated.Value(0));
  const scrollYClamped = diffClamp(scrollY.current, 0, topBarHeight);

  const translateY = scrollYClamped.interpolate({
    inputRange: [0, topBarHeight],
    outputRange: [0, -topBarHeight]
  });

  const resetToInitialPosition = () => {
    scrollY.current.setValue(0);
  };

  const handleScroll = Animated.event(
    [
      {
        nativeEvent: {
          contentOffset: { y: scrollY.current }
        }
      }
    ],
    {
      useNativeDriver: true
    }
  );

I have a problem with resetToInitialPosition. It works fine and sets animated value back to initial, however scrollYClamped and translateY are not being reset and the component goes all the way up immediately after any interaction with the scroll view. Any idea how to set those two variables back to initial values as well?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!