首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React本机动画未运行

React本机动画未运行
EN

Stack Overflow用户
提问于 2021-04-30 03:53:14
回答 1查看 97关注 0票数 0

我正在使用react-native-animatable库来制作一个加载图标的动画。我已经有一段时间没有接触过它了,直到我决定用它来做我的新项目。当我将它添加到我的代码中时,它可以做任何事情,我真的很困惑为什么它不能运行。加载程序在视觉上是存在的,但没有动画。我不知道问题出在哪里,因为我上次用它工作得很好。

代码:

代码语言:javascript
复制
import React from 'react';
import { StyleSheet, View } from 'react-native';
import * as Animatable from 'react-native-animatable';

import constansts from "../../assets/constants"

export default function Loading(){
    const flipAnim = {
        0: {
            transform: [{rotate: "0deg"}]
        },
        0.25: {
            transform: [{rotate: "180deg"}]
        },
        0.5: {
            transform: [{rotate: "180deg"}]
        },
        0.75: {
            transform: [{rotate: "360deg"}]
        },
        1: {
            transform: [{rotate: "360deg"}]
        }
    }

    const fillAnim = {
        0: {
            height: "0%"
        },
        0.25: {
            height: "0%"
        },
        0.5: {
            height: "100%"
        },
        0.75: {
        height: "100%"
        },
        1: {
            height: "0%"
        }
    }
    
    return (
        <View style={styles.loadingCon}>
            <Animatable.View 
                style={styles.loader} 
                animation={flipAnim}
                duration={2000}
                iterationCount="infinite"
                easing="linear"
            >
                <Animatable.View
                    style={styles.loaderInner}
                    animation={fillAnim}
                    duration={2000}
                    iterationCount="infinite"
                    easing="linear"
                >
                </Animatable.View>
            </Animatable.View>
        </View>
    )
}

const styles = StyleSheet.create({
    loadingCon: {
        height: "100%",
        justifyContent: "center",
        alignItems: "center"
    },
    loader: {
        width: 40,
        height: 40,
        borderWidth: 5,
        borderColor: constansts.colors.blues,
        borderRadius: 4
    },
    loaderInner: {
        width: "100%",
        backgroundColor: constansts.colors.blues,
    }
})
EN

回答 1

Stack Overflow用户

发布于 2021-06-16 23:17:31

你在视图中没有任何东西,为了动画添加一些图标,如下所示

代码语言:javascript
复制
 <View style={styles.loadingCon}>
  <Animatable.View
    style={styles.loader}
    animation={flipAnim}
    duration={2000}
    iterationCount="infinite"
    easing="linear"
  >
    <Animatable.View
      style={styles.loaderInner}
      animation={fillAnim}
      duration={2000}
      iterationCount="infinite"
      easing="linear"
    >
      <Feather name="loader" size={24} color="black" />
    </Animatable.View>
  </Animatable.View>
</View>;

请注意,您需要安装和导入任何图标库,我使用expo

代码语言:javascript
复制
  import { Feather } from '@expo/vector-icons'; 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67324205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档