visit
This tutorial is the third part of our React Native Plant App tutorial series. In the , we successfully implemented all the components in our
'./components'
folder. This tutorial is the continuation of the same tutorial from where we left off in the last part. So, it is recommended to go through the previous part in order to get insight and knowledge of the overall project.In case of wanting to learn from the beginning, all the parts for this tutorial series are available below:As mentioned in the previous parts, this tutorial series was inspired by the React Native App Templates that accommodates a wide variety of mobile application templates written in React Native and powered by universal features and design. These app templates allow us to implement our own apps and even start our own startups. And, this third part is also the continuation of coding implementations and designs from the Youtube video tutorial by for the Plant App. The video tutorial delivers the coding implementation of the overall app very thoroughly but without any verbal guidance. This tutorial series is the implementation of the same coding style and designs in the form of the article. Thus, the learners can go through each step and take their time understanding the implementations.So, let us begin!!
Here, we are going to implement some of the UI sections of the Welcome screen in the
Welcome.js
file. First, we are going to set the header or slogan section of the Welcome screen. For that, we need to use the code from the following code snippet in the render() function of Welcome.js file:render(){
return (
<Block>
<Block center bottom flex={0.4}>
<Text h1 center bold>
Your Home.
<Text h1 primary> Greener.</Text>
</Text>
<Text h3 gray2 style={{ marginTop: theme.sizes.padding / 2 }}>
Enjoy the experience.
</Text>
</Block>
<Block center middle>
<Text>Welcome</Text>
</Block>
</Block>
);
}
Here, we have used the
Block
component as well as some Text
components. These components are not from the react-native package. Hence, these are the pre-defined custom components that we implemented in the earlier tutorial part. We have also assigned some props to the components which are already configured inside the component files. Thus, we need to import the constant theme.js
file to the Welcome.js
file:import { theme } from '../constants';
renderIllustrations(){
return(
<Block>
<Text>Image</Text>
</Block>
)
}
This section will contain the
Delimiter Dots
as per the number of Illustrations. The idea is to animate to active dot whenever we scroll the Illustrations. For this, we are going to use the function called renderSteps() which is provided in the code snippet below:renderSteps(){
return(
<Block>
<Text>* * *</Text>
</Block>
)
}
Now, we need to call both the functions into our render() function as shown in the code snippet below:
render(){
return (
<Block>
<Block center bottom flex={0.4}>
<Text h1 center bold>
Your Home.
<Text h1 primary> Greener.</Text>
</Text>
<Text h3 gray2 style={{ marginTop: theme.sizes.padding / 2 }}>
Enjoy the experience.
</Text>
</Block>
<Block center middle>
{this.renderIllustrations()}
{this.renderSteps()}
</Block>
</Block>
);
}
Here, we are going to add buttons to the bottom of the Welcome screen just below the Steps section. We are going to add three buttons for
Login
, Sign up
and Terms and Conditions(TOC)
. For that, we need to use the code from the following code snippet in the render() function:<Block center middle>
{this.renderIllustrations()}
{this.renderSteps()}
</Block>
<Block middle flex={0.5} margin={[0, theme.sizes.padding * 2]}>
<Button>
<Text center>Login</Text>
</Button>
<Button>
<Text center>Signup</Text>
</Button>
<Button>
<Text center>Terms of service</Text>
</Button>
</Block>
Here, we have added another
Block
component below the Block component wrapping function calls. This Block
component wraps the three Button
components with Text
components. Hence, we will get the following result in our emulator screen:Before applying style props to the
Button
and Text
component, we need to make a slight configuration to the Button.js
file of the './components/'
folder. For that, we need to install the package called . This package provides a React component that renders a gradient view. Now, we are going to import this package as LinearGradient
in the Button.js
file as shown in the code snippet below:import { LinearGradient } from 'expo-linear-gradient';
Note that we installed this package because the expo package that provided the LinearGradient component was already separated out to this package. Now, we are going to add some style props to the
Button
components as shown in the code snippet below:<Block middle flex={0.5} margin={[0, theme.sizes.padding * 2]}>
<Button gradient>
<Text center semibold white>Login</Text>
</Button>
<Button shadow>
<Text center semibold>Signup</Text>
</Button>
<Button>
<Text center caption gray>Terms of service</Text>
</Button>
</Block>
Here, we have added gradient and shadow prop to our buttons. We have also styled our
Text
components with some color and position props. Hence, we will get the following result in our emulator screen: As we can see, we have got beautiful buttons in our Welcome screen. The Login button has a gradient color to it and the
Signup
button has a shadow style. Now, we should already have guessed that these two buttons navigate to the Login
and Signup
screen. So, we are going to add the navigation configuration to them now. Here, we are going to add the navigation configuration to buttons. For that, we are going to use the navigate() function provided by the navigation prop as shown in the code snippet below:
<Block middle flex={0.5} margin={[0, theme.sizes.padding * 2]}>
<Button gradient onPress={() => this.props.navigation.navigate('Login')}>
<Text center semibold white>Login</Text>
</Button>
<Button shadow onPress={() => this.props.navigation.navigate('SignUp')}>
<Text center semibold>Signup</Text>
</Button>
<Button onPress={() => {}}>
<Text center caption gray>Terms of service</Text>
</Button>
</Block>
Here, we have added the navigation config to onPress event of the Button component. But, we might remember that we have commented out the Login and SignUp screens in our index.js file of the './navigation' folder. Now, it is now time to uncomment the Login and SignUp screen in the index.hs file of the './navigation/' folder. Now, we need to add a simple React Native Template to these two screens. In
Login.js
file, we are going to use the code from the following code snippet to implement a simple template:import React from 'react';
import { StyleSheet } from 'react-native';
import { Button, Block, Text } from '../components';
export default class Welcome extends React.Component {
static navigationOptions = {
header : null
}
render(){
return (
<Block middle>
<Text>Login</Text>
</Block>
);
}
}
const styles = StyleSheet.create({
});
Same goes for SignUp screen in the
Signup.js
file:import React from 'react';
import { StyleSheet } from 'react-native';
import { Button, Block, Text } from '../components';
export default class Welcome extends React.Component {
static navigationOptions = {
header : null
}
render(){
return (
<Block middle>
<Text>Sign Up</Text>
</Block>
);
}
}
const styles = StyleSheet.create({
});
This tutorial is the third part of the React Native Plant App tutorial series. In this part, we continued from where we left off in the second part of this tutorial series. In this part of the tutorial, we implemented the slogan section of our Welcome screen by using our predefined custom components. Then, we separated out the functions which will return the templates for
Illustrations
and Steps
section. Lastly, we learned how to make use of the Button
component to implement buttons and style them with different props as well as configure them with the navigation features.In the next part of this tutorial series, we are going to implement the Illustrations and Steps section that we separated out in this tutorial part.So, Stay Tuned folks!!!