先看效果

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

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 timethis.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 Viewstyle={{...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={{width: 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 updateLayoutAnimation.spring();this.setState({w: this.state.w + 15, h: this.state.h + 15})}render() {return (<View style={styles.container}><View style={[styles.box, {width: 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: {width: 200,height: 200,backgroundColor: 'red',},button: {backgroundColor: 'black',paddingHorizontal: 20,paddingVertical: 15,marginTop: 15,},buttonText: {color: '#fff',fontWeight: 'bold',},
});

转载于:https://www.cnblogs.com/smart-girl/p/10648425.html

react-native中的动画相关推荐

  1. 如何在React Native中创建精美的动画加载器

    by Vikrant Negi 通过Vikrant Negi 如何在React Native中创建精美的动画加载器 (How to create a beautifully animated load ...

  2. 在 React Native 中实现 3D 动画

    本文的范围将涵盖对 Three.js 库和 Animated API 的探索. 您应该具备 JavaScript 和 React Native 的基本知识才能继续学习: 要了解更多关于可以在 Reac ...

  3. 如何在React Native中使用react-navigation 5处理导航

    React-navigation is the navigation library that comes to my mind when we talk about navigation in Re ...

  4. 使用React Native进行气泡动画

    by Narendra N Shetty 由纳伦德拉·N·谢蒂(Narendra N Shetty) 使用React Native进行气泡动画 (Bubble animation with React ...

  5. android 倒计时封装,react native中的聊天气泡及timer封装成的发送验证码倒计时

    其实,今天我想把我近期遇到的坑都总结一下: 1.goBack的跨页面跳转,又两种方法,一可以像兔哥那样修改navigation源码,二可以用navigationActions 2.父子组件的传值,一可 ...

  6. 理解 React Native 中的 AJAX 请求

    曾经,大多数 Web 应用程序通过用户操作刷新整个网页以与 Web 服务器通信. 后来,AJAX(异步 JavaScript 和 XML)概念通过提供一种在后台与 Web 服务器通信的方式使 Web ...

  7. 我在React Native中构建时获得的经验教训

    by Amanda Bullington 通过阿曼达·布林顿(Amanda Bullington) 我在React Native中构建时获得的经验教训 (Lessons I learned while ...

  8. 如何在React Native中写一个自定义模块

    前言 在 React Native 项目中可以看到 node_modules 文件夹,这是存放 node 模块的地方,Node.js 的包管理器 npm 是全球最大的开源库生态系统.提到npm,一般指 ...

  9. 如何在React Native中记录日志?

    本文翻译自:How to do logging in React Native? 如何为Web开发时在React Native中记录变量,例如使用console.log ? #1楼 参考:https: ...

  10. react native中一次错误排查 Error:Error: Duplicate resources

    最近一直在使用react native中,遇到了很多的坑,同时也学习到了一些移动端的开发经验. 今天在做一个打包的测试时,遇到了一个问题,打包过程中报错"Error:Error: Dupli ...

最新文章

  1. 《麻省理工学院技术评论》评出最新十大突破性技术
  2. ubuntu 查看内存和cpu使用情况
  3. Java虚拟机管理的内存运行时数据区域解释
  4. Sprint(第十天11.23)
  5. 【开源】Caffe、TensorFlow、MXnet三个开源库对比
  6. 越南黑客组织APT32正对NSA网络武器开展研究利用
  7. Django 之 Cookie判断是否已登陆(写成类)
  8. LiveVideoStackCon深圳-发掘移动客户端更多可能
  9. Android UI 常用图标尺寸规范
  10. .NET 云原生架构师训练营(模块二 基础巩固 配置)--学习笔记
  11. kafka集群 kubernetes_为什么 Kubernetes 如此受欢迎?
  12. Python超越R,为何Python攀上数据科学巅峰?
  13. div.php织梦自定义表判断不能为空,织梦使用if判断某个字段是否为空
  14. 干了四五年Android 开发了,如何突破成长中的技术瓶颈期?
  15. 使用oracle执行txt语句,oracle常用SQL语句.txt
  16. 洛谷P5170 【模板】类欧几里得算法(数论)
  17. 拼接图像亮度均匀调整_华邦瀛微色差液晶拼接屏系统解决方案
  18. speedoffice(Word)文档中如何插入图片
  19. 基于Vue的移动端图片裁剪组件 vue-clip(完美兼容ios与安卓)
  20. Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈)

热门文章

  1. python3 抓取图片
  2. Listview的OnScrollListener的滑动监听实现分页加载
  3. 声明 static 变量注意事项
  4. IOS开发之Storyboard应用
  5. 关于如何为eclipse3.5安装cdt插件的问题
  6. 视频预训练界的HERO!微软提出视频-语言全表示预训练模型HERO,代码已开源!...
  7. CVPR2021 用更好的目标检测器提取视觉特征!微软提出VinVL,基于更好的视觉特征,达到更强的多模态性能...
  8. 电商标识检测的鲁棒性防御,ACM MM2021 安全AI大赛技术解析
  9. PyTorch 多目标跟踪
  10. 霍夫变换是怎么发明的?