question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Animated.event

See original GitHub issue

Hey!

Thanks for a great lib.

Any way to add an onScroll Animated.event to the component for some cool animation shenanigans? 😃

Would be awesome if one could do something along the lines of

<KeyboardAwareScrollView
        style={styles.container}
        onScroll={Animated.event(
          [{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }],
          { useNativeDriver: true }
        )}
      >
    <View />
</KeyboardAwareScrollView>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15

github_iconTop GitHub Comments

12reactions
jhalborgcommented, Jan 18, 2018

Cool, thanks! It works! 😃

For anyone coming across this issue, remember to make the component animated using Animated.createAnimatedComponent, otherwise it will not work. Something like:

import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
...
const AnimatedKeyboardAwareScrollView = Animated.createAnimatedComponent(
  KeyboardAwareScrollView
);
...
const scale = this.state.scrollY.interpolate({
      inputRange: [-180, 0],
      outputRange: [0.5, 1],
      extrapolate: 'clamp',
    });

    return (
      <AnimatedKeyboardAwareScrollView
        scrollEventThrottle={16}
        onScroll={Animated.event(
          [{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }],
          { useNativeDriver: true }
        )}
      >...</AnimatedKeyboardAwareScrollView>
2reactions
ddxxtonycommented, Aug 8, 2019

In my case if I use this { useNativeDriver: true }, it stops working

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native Animated with useNativeDriver - Stack Overflow
Short answer: it isn't possible. You can use native driver only by passing Animated.event into onScroll handler.
Read more >
Animated - React Native
The Animated library is designed to make animations fluid, powerful, ... events can map directly to animated values using Animated.event() .
Read more >
Animated.event - React Native Animated for Beginners
Animated.event. This is just a helper function to map arbitrary data to Animated values. Check out the docs for their explanation ...
Read more >
Animated.event() with useNativeDriver returns an object, not a ...
event () with useNativeDriver returns an object, not a function #16250. Resolution: Locked.
Read more >
Non-Native and Native Animated Values in React Native
Some may be supported by the native driver (such as transform, or opacity), ... Calling Animated.event can actually return two things, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found