【问题标题】:Why won't my Animated API component show in React Native?为什么我的动画 API 组件不会在 React Native 中显示?
【发布时间】:2018-08-07 00:42:37
【问题描述】:

我正在尝试在 Animated Api 中使用 interpolate 函数,当我使用 Image 组件时,它可以工作,但是当我使用 Animated.Image 时,什么都没有出现,或者如果我用一个值硬编码旋转它也不起作用或抛出错误。

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',
  },
});

【问题讨论】:

    标签: react-native react-animated


    【解决方案1】:

    来自 React-native 文档:

    请注意,对于网络和数据图像,您需要手动指定图像的尺寸!

    您需要在样式属性中添加宽度和高度

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2017-09-17
      • 2021-07-22
      • 1970-01-01
      • 2021-06-12
      相关资源
      最近更新 更多