[React Native] Animate the Scale of a React Native Button using Animated.spring
2017-11-06 20:38
344 查看
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.
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(1); } handlePressIn() { Animated.spring(this.animatedValue, { toValue: .5 }).start() } handlePressOut() { Animated.spring(this.animatedValue, { toValue: 1, friction: 3, tension: 40 }).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: 1, justifyContent: 'center', alignItems: 'center', }, button: { backgroundColor: "#333", width: 100, height: 50, alignItems: "center", justifyContent: "center", }, text: { color: "#FFF" } }); AppRegistry.registerComponent('animatedbasic', () => animatedbasic);
相关文章推荐
- [React Native] Animate Styles of a React Native View with Animated.timing
- 【react native】the Haste package `react-native-vector-icons` was found.
- The Caching Relationships of S3 / CloudFront / ReactNative
- [ReactVR] Animate Text, Images, Views, and 3D Elements Using the Animated Library in React VR
- [React Native] Dismiss the Keyboard in React Native
- Simple example of using the Java Native Interface
- [转] What is the point of redux when using react?
- react native生成APP报错:You have not accepted the license agreements of the following SDK components:
- Simple example of using the Java Native Interface(JNI)
- Mobile JavaScript Apps: The Dawn of React Native
- [React Native] Use the SafeAreaView Component in React Native for iPhone X Compatibility
- Photoshop CS2 RAW : Using Adobe Camera Raw, Bridge, and Photoshop to Get the Most out of Your Digita
- using multiple versions of the SDK
- 【React Native】React Native 的开发路(Windows 开发环境配置)
- 严重: The web application [/native] created a ThreadLocal with key of type
- How to pass the paramater of Node.js or io.js into native C/C++ function.
- csharp: using OleDb Getting the identity of the most recently added record
- Array.forEach() and Using square brackets to obtain the value of a property
- Hitting the database(Chapter 5 of Spring In Action)
- You are using version 6.4.1 of the AdMob SDK which is non-compliant with the Google Play Ad Policy