zoukankan      html  css  js  c++  java
  • [ReactVR] Animate Text, Images, Views, and 3D Elements Using the Animated Library in React VR

    Motion is an important aspect of a complete immersive experience, therefor we are going to look into the animation API Animated.

    Animated allows us to express a wide variety of animation patterns to animate text, images, and views.

    In addition we'll leverage the higher order component, <CreateAnimatedComponent/>, to create a rotating box!

    import React from 'react';
    import {
      AppRegistry,
      Animated,
      asset,
      Pano,
      Box,
      Text,
      View,
      Image,
      Model,
      Sphere,
      PointLight,
      AmbientLight,
      DirectionalLight,
    } from 'react-vr';
    
    const AnimatedBox = Animated.createAnimatedComponent(Box);
    
    export default class app extends React.Component {
      constructor() {
        super();
        this.state = {
          fadeIn: new Animated.Value(0),
          springValue: new Animated.Value(-1),
          rotation: new Animated.Value(0)
        }
      }
    
      componentDidMount() {
        Animated.timing(
          this.state.rotation,
          {
            duration: 10000,
            toValue: 930
          }
        ).start();
        Animated.sequence([
          Animated.spring(
            this.state.springValue,
            {
              toValue: 0,
              duration: 3000,
              tension: 1,
              friction: 2
            }
          ),
          Animated.delay(200),
          Animated.timing(
            this.state.fadeIn,
            {
              duration: 1500,
              toValue: 1,
              easing: (x) => x 
            }
          )
        ]).start();
      }
    
      render() {
        return (
          <View>
            <View>
              <AmbientLight intensity={0.5}/>
              <AnimatedBox
                lit
                dimWidth={2}
                dimDepth={2}
                dimHeight={1}
                style={
                  {
                    color: 'orange',
                    transform: [
                      {translate: [0,2,-3]},
                      {rotateY: this.state.rotation},
                      {rotateX: -40}
                    ]
                  }
                }
              ></AnimatedBox>
            </View>
            <Animated.Image 
              style={{
                layoutOrigin: [0.5, 0.5],
                transform: [
                  {translateZ: -1},
                  {translateY: this.state.springValue}
                ],
                height: 0.5,
                 0.5,
                backgroundColor: '#335'
              }}
              source={asset('4.jpeg')}
            >
              <Animated.Text 
                style={{
                  opacity: this.state.fadeIn,
                  color: 'green',
                  fontSize: 0.10,
                  textAlign: 'center'
                }}
              >Grit</Animated.Text>
            </Animated.Image>
          </View>
        );
      }
    };
    
    AppRegistry.registerComponent('app', () => app);
  • 相关阅读:
    聊聊Java中的异常及处理
    mysql各个版本介绍
    三范式理解
    spring 自定义注解
    双亲委派机制
    架构师之路
    访问localhost报错404
    删除重复记录sql
    如何测试kafka集群能否正常工作?
    SQL14
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8434059.html
Copyright © 2011-2022 走看看