1566180580
The animations are an important part of the UX of an app, and interacting with the user using the animations create a better experience for the user, the most successful user experience are made with animations, that’s why we are goin to play around animations in React Native, technically React Native provide a great animations API that give us the ability to do different transitions and the animations .
New to React Native? check my article introduction to React Native check this out!
You may want how to style a React Native app and the options you can use to do the Job check Styling in React Native.
Now, what are we gonna is create animations like Fade
,slideUp
, slideDown
, rotate
..etc. using the animations API.
A good to mention we will be comparing the examples we are going to create with rnal (react native animations library) the library I’ve created a library that does that all the kind of the animations you may want use.
First, of all to start using animations, we are using Animated
module that react-native provides to do the magic things for us
LayoutAnimation !!!
import {Animated} from "react-native";
Let’s start first with Fade
The Animated
method takes parameters as values and turns those values into animated values then we can use those values to animate our
Components, okay! show me the code!
import React, { Component } from "react";
import {
Text,
View,
StyleSheet,
Animated,
TouchableOpacity
} from "react-native";
export default class Fade extends Component {
state = {
fadeValue: new Animated.Value(0)
};
_start = () => {
Animated.timing(this.state.fadeValue, {
toValue: 1,
duration: 1000
}).start();
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={styles.btn} onPress={() => this._start()}>
<Text style={styles.textBtn}>Start</Text>
</TouchableOpacity>
<Animated.View
style={{
opacity: this.state.fadeValue,
height: 250,
width: 200,
margin: 5,
borderRadius: 12,
backgroundColor: "#347a2a",
justifyContent: "center"
}}
>
<Text style={styles.text}>Fade </Text>
</Animated.View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFF",
alignItems: "center",
justifyContent: "center"
},
item: {},
btn: {
backgroundColor: "#480032",
width: 100,
height: 40,
padding: 3,
justifyContent: "center",
borderRadius: 6
},
text: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
textAlign: "center"
},
item1: {
backgroundColor: "red",
padding: 20,
width: 100,
margin: 10
},
textBtn: {
color: "#f4f4f4",
fontWeight: "bold",
textAlign: "center"
}
});
Let’s break it down!
First, we need to initialize a value so we can give this value to the Animated
method :
state = {
fadeValue: Animated.Value(0)
};
Then let’s create a function called _start
that will start our animations:
_start = () => {
return Animated.timing(this.state.fadeValue, {
toValue: 1, // output
duration: 3000, // duration of the animation
}).start();
};
What we just did here? we used timing
method from Animated
, it takes some values:
start()
callback that starts the animations!Now we have an animated value, the next step is to use it to animate the component. we use Animated.View
as a wrapper to our component in order to make the animations happen !
<Animated.View
style={{
opacity: this.state.fadeValue,
height: 250,
width: 200,
margin: 5,
borderRadius: 12,
backgroundColor: "#347a2a",
justifyContent: "center"
}}
>
<Text style={styles.text}>Fade </Text>
</Animated.View>
You see we passed the fadeValue
to the opacity property so we can handle the opacity of the element so when the component start appears it happens smoothly and in an animated behavior! and that gives us the fade
animation !
Now let's call the _start()
function when an action is taken , in our case we call the function when button
is clicked. you can trigger the function whenever you like for example within componentDidMount()
.
<TouchableOpacity style={styles.btn} onPress={() => this._start()}>
rnal made things for us more easy to create the fade animation:
First, let’s install the package :
With Yarn
hit yarn add rnal
, or npm
run npm i rnal
Then Import The Fade
element :
import React, { Component } from "react";
import {
Text,
View,
StyleSheet,
Animated,
TouchableOpacity
} from "react-native";
import { Fade } from "rnal";
export default class MyComponent extends Component {
state = {
ready: false
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity
style={styles.btn}
onPress={() => this.setState({ ready: true })}
>
<Text style={styles.textBtn}>Start</Text>
</TouchableOpacity>
<Fade startWhen={this.state.ready}>
<View
style={{
height: 250,
width: 200,
margin: 5,
borderRadius: 12,
backgroundColor: "#347a2a",
justifyContent: "center"
}}
/>
<Text style={styles.text}>Fade </Text>
<View />
</Fade>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFF",
alignItems: "center",
justifyContent: "center"
},
item: {},
btn: {
backgroundColor: "#480032",
width: 100,
height: 40,
padding: 3,
justifyContent: "center",
borderRadius: 6
},
text: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
textAlign: "center"
},
item1: {
backgroundColor: "red",
padding: 20,
width: 100,
margin: 10
},
textBtn: {
color: "#f4f4f4",
fontWeight: "bold",
textAlign: "center"
}
});
And:
Fade has startWhen
props, it’s a type of boolean
and it determines when the animation should start by default it starts when the component mount, you can discover more options to customize your animations, check out the docs.
Let’s try with something more awesome like making the component goes from the bottom or SlideDown
animation. we will use the same code above but we need to change some values! and we will use interpolate
method to interpolate the AnimatedValue cool let’s do it 🎩
SlideDown animation
import React, { Component } from "react";
import {
Text,
View,
StyleSheet,
Animated,
TouchableOpacity
} from "react-native";
import { Fade } from "rnal";
export default class MyComponent extends Component {
state = {
ready: false,
animatedValue: new Animated.Value(0)
};
_start = () => {
Animated.timing(this.state.animatedValue, {
toValue: 1,
duration: 1000
}).start();
};
render() {
let { animatedValue } = this.state;
return (
<View style={styles.container}>
<TouchableOpacity style={styles.btn} onPress={() => this._start()}>
<Text style={styles.textBtn}>Start</Text>
</TouchableOpacity>
<Animated.View
style={{
transform: [
{
translateY: animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [-600, 0]
})
}
],
height: 250,
width: 200,
margin: 5,
borderRadius: 12,
backgroundColor: "#347a2a",
justifyContent: "center"
}}
/>
<Text style={styles.text}>Fade </Text>
<Animated.View />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFF",
alignItems: "center",
justifyContent: "center"
},
item: {},
btn: {
backgroundColor: "#480032",
width: 100,
height: 40,
padding: 3,
justifyContent: "center",
borderRadius: 6
},
text: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
textAlign: "center"
},
item1: {
backgroundColor: "red",
padding: 20,
width: 100,
margin: 10
},
textBtn: {
color: "#f4f4f4",
fontWeight: "bold",
textAlign: "center"
}
});
Replace gif with the slideDown animation
The interpolate
method takes an Object of properties.
inputRange
: The start point of the animatedValue
: for example, we want the translateX
to start from 1 level :inputRange:[0,1]
outputRange
: gives us an outputRange based on the inputRange
transform:[
{translateY:animatedValue.interpolate({
inputRange:[0,1],
outputRange:[-600,0]})}
]
Doing the same with react-native-animations-library! is more much simple, there is theSlideDown
element so you can wrap the component you want to animate!
import React, { Component } from "react";
import {
Text,
View,
StyleSheet,
Animated,
TouchableOpacity
} from "react-native";
import { Fade, SlideDown } from "rnal";
export default class MyComponent extends Component {
state = {
ready: false
};
render() {
let { animatedValue } = this.state;
return (
<View style={styles.container}>
<TouchableOpacity
style={styles.btn}
onPress={() => this.setState({ ready: true })}
>
<Text style={styles.textBtn}>Start</Text>
</TouchableOpacity>
<SlideDown
startWhen={this.state.ready}
duration={1000}
style={{
height: 250,
width: 200,
margin: 5,
borderRadius: 12,
backgroundColor: "#347a2a",
justifyContent: "center"
}}
/>
<Text style={styles.text}>Fade </Text>
<SlideDown />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFF",
alignItems: "center",
justifyContent: "center"
},
item: {},
btn: {
backgroundColor: "#480032",
width: 100,
height: 40,
padding: 3,
justifyContent: "center",
borderRadius: 6
},
text: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
textAlign: "center"
},
item1: {
backgroundColor: "red",
padding: 20,
width: 100,
margin: 10
},
textBtn: {
color: "#f4f4f4",
fontWeight: "bold",
textAlign: "center"
}
});
There are cases when need to make the animations to run indefinitely, Animated gives us Animated.loop()
method to make this happen let’s see how it works! the best example to demonstrate that is to create a spinner!
import React, { Component } from "react";
import {
Text,
View,
StyleSheet,
Animated,
TouchableOpacity
} from "react-native";
export default class Infinite extends Component {
state = {
rotateValue: new Animated.Value(0)
};
componentDidMount() {
this._start();
}
_start = () => {
Animated.loop(
Animated.timing(this.state.rotateValue, {
toValue: 1,
duration: 400,
Infinite: true
})
).start();
};
render() {
return (
<View style={styles.container}>
<Animated.View
style={{
transform: [
{
rotate: this.state.rotateValue.interpolate({
inputRange: [0, 1],
outputRange: ["0deg", "380deg"]
})
}
],
height: 50,
width: 50,
margin: 5,
borderWidth: 2,
borderColor: "#888",
borderBottomColor: "#8bffff",
borderRadius: 50,
justifyContent: "center"
}}
/>
<Text style={styles.text}>Fade </Text>
<Animated.View />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFF",
alignItems: "center",
justifyContent: "center"
},
item: {},
btn: {
backgroundColor: "#480032",
width: 100,
height: 40,
padding: 3,
justifyContent: "center",
borderRadius: 6
},
text: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
textAlign: "center"
},
item1: {
backgroundColor: "red",
padding: 20,
width: 100,
margin: 10
},
textBtn: {
color: "#f4f4f4",
fontWeight: "bold",
textAlign: "center"
}
});
Here we go!
What we just did is give the Animated.loop
our animations as an argument to run it in a loop cycle.
With react-native animation library(rnal), you can just addinifinite
props to make this happen!
import { Rotate } from "rnal";
<Rotate infinite>
<View
style={{
height: 50,
width: 50,
margin: 5,
borderWidth: 2,
borderColor: "#888",
borderBottomColor: "#8bffff",
borderRadius: 50,
justifyContent: "center"
}}
/>
<Text style={styles.text}>Fade </Text>
<View />
</Rotate>
If you take a look at the examples above, we don’t actually change much, the same function we just determine where we use then animatedValue
yeah it’s all about a value transformed to an animated value and allow us to do the animation we want using translate,scale, rotate
and all other supported animations 😛 .
That was the way we run a single animation what about making a group of animations? sequence
and parallel
methods got you covred!
Run a group of animations
We can usesequence
or parallel
methods to run a group of animations, the two methods do almost the same job, the only difference is that parallel run the group of animations at once whereas the sequence
method blocks the next animation until the previous animation is finished and done, and if one of the animations stops or break the next animation won’t be able to run. you can explore more about the two methods in the official docs.
import React, { Component } from "react";
import {
Text,
View,
StyleSheet,
Animated,
TouchableOpacity
} from "react-native";
export default class MyComponent extends Component {
state = {
ready: false,
SlideInLeft: new Animated.Value(0),
slideUpValue: new Animated.Value(0),
fadeValue: new Animated.Value(0)
};
_start = () => {
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._start()}>
<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>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFF",
alignItems: "center"
},
item: {},
btn: {
backgroundColor: "#480032",
width: 100,
height: 40,
padding: 3,
justifyContent: "center",
borderRadius: 6,
marginTop: 29
},
text: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
textAlign: "center"
},
item1: {
backgroundColor: "red",
padding: 20,
width: 100,
margin: 10
},
textBtn: {
color: "#f4f4f4",
fontWeight: "bold",
textAlign: "center"
}
});
parallel
method:sequence
:I think we are gonna stop at this point we don’t want to make this post longer. generally, there is much to talk about React Native animations and it’s a huge subject we won’t be able to cover it in one post we will have a chance to talk about other parts in upcoming articles but anyway we just covered the most parts of it and you will be able to create your own animations after reading this article. you can always use the react-native animations library I’ve created it’s so simple and easy to use. Thanks for reading, and please comment below!
#reactnative #react
1598839687
If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?
In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.
Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.
React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.
Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.
Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.
The popularity of React Native comes from its advantages. Some of its advantages are as follows:
Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.
React Native is very close to native. Consider the following aspects as described on the React Native website:
Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.
#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native
1593420654
Have you ever thought of having your own app that runs smoothly over multiple platforms?
React Native is an open-source cross-platform mobile application framework which is a great option to create mobile apps for both Android and iOS. Hire Dedicated React Native Developer from top React Native development company, HourlyDeveloper.io to design a spectacular React Native application for your business.
Consult with experts:- https://bit.ly/2A8L4vz
#hire dedicated react native developer #react native development company #react native development services #react native development #react native developer #react native
1616494982
Being one of the emerging frameworks for app development the need to develop react native apps has increased over the years.
Looking for a react native developer?
Worry not! WebClues infotech offers services to Hire React Native Developers for your app development needs. We at WebClues Infotech offer a wide range of Web & Mobile App Development services based o your business or Startup requirement for Android and iOS apps.
WebClues Infotech also has a flexible method of cost calculation for hiring react native developers such as Hourly, Weekly, or Project Basis.
Want to get your app idea into reality with a react native framework?
Get in touch with us.
Hire React Native Developer Now: https://www.webcluesinfotech.com/hire-react-native-app-developer/
For inquiry: https://www.webcluesinfotech.com/contact-us/
Email: sales@webcluesinfotech.com
#hire react native developers #hire dedicated react native developers #hire react native developer #hiring a react native developer #hire freelance react native developers #hire react native developers in 1 hour
1626928787
Want to develop app using React Native? Here are the tips that will help to reduce the cost of react native app development for you.
Cost is a major factor in helping entrepreneurs take decisions about investing in developing an app and the decision to hire react native app developers in USA can prove to be fruitful in the long run. Using react native for app development ensures a wide range of benefits to your business. Understanding your business and working on the aspects to strengthen business processes through a cost-efficient mobile app will be the key to success.
#best react native development companies from the us #top react native app development companies in usa #cost of hiring a react native developer in usa #top-notch react native developer in usa #best react native developers usa #react native
1623299374
React Native allows developers to develop mobile apps that have compatibility with Android, iOS & other operating systems. Due to the features like Native-like functionality and single code reusability and the access of various frameworks in the market, React Native has excelled as the most suitable framework for cross-platform mobile app development.
Why Do Businesses Prefer React Native App Development?
React Native is integrated with JS library that works as the fundamental for developing the app UI. Most businesses choose for developing React Native apps just due to their cross-platform & open-source features. A few further reasons why entrepreneurs & developers choose React Native app development include:
• Lowered Expedition Time
• Simple UI
• Cross-Platform and Code Sharing
• Lesser Workforce and Resources
• Community Assistance
• In-Built Elements and Reusable Codes
• Hot Reload
• JavaScript as Programming Language
• Easy to Execute Updates
Factors That Decide Cost of React Native App Development
If you are an entrepreneur or start-up and looking for cost-effective app development, React Native is one of the ideal options available out there.
• App’s UI/UX Design
• User Authorization
• App Complexity and Functionality
• App Development Team
• App Maintenance
• App Add-ons
• App Distribution
• Location of Development Company
• App Category
React Native cost depends widely on the complexity of a project or the app requirements. The price may also vary based on business requirements. React Native app development per hour can cost from $20 and $30 per hour in India. It can vary as per different locations.
Is React Native a good choice for mobile apps development?
Yes, React Native is the best choice for mobile app development as React apps are faster to develop and it offers better quality than hybrid apps. Additionally, React Native is a mature cross-platform framework.
Best React Native App Development Agency
AppClues Infotech is a leading React Native App Development Company in USA that build robust & innovative mobile app as per your specific business needs. They have a dedicated team of designers and programmers help to make a perfect mobile app.
If you have any mobile app development project in mind get in touch with AppClues Infotech and get the best solution for your business.
#react native app development cost #react native development company #best react native development company in usa #hire react native developers #hire dedicated react native developers & programmers #hire a react native development company