• react-native中的动画


    先看效果

    这个一个渐渐显示的动画,代码如下

    import React from 'react';
    import { Animated, Text, View } from 'react-native';
    
    class FadeInView extends React.Component {
      //定义状态
      state = {
        fadeAnim: new Animated.Value(0),  // Initial value for opacity: 0
      }
    
      componentDidMount() {
        Animated.timing(                  // Animate over time
          this.state.fadeAnim,            // The animated value to drive
          {
            toValue: 1,                   // Animate to opacity: 1 (opaque)
            duration: 10000,              // Make it take a while
          }
        ).start();                        // Starts the animation
      }
    
      render() {
        let { fadeAnim } = this.state;
    
        return (
          <Animated.View                 // Special animatable View
            style={{
              ...this.props.style,
              opacity: fadeAnim,         // Bind opacity to animated value
            }}
          >
            {this.props.children}
          </Animated.View>
        );
      }
    }
    
    // You can then use your `FadeInView` in place of a `View` in your components:
    export default class App extends React.Component {
      render() {
        return (
          <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
            <FadeInView style={{ 250, height: 50, backgroundColor: 'powderblue'}}>
              <Text style={{fontSize: 28, textAlign: 'center', margin: 10}}>Fading in</Text>
            </FadeInView>
          </View>
        )
      }
    }
    

    第二个demo
    点击图形变大
    先看效果

    再看代码如下

    import React from 'react';
    import {
      NativeModules,
      LayoutAnimation,
      Text,
      TouchableOpacity,
      StyleSheet,
      View,
    } from 'react-native';
    
    const { UIManager } = NativeModules;
    
    UIManager.setLayoutAnimationEnabledExperimental &&
      UIManager.setLayoutAnimationEnabledExperimental(true);
    
    export default class App extends React.Component {
      state = {
        w: 100,
        h: 100,
      };
    
      _onPress = () => {
        // Animate the update
        LayoutAnimation.spring();
        this.setState({w: this.state.w + 15, h: this.state.h + 15})
      }
    
      render() {
        return (
          <View style={styles.container}>
            <View style={[styles.box, { this.state.w, height: this.state.h}]} />
            <TouchableOpacity onPress={this._onPress}>
              <View style={styles.button}>
                <Text style={styles.buttonText}>Press me!</Text>
              </View>
            </TouchableOpacity>
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
      },
      box: {
         200,
        height: 200,
        backgroundColor: 'red',
      },
      button: {
        backgroundColor: 'black',
        paddingHorizontal: 20,
        paddingVertical: 15,
        marginTop: 15,
      },
      buttonText: {
        color: '#fff',
        fontWeight: 'bold',
      },
    });
    
  • 相关阅读:
    【Unity】自定义编辑器窗口——拓展编辑器功能
    【Unity】AssetBundle的使用——打包/解包
    【Unity】使用Resources类管理资源
    【Unity】使用AssetDatabase编辑器资源管理
    【Unity】协程Coroutine及Yield常见用法
    【Unity】制作简易定时器(Timer)
    python3使用csv模块读写csv文件
    Python3使用csv模块csv.writer().writerow()保存csv文件,产生空行的问题
    MongoDB服务无法启动,发生服务特定错误:100
    ValueError: update only works with $ operators
  • 原文地址:https://www.cnblogs.com/smart-girl/p/10648425.html
Copyright © 2020-2023  润新知