user5596792
user5596792

Reputation: 67

Why won't my Animated API component show in React Native?

I'm trying to use the interpolate function in the Animated Api and when I use the Image component this works but when I use the Animated.Image nothing appears or if I hardcode rotate with a value it also doesn't work or throw an error.

import React from 'react';
import { StyleSheet, Text, View, Animated, Easing, Image} from 'react-native';


export default class App extends React.Component {
  state = {spinValue : new Animated.Value(0)}

  componentDidMount(){
    Animated.timing(
      this.state.spinValue,
      {
        toValue: 1,
        duration: 3000,
        easing: Easing.linear
      }
    ).start()
  }

  spin = this.state.spinValue.interpolate({
    inputRange: [0, 1], 
    outputRange: ['0deg', '360deg']
  })

  render() {
    return (
      <View style={styles.container}>
        <Animated.Image
          style={{transform: [{rotate: "90deg"}] }}
          source={{uri: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Square_-_black_simple.svg/1200px-Square_-_black_simple.svg.png'}} />
        <Text>Testing</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Upvotes: 1

Views: 28

Answers (1)

Antoine Grandchamp
Antoine Grandchamp

Reputation: 7470

From React-native documentation :

Note that for network and data images, you will need to manually specify the dimensions of your image!

You need to add a Width and Height in your style prop

Upvotes: 1

Related Questions