Skip to content

Commit 38caac4

Browse files
committed
animated basic and animated button
0 parents  commit 38caac4

11 files changed

+184
-0
lines changed

.babelrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": ["babel-preset-expo"],
3+
"env": {
4+
"development": {
5+
"plugins": ["transform-react-jsx-source"]
6+
}
7+
}
8+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*

.watchmanconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

assets/icons/app.png

7 KB
Loading

assets/icons/loading.png

7 KB
Loading

exp.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "react-native-animations",
3+
"description": "An empty new project",
4+
"slug": "react-native-animations",
5+
"privacy": "public",
6+
"sdkVersion": "16.0.0",
7+
"version": "1.0.0",
8+
"orientation": "portrait",
9+
"primaryColor": "#cccccc",
10+
"icon": "./assets/icons/app.png",
11+
"loading": {
12+
"icon": "./assets/icons/loading.png",
13+
"hideExponentText": false
14+
},
15+
"packagerOpts": {
16+
"assetExts": ["ttf", "mp4"]
17+
},
18+
"ios": {
19+
"supportsTablet": true
20+
}
21+
}

jsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"allowSyntheticDefaultImports": true
5+
},
6+
"exclude": [
7+
"node_modules"
8+
]
9+
}

main.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Expo from 'expo';
2+
import React from 'react';
3+
import { StyleSheet, Text, View } from 'react-native';
4+
5+
import AnimatedBasic from './src/AnimatedBasic';
6+
import Button from './src/Button';
7+
8+
class App extends React.Component {
9+
render() {
10+
return (
11+
<View style={styles.container}>
12+
<Button />
13+
</View>
14+
);
15+
}
16+
}
17+
18+
const styles = StyleSheet.create({
19+
container: {
20+
flex: 1,
21+
backgroundColor: '#fff',
22+
alignItems: 'center',
23+
justifyContent: 'center',
24+
},
25+
});
26+
27+
Expo.registerRootComponent(App);

package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "react-native-animations",
3+
"version": "0.0.0",
4+
"description": "Hello Expo!",
5+
"author": null,
6+
"private": true,
7+
"main": "main.js",
8+
"dependencies": {
9+
"expo": "16.0.0",
10+
"react": "16.0.0-alpha.6",
11+
"react-native": "https://github.com/expo/react-native/archive/sdk-16.0.0.tar.gz"
12+
}
13+
}

src/AnimatedBasic.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { Component } from 'react';
2+
import {
3+
View,
4+
StyleSheet,
5+
Animated,
6+
Easing
7+
} from 'react-native';
8+
9+
class AnimatedBasic extends Component {
10+
componentWillMount() {
11+
this.animatedValue = new Animated.Value(100);
12+
}
13+
14+
componentDidMount() {
15+
Animated.timing(this.animatedValue, {
16+
toValue: 150,
17+
duration: 3000,
18+
easing: Easing.bounce
19+
}).start()
20+
}
21+
22+
render() {
23+
const animatedStyle = { height: this.animatedValue }
24+
return (
25+
<Animated.View style={[ styles.root, animatedStyle ]}>
26+
27+
</Animated.View>
28+
);
29+
}
30+
}
31+
32+
const styles = {
33+
root: {
34+
width: 100,
35+
height: 100,
36+
backgroundColor: '#b1bb'
37+
}
38+
}
39+
40+
export default AnimatedBasic;

src/Button.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React, { Component } from 'react';
2+
import { View, Text, TouchableWithoutFeedback, Animated } from 'react-native';
3+
4+
class Button extends Component {
5+
constructor(props) {
6+
super(props);
7+
8+
this.handlePressIn = this.handlePressIn.bind(this);
9+
this.handlePressOut = this.handlePressOut.bind(this);
10+
}
11+
12+
componentWillMount() {
13+
this.animatedValue = new Animated.Value(1);
14+
}
15+
16+
handlePressIn() {
17+
Animated.spring(this.animatedValue, {
18+
toValue: .5
19+
}).start()
20+
}
21+
22+
handlePressOut() {
23+
Animated.spring(this.animatedValue, {
24+
toValue: 1,
25+
friction: 3,
26+
tension: 40
27+
}).start()
28+
}
29+
30+
render() {
31+
const animatedStyle = {
32+
transform: [{ scale: this.animatedValue }]
33+
}
34+
35+
return (
36+
<TouchableWithoutFeedback
37+
onPressIn={this.handlePressIn}
38+
onPressOut={this.handlePressOut}
39+
>
40+
<Animated.View style={[styles.button, animatedStyle]}>
41+
<Text style={styles.text}>Press Me</Text>
42+
</Animated.View>
43+
</TouchableWithoutFeedback>
44+
);
45+
}
46+
}
47+
48+
const styles = {
49+
button: {
50+
backgroundColor: "#9C27B0",
51+
width: 100,
52+
height: 50,
53+
alignItems: "center",
54+
justifyContent: "center",
55+
borderRadius: 5
56+
},
57+
text: {
58+
color: "#fff"
59+
}
60+
}
61+
62+
export default Button;

0 commit comments

Comments
 (0)