Skip to content

Instantly share code, notes, and snippets.

@luandevpro
Created August 5, 2019 13:08
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/26c6b07ae10096dd03ee04e91b50c91e to your computer and use it in GitHub Desktop.
Save luandevpro/26c6b07ae10096dd03ee04e91b50c91e 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', 'red'],
}),
};
return (
<ScrollView
scrollEventThrottle={16}
onScroll={(e) => {
animated.setValue(e.nativeEvent.contentOffset.y);
}}
>
<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