微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React Native动画没有动画

如何解决React Native动画没有动画

因此,当前正在尝试RN动画,为了了解基本功能和工作流程,我试图尽可能慢一些。我创建了一个新的Expo应用程序,并通过react-native-reanimated命令安装了~1.13.0软件包版本react-native-gesture-handler~1.7.0版本expo install

稍后我也计划使用react-native-redash软件包,但现在我正尝试配置为什么下面的代码根本不起作用。

import React from "react";
import { View,StyleSheet } from "react-native";

import Animated from "react-native-reanimated";
import { PanGestureHandler } from "react-native-gesture-handler";

const { Value } = Animated;

export default function App() {
  const translateY = new Value(0);
  const translateX = new Value(0);

  return (
    <View style={styles.container}>
      <PanGestureHandler
        onGestureEvent={Animated.event(
          [
            {
              nativeEvent: {
                translationY: translateY,translationX: translateX,},],{ useNativeDriver: true }
        )}
      >
        <Animated.View
          style={[
            styles.ball,{
              transform: [
                { translateY: translateY },{ translateX: translateX },]}
        ></Animated.View>
      </PanGestureHandler>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,backgroundColor: "#ffffff",alignItems: "center",justifyContent: "center",ball: {
    width: 100,height: 100,borderRadius: 9999,backgroundColor: "black",});

此后,我的“球”视图中没有动画。有人知道我在做什么错吗?

解决方法

应将event()节点分配给

 const eventHandler = event(/* */);
 // ...
 <PanGestureHandler
    onGestureEvent={eventHandler}
    onHandlerStateChange{eventHandler}
  >

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。