Skip to content

Instantly share code, notes, and snippets.

@luandevpro
Created August 5, 2019 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luandevpro/f1c82ed28e826bceb6fadbd6828bfda0 to your computer and use it in GitHub Desktop.
Save luandevpro/f1c82ed28e826bceb6fadbd6828bfda0 to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
import {
View, Text, Animated, StyleSheet, TouchableWithoutFeedback, ScrollView,
} from 'react-native';
import PropTypes from 'prop-types';
export default function Home() {
const [animated, setAnimated] = useState(new Animated.Value(0));
const animatedEvent = {
backgroundColor: animated.interpolate({
inputRange: [0, 3000],
outputRange: ['blue', 'yellow'],
}),
};
return (
<ScrollView
scrollEventThrottle={16}
onScroll={Animated.event([
{
nativeEvent: {
contentOffset: {
y: animated,
},
},
},
])}
>
<View style={styles.container}>
<Animated.View
style={[styles.box, animatedEvent]}
/>
</View>
</ScrollView>
);
}
Home.propTypes = {
navigation: PropTypes.object , // eslint-disable-line
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
box: {
width: '100%',
height: 3000,
backgroundColor: 'blue',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment