In this lesson we will use Animated.spring and TouchableWithoutFeedback to animate the scale of a button in our React Native application. We will use the scale transform property and see how adjusting the friction of a spring will effect the spring animation.

Checkout: TouchableWithoutFeedback.

Checkout: Animated.spring.

Only when you decide to override the default button feedback, create a new one.

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View, TouchableWithoutFeedback, Animated } from 'react-native'; export default class animatedbasic extends Component {
constructor(props) {
super(props); this.handlePressIn = this.handlePressIn.bind(this);
this.handlePressOut = this.handlePressOut.bind(this);
} componentWillMount() {
this.animatedValue = new Animated.Value();
} handlePressIn() {
Animated.spring(this.animatedValue, {
toValue: .
}).start()
}
handlePressOut() {
Animated.spring(this.animatedValue, {
toValue: ,
friction: ,
tension:
}).start()
}
render() {
const animatedStyle = {
transform: [{ scale: this.animatedValue}]
}
return (
<View style={styles.container}>
<TouchableWithoutFeedback
onPressIn={this.handlePressIn}
onPressOut={this.handlePressOut}
>
<Animated.View style={[styles.button, animatedStyle]}>
<Text style={styles.text}>Press Me</Text>
</Animated.View>
</TouchableWithoutFeedback>
</View>
);
}
} const styles = StyleSheet.create({
container: {
flex: ,
justifyContent: 'center',
alignItems: 'center',
},
button: {
backgroundColor: "#333",
width: ,
height: ,
alignItems: "center",
justifyContent: "center",
},
text: {
color: "#FFF"
}
}); AppRegistry.registerComponent('animatedbasic', () => animatedbasic);

[React Native] Animate the Scale of a React Native Button using Animated.spring的更多相关文章

  1. [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 ...

  2. React Native v0.4 发布,用 React 编写移动应用

    React Native v0.4 发布,自从 React Native 开源以来,包括超过 12.5k stars,1000 commits,500 issues,380 pull requests ...

  3. 移动端学习之理解WEB APP、Native APP、Hybrid APP以及React Native/uniapp包括H5、小程序等的区别与共通之处

    因为工作需要,需要进一步了解移动端的开发,遂返回复习移动端的知识点,在开始学习之前,产生了疑惑WEB APP .Native APP .Hybrid APP.React Native.Uniapp.H ...

  4. React躬行记(16)——React源码分析

    React可大致分为三部分:Core.Reconciler和Renderer,在阅读源码之前,首先需要搭建测试环境,为了方便起见,本文直接采用了网友搭建好的环境,React版本是16.8.6,与最新版 ...

  5. React.js入门笔记(续):用React的方式来思考

    本文主要内容来自React官方文档中的"Thinking React"部分,总结算是又一篇笔记.主要介绍使用React开发组件的官方思路.代码内容经笔者改写为较熟悉的ES5语法. ...

  6. 五分钟学习React(三):纯HTML代码搭建React应用

    上一期我们使用了React官方的脚手架运行React应用.大家可能会觉得这种方法很繁琐,需要配置各种第三方插件.JQuery时代的前端真是让人怀念.这一期,我就带领大家创建一个"怀旧版&qu ...

  7. React 源码剖析系列 - 不可思议的 react diff

      简单点的重复利用已有的dom和其他REACT性能快的原理. key的作用和虚拟节点 目前,前端领域中 React 势头正盛,使用者众多却少有能够深入剖析内部实现机制和原理. 本系列文章希望通过剖析 ...

  8. [React] Use react-rewards to add microinteractions to React app to reward users for some actions

    It's important that our users enjoy using our application or website. One way we can make it happen ...

  9. React躬行记(5)——React和DOM

    React实现了一套与浏览器无关的DOM系统,包括元素渲染.节点查询.事件处理等机制. 一.ReactDOM 自React v0.14开始,官方将与DOM相关的操作从React中剥离,组成单独的rea ...

随机推荐

  1. 题解 P1198 【[JSOI2008]最大数】

    说起来这还是蒟蒻AC的第一道省选线段树呢. 这道题和其他线段树最大的不同就是在于本题数组一直在增大. 寻常的线段树蒟蒻习惯用如下的结构体储存,然而对于此题就不行了: struct node{ int ...

  2. 【codeforces 538E】Demiurges Play Again

    [题目链接]:http://codeforces.com/problemset/problem/538/E [题意] 给你一棵树; 有两个人,分别从根节点开始,往叶子节点的方向走; 每个人每次只能走一 ...

  3. 网页载入进度条中的javascript

    demo地址:http://output.jsbin.com/buquyedosa 思路例如以下:代码都有凝视,就不一一介绍了. <!DOCTYPE html> <html> ...

  4. 如何保证对象线程内唯一:数据槽(CallContext)

    CallContext 是类似于方法调用的线程本地存储区的专用集合对象,并提供对每个逻辑执行线程都唯一的数据槽.数据槽不在其他逻辑线程上的调用上下文之间共享.当 CallContext 沿执行代码路径 ...

  5. Quart 学习

    quartz版本使用2.2.1 梳理一下其中的流程,可以表示为: 0.调度器线程run() 1.获取待触发trigger 1.1数据库LOCKS表TRIGGER_ACCESS行加锁 1.2读取JobD ...

  6. UVALive - 6268 Cycling 贪心

    UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:

  7. input file HTML控件控制

    网页上添加一个input file HTML控件: 1 <input id="File1" type="file" /> 默认是这样的,所有文件类型 ...

  8. SQL Server 多种分页查询效率

    关于SQL语句分页,网上也有很多,我贴一部分过来,并且总结自己已知的分页到下面,方便日后查阅. 方法1 适用于 SQL Server 任何版本 SELECT TOP 页大小 * FROM table1 ...

  9. 分享一段官date函数用法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. SQL server 事务介绍,创建与使用

    事务(Transaction)事务是一种机制,一个操作序列,包含一组操作指令,并且把所有的命令作为一个整体一起向系统提交或撤销操作请求(即要么全部执行,要么全部不执行)---------------- ...