Примените backgroundColor внутри свойства style вместо contentContainerStyle scrollView.
Animated.Value (0) должен храниться в состоянии, а не как объект класса (из официальных документов и передового опыта).
Я изменил ваш код выше, чтобы он работал,
import React, { Component } from 'react';
import { Text, StyleSheet, Animated } from 'react-native';
export default class App extends Component {
constructor (props) {
super(props);
// Intialize to default value
this.state = {
backgroundColor: new Animated.Value(0)
};
}
onPress = () => {
// onPress, initialize to default value using setState and start animation
// after the state has been updated
this.setState({ backgroundColor: new Animated.Value(0) }, () => {
Animated.timing(this.state.backgroundColor, {
toValue: 100,
duration: 5000
}).start();
});
}
render() {
return (
<Animated.ScrollView
style={[
styles.container,
// Interpolation mapping from numbers to strings (colors)
{
backgroundColor: this.state.backgroundColor.interpolate({
inputRange: [0, 100],
outputRange: ["#00aaFF", "#808080"]
})
}
]}
>
<Text
// onPress to start Animation
onPress={() => this.onPress() }
style={styles.paragraph}
>
Change code in the editor and watch it change on your phone!
Save to get a shareable url.
</Text>
</Animated.ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
color: '#34495e',
},
});
Пример рабочего перекуса: https://snack.expo.io/BymzMdtRG
Надеюсь, это поможет.