为什么我的Animated API组件不会在React Native中显示?

用户名

我正在尝试在Animated Api中使用插值函数,当我使用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',
  },
});
安托万·格兰尚(Antoine Grandchamp)

从React-native文档中:

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

您需要在样式道具中添加宽度和高度

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么mouseDown事件不会在React中传播?

为什么我的简单元素不会在此React渲染方法中渲染?

为什么我的ibjects不会在javascript中变形?

为什么我不能在 React Native 的 Animated.event() 中触发 nativeEvent 回调?

React.js 不会在我的 Codepen 中呈现

为什么 angular 不会在动态创建的组件中填充视图?

React Native 组件不会在计算后立即更新

为什么我的 InnerHTML 代码不会在表单字段中显示任何数据?

React不会在组件中触发功能

React - 道具不会在整个组件中更新相同

Route 不会在 React 中渲染组件

如果我在api.onchange方法中更改字段值,则该值不会在视图中更新。为什么?

为什么在新的react-router-dom <Redirect />中不会在setTimout内部触发?

SwiftUI - 为什么我的 @Published 变量不会在我的 @ObservedObject 调用中更新?

Vue 不会在我的组件的 mustache 模板 ( {{}} ) 中呈现内容

当子组件通过 {#key} 重新渲染时,为什么绑定的道具不会在父级中重置?

组件的 prop 不会在带有 Redux 的 React Native 中更新

React Native更改let值不会在子组件中作为prop更改

为什么为每个模块设置日志记录级别都不会在我的代码中显示日志?

为什么当我将 \ 添加到 cout 时,它不会在输出中显示

我的文字不会在 pygame 中显示

我的YouTube视频不会在iframe中显示

Angular 不会在 HTML 中显示我的数组结果

为什么不会在我的代码中执行请求方法?

为什么打印消息不会在我的C#代码中打印?

为什么这个计时器不会在我的 Fragment 中执行?

组件不会在反应中呈现

FlatList不会在组件中呈现

为什么不会在选择框中填充字段?