react native中使用Animated实现三张图片动态旋转效果

react native中使用Animated实现三张图片动态旋转效果

效果示例图


示例代码

复制代码
import React, {useEffect, useRef} from 'react';
import {Animated, StyleSheet, View} from 'react-native';
import {pxToPd} from '../../common/js/device';

const TestShowCard = () => {
  const rotationValue = useRef(new Animated.Value(0)).current;

  const firstCardRotation = '0deg';
  const secondCardRotation = rotationValue.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '-15deg'],
  });
  const thirdCardRotation = rotationValue.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '15deg'],
  });

  useEffect(() => {
    Animated.timing(rotationValue, {
      toValue: 1,
      duration: 1000,
      useNativeDriver: true,
    }).start();
    return () => {};
  }, []);

  return (
    <>
      <View style={styles.container}>
        <View style={styles.dynCard}>
          <Animated.View
            style={[
              styles.cardItem,
              {transform: [{rotate: thirdCardRotation}]},
            ]}></Animated.View>
          <Animated.View
            style={[
              styles.cardItem,
              {transform: [{rotate: secondCardRotation}]},
            ]}></Animated.View>
          <Animated.View
            style={[
              styles.cardItem,
              {transform: [{rotate: firstCardRotation}]},
            ]}></Animated.View>
        </View>
      </View>
    </>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  dynCard: {
    width: pxToPd(174),
    height: pxToPd(203),
    position: 'relative',
    marginTop: pxToPd(200),
    marginLeft: pxToPd(100),
  },
  cardItem: {
    width: '100%',
    height: '100%',
    borderColor: 'blue',
    borderWidth: pxToPd(1),
    borderStyle: 'solid',
    position: 'absolute',
    backgroundColor: 'white',
  },
});

export default TestShowCard;
相关推荐
不羁的fang少年1 小时前
前端常见问题(vue,css,html,js等)
前端·javascript·css
change_fate2 小时前
el-menu折叠后文字下移
前端·javascript·vue.js
weixin_411191843 小时前
flutter中WebView的使用及JavaScript桥接的问题记录
javascript·flutter
百***06013 小时前
SpringMVC 请求参数接收
前端·javascript·算法
用户47949283569154 小时前
React 渲染两次:是 Bug 还是 Feature?聊聊严格模式的“良苦用心”
前端·react.js·前端框架
用户47949283569154 小时前
Code Review 惊魂:同事的“优雅”重构,差点让管理员全部掉线
javascript
虚伪的空想家5 小时前
arm架构服务器使用kvm创建虚机报错,romfile “efi-virtio.rom“ is empty
linux·运维·服务器·javascript·arm开发·云原生·kvm
0***K8926 小时前
Vue数据挖掘开发
前端·javascript·vue.js
QQRRRRW6 小时前
Tailwind+VScode (Vite + React + TypeScript) 原理与实践
vscode·react.js·typescript
Irene19916 小时前
ES6 export 语句 语法规范
javascript·es6·export