Commit 72a13429 authored by Kerem Çubuk's avatar Kerem Çubuk
Browse files

Add: Group Animation setup

parent 462313b8
Showing with 185 additions and 89 deletions
+185 -89
......@@ -250,3 +250,183 @@ startAnimation = () => {
Your spinner is ready to use, just run your application.
<!---------------------- Group of Animation --------------------------->
<br />
<br />
<a name="group-animation"></a>
## 3. Group Animation
In this section, we will try to work all animation in one screen component. If you wonder that follow the steps, how to use it. :D
For the last time, we will add `Animated` to our project. Open `GroupAnimation` file.
```javascript
import {
Text,
View,
StyleSheet,
Animated, // Add this line
TouchableOpacity
} from "react-native";
```
Let's create our, render section for seeing animations. Firstly define states before the return. We will use it in the next steps.
```javascript
render() {
let { slideUpValue, fadeValue, SlideInLeft } = this.state; // Add this line
return (
<View>YOUR COMPONENTS</View>
)
}
```
**First Animation:**
```xml
<View style={styles.container}>
<Animated.View
style={{
transform: [
{
translateX: slideUpValue.interpolate({
inputRange: [0, 1],
outputRange: [-600, 0]
})
}
],
flex: 1,
height: 250,
width: 200,
borderRadius: 12,
backgroundColor: "#c00",
justifyContent: "center"
}}
>
<Text style={styles.text}>SlideUp </Text>
</Animated.View>
</View>
```
**Second Animation:**
Add Second Animation to render.
```xml
<View style={styles.container}>
<!-- Under First Animation -->
<Animated.View
style={{
transform: [
{
translateY: SlideInLeft.interpolate({
inputRange: [0, 1],
outputRange: [600, 0]
})
}
],
flex: 1,
height: 250,
width: 200,
borderRadius: 12,
backgroundColor: "#347a2a",
justifyContent: "center"
}}
>
<Text style={styles.text}>SlideInLeft</Text>
</Animated.View>
</View>
```
**Third Animation:**
Add Third Animation to render.
```xml
<View style={styles.container}>
<!-- Under First Animation -->
<!-- Under Second Animation -->
<Animated.View
style={{
opacity: fadeValue,
flex: 1,
height: 250,
width: 200,
borderRadius: 12,
backgroundColor: "#f4f",
justifyContent: "center"
}}
>
<Text style={styles.text}>Fade</Text>
</Animated.View>
</View>
```
And now, we define `state`, `first animation`, `second animation` and `third animation` in the render area. We will define `defaultState` in `constructor.`
```javascript
constructor(props) {
super(props)
this.state = {
SlideInLeft: new Animated.Value(0),
slideUpValue: new Animated.Value(0),
fadeValue: new Animated.Value(0)
};
}
```
> Note: Be patient these are last steps for complete whole group animation. :D
We will add a function for using animation in one page. The function is called `startAnimation()`.
```javascript
startAnimation = () => {
return Animated.parallel([
Animated.timing(this.state.SlideInLeft, {
toValue: 1,
duration: 500,
useNativeDriver: true
}),
Animated.timing(this.state.fadeValue, {
toValue: 1,
duration: 500,
useNativeDriver: true
}),
Animated.timing(this.state.slideUpValue, {
toValue: 1,
duration: 500,
useNativeDriver: true
})
]).start();
};
```
Call your `startAnimation()` function in render area.
```xml
<View style={styles.container}>
<TouchableOpacity style={styles.btn} onPress={() => this.startAnimation()}>
<Text style={styles.textBtn}>Start</Text>
</TouchableOpacity>
<!-- First Animation -->
<!-- Second Animation -->
<!-- Third Animation -->
</View>
```
Are you ready for running your app?
If you are ready, start your app and go to `Group Animation` screen.
You can be happy now, we learned `Animation` in React Native <3
\ No newline at end of file
......@@ -3,101 +3,18 @@ import {
Text,
View,
StyleSheet,
Animated,
TouchableOpacity
} from "react-native";
export default class GroupAnimation extends Component {
constructor(props) {
super(props)
this.state = {
ready: false,
SlideInLeft: new Animated.Value(0),
slideUpValue: new Animated.Value(0),
fadeValue: new Animated.Value(0)
};
this.state = {};
}
startAnimation = () => {
return Animated.parallel([
Animated.timing(this.state.SlideInLeft, {
toValue: 1,
duration: 500,
useNativeDriver: true
}),
Animated.timing(this.state.fadeValue, {
toValue: 1,
duration: 500,
useNativeDriver: true
}),
Animated.timing(this.state.slideUpValue, {
toValue: 1,
duration: 500,
useNativeDriver: true
})
]).start();
};
render() {
let { slideUpValue, fadeValue, SlideInLeft } = this.state;
return (
<View style={styles.container}>
<TouchableOpacity style={styles.btn} onPress={() => this.startAnimation()}>
<Text style={styles.textBtn}>Start</Text>
</TouchableOpacity>
<Animated.View
style={{
transform: [
{
translateX: slideUpValue.interpolate({
inputRange: [0, 1],
outputRange: [-600, 0]
})
}
],
flex: 1,
height: 250,
width: 200,
borderRadius: 12,
backgroundColor: "#c00",
justifyContent: "center"
}}
>
<Text style={styles.text}>SlideUp </Text>
</Animated.View>
<Animated.View
style={{
transform: [
{
translateY: SlideInLeft.interpolate({
inputRange: [0, 1],
outputRange: [600, 0]
})
}
],
flex: 1,
height: 250,
width: 200,
borderRadius: 12,
backgroundColor: "#347a2a",
justifyContent: "center"
}}
>
<Text style={styles.text}>SlideInLeft </Text>
</Animated.View>
<Animated.View
style={{
opacity: fadeValue,
flex: 1,
height: 250,
width: 200,
borderRadius: 12,
backgroundColor: "#f4f",
justifyContent: "center"
}}
>
<Text style={styles.text}>Fade </Text>
</Animated.View>
<Text style={styles.text}>Group Animation</Text>
</View>
);
}
......
......@@ -11,7 +11,6 @@ export default class GroupAnimation extends Component {
constructor(props) {
super(props)
this.state = {
ready: false,
SlideInLeft: new Animated.Value(0),
slideUpValue: new Animated.Value(0),
fadeValue: new Animated.Value(0)
......@@ -63,7 +62,7 @@ export default class GroupAnimation extends Component {
justifyContent: "center"
}}
>
<Text style={styles.text}>SlideUp </Text>
<Text style={styles.text}>SlideUp</Text>
</Animated.View>
<Animated.View
style={{
......@@ -83,7 +82,7 @@ export default class GroupAnimation extends Component {
justifyContent: "center"
}}
>
<Text style={styles.text}>SlideInLeft </Text>
<Text style={styles.text}>SlideInLeft</Text>
</Animated.View>
<Animated.View
style={{
......@@ -96,7 +95,7 @@ export default class GroupAnimation extends Component {
justifyContent: "center"
}}
>
<Text style={styles.text}>Fade </Text>
<Text style={styles.text}>Fade</Text>
</Animated.View>
</View>
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment