Sachin Biradar
Sachin Biradar

Reputation: 33

scroll the view simultaneously as the scrollView scrolls

scrollPositionX: new Animated.Value(0),    

scrollEventThrottle={16}
onScroll={Animated.event([{nativeEvent: {contentOffset: {x: this.state.scrollPositionX}}}] )}

<Animated.View style={[styles.times, {
     transform: [{translateX: this.state.scrollPositionX}]
}]}>
   ...
</Animated.View>

This code works but it scrolls the animated view in opposite direction. How do i make it scroll in the same direction. this is with respect to the issue - React Native ScrollView Sticky View Element

Upvotes: 2

Views: 1314

Answers (1)

oblador
oblador

Reputation: 3004

Use interpolate:

<Animated.View style={[styles.times, {
  transform: [{
    translateX: this.state.scrollPositionX.interpolate({
      inputRange: [0, 1], 
      outputRange: [0, -1]
    })
  }]
}]}>

Upvotes: 1

Related Questions