Build WordPress App with React Native #14 : Settings Screen
Tags: reactnative, reactnativefirebase
Published: 2019-12-05 08:21:25

---
title: Build WordPress App with React Native #14 : Settings Screen
published: true
date: 2019-12-04 17:45:34 UTC
tags: React native, react native firebase
canonical_url: https://kriss.io/build-wordpress-client-app-with-react-native-14-implementing-settings-screen/
cover_image: https://cdn-images-1.medium.com/max/1024/1*0qWyQ1BHUL6FoFfa-uPTYg.png
series: Build Wordpress Client App with React Native
---

This series intends to show how I build app to serve content from my WordPress blog by using react native. Since, my blog is talking about react-native, the series and the articles are interconnected. We will learn how to set-up many packages that make our lives comfortable and learn how to deal with WordPress APIs. Here, the most prominent features talked about in the book are the dark theme , offline mode, infinite scroll and many more. You can discover much more in this series.this inspiration to do this tutorial series came from the [React Native Mobile Templates](https://www.instamobile.io/) from instamobile

In case of wanting to learn from the beginning, all the previous parts for this tutorial series are available below:

1. [Build WordPress Client App with React Native #1: Overview](https://kriss.io/build-wordpress-client-app-with-react-native-1-overview/)
2. [Build WordPress Client App with React Native #2: Setting Up Your Environment](https://kriss.io/build-wordpress-client-app-with-react-native-2-setting-up-your-environment/)
3. [Build WordPress Client App with React Native #3: Handle Navigation with React navigation](https://kriss.io/build-wordpress-client-app-with-react-native-3-handle-navigation-with-react-navigation/)
4. [Build WordPress Client App with React Native #4: Add Font Icon](https://kriss.io/build-wordpress-client-app-with-react-native-4-add-font-icon/)
5. [Build WordPress Client App with React Native #5 : Home Screen with React native paper](https://kriss.io/build-wordpress-client-app-with-react-native-5-using-react-native-paper/)
6. [Build WordPress Client App with React Native #6 : Using Html renderer and Moment](https://kriss.io/build-wordpress-client-app-with-react-native-6-using-html-renderer-and-moment/)
7. [Build WordPress Client App with React Native #7: Add pull to refresh and Infinite scroll](https://kriss.io/build-wordpress-client-app-with-react-native-7-add-pull-to-refresh-and-infinite-scroll/)
8. [Build WordPress Client App with React Native #8: Implementing SinglePost Screen](https://kriss.io/build-wordpress-client-app-with-react-native-8-implementing-singlepost-screen/)
9. [Build WordPress Client App with React Native #9: implement simple share](https://kriss.io/build-wordpress-client-app-with-react-native-9-implement-simple-share/)
10. [Build WordPress Client App with React Native #10: Setup and save bookmark](https://kriss.io/build-wordpress-client-app-with-react-native-10-setup-and-save-bookmark/)
11. [Build WordPress Client App with React Native #11: Remove and Render Bookmark](https://kriss.io/build-wordpress-client-app-with-react-native-11-remove-and-render-bookmark/)
12. [Build WordPress Client App with React Native #12: Categories screen](https://kriss.io/build-wordpress-client-app-with-react-native-12-categories-screen/)
13. [Build WordPress Client App with React Native #13: Configuring firebase in contact screen](https://kriss.io/build-wordpress-client-app-with-react-native-13-configuring-firebase-in-contact-screen/)

Now, we need to goto **Setting.js** file and implement a Contact menu option UI in order to navigate to the Contact screen. For that, we need to use the code from the following code snippet in the **Setting.js** file:

```javascript
  import React, {Component} from 'react';
    import {View, TouchableOpacity} from 'react-native';
    import {List, Icon} from 'react-native-paper';
    class Setting extends Component {
      constructor(props) {
        super(props);
        this.state = {};
      }
      render() {
        return (
          <View>
            <TouchableOpacity
              onPress={() => this.props.navigation.navigate('Contact')}>
              <List.Item
                title="Contact Us"
                left={() => <List.Icon icon="chevron-right" />}
              />
            </TouchableOpacity>
          </View>
        );
      }
    }
    export default Setting;
```
Here, we have imported all the necessary packages and components in order to
implement the Settings screen UI. Then, we used the TouchableOpacity component
wrapping the List component in order to show the Contact option in the Settings
screen. Then, we have set up the navigation config in the TouchableOpacity
component.

Hence, we will get the following result in the emulator screen:

![](https://cdn-images-1.medium.com/max/800/0*bDYru5gxPtZkCY4l.png)

![](https://cdn-images-1.medium.com/max/800/0*U7xLvKP1z_qpQn_v.png)

As we can see, we have got the Contact option in the Settings screen.

#### Implementing Contact Screen

Here, we need to create a new screen called Contact screen. For that, we need to
create a new file called **Contact.js** in the **‘./screens/’** folder. Then, we
need to import the **Contact.js** file to the **App.js** file and then add it to
the stack navigator as shown in the code snippet below:
```javascript
    const StackNavigator = createStackNavigator({
      DashboardTabNavigator: DashboardTabNavigator,
      SinglePost: SinglePost,
      CategorieList: CategorieList,
      Contact:Contact
    });
```
Now, we need to go back to the Contact.js file and import the required packages.
Here, we are going to make use of the react-native-firebase and
tcomb-form-native packages as shown in the code snippet below:
```javascript
    import {
      View,
      StyleSheet,
      TouchableHighlight,
      Text,
      Alert,
      ActivityIndicator,
      Image,
    } from 'react-native';
    import firebase from 'react-native-firebase'
    import t from 'tcomb-form-native'; // 0.6.9
    export default class Contact extends Component {
      constructor(props) {
        super(props);
        this.state = {
          submit: false
        };
      }
    }
```
Here, we have defined a state called submit which will handle the submitting of
form to firebase.

Now, we are going to make use of tcomb-form-native package to initialize the
form instance and define the structure of the form. Then, we are going to use it
in the render() function as shown in the code snippet below:
```javascript
    render() {
        const Form = t.form.Form;
        const ContactForm = t.struct({
          email: t.String,
          name: t.String,
          message: t.String,
        });
        return (
          <View style={styles.container}>
            <Form type={ContactForm}  />
          </View>
        );
    const styles = StyleSheet.create({
      container: {
        justifyContent: 'center',
        marginTop: 50,
        padding: 20,
        backgroundColor: '#ffffff',
      },
      buttonText: {
        fontSize: 18,
        color: 'white',
        alignSelf: 'center',
      },
      button: {
        height: 36,
        backgroundColor: '#48BBEC',
        borderColor: '#48BBEC',
        borderWidth: 1,
        borderRadius: 8,
        marginBottom: 10,
        alignSelf: 'stretch',
        justifyContent: 'center',
      },
    });
```
Hence, we will get the following result in the emulator screens:

![](https://cdn-images-1.medium.com/max/800/0*FR5bsdkKFw_QRx6y.png)

![](https://cdn-images-1.medium.com/max/800/0*lA2H79sJghoOQCHb.png)

As we can, we have got the form interface in the Contact screen.

Now, instead of using the text field in the message input, we are going to
implement the text area into it. For that, we need to use the code from the
following code snippet:
```javascript
    const Form = t.form.Form;
    const options = {
      fields: {
        message: {
          multiline: true,
          stylesheet: {
            ...Form.stylesheet,
            textbox: {
              ...Form.stylesheet.textbox,
              normal: {
                ...Form.stylesheet.textbox.normal,
                height: 150,
              },
              error: {
                ...Form.stylesheet.textbox.error,
                height: 150,
              },
            },
          },
        },
      },
    };
```
Here, we have defined the options object in order to configure the Form
component. Now, we need to integrate the options constant to the Form component
as shown in the code snippet below:

    <Form
      type={ContactForm}
      options={options}
    />

Hence, we will get the result as shown in the following emulator screen on the
next page:

![](https://cdn-images-1.medium.com/max/800/0*YZCwB-CpB334pkXO.png)

![](https://cdn-images-1.medium.com/max/800/0*fymXtHcVubKLbqih.png)

#### Saving message to Firebase database

Now, we are going to implement the feature to save the users message to the
Firebase database. For that, we need to use the ref prop to get the value from
the form as shown in the code snippet below:
```javascript
    <Form
      type={ContactForm}
      ref={c => (this._form = c)}
      options={options}
    />
```
Next, we need to create a function called handleSubmit which will get the value
from the form and submit to the firebase. For now, we are going to add a simple
log to it as shown in the code snippet below:
```javascript
    handleSubmit = async () => {
        // this.setState({submit: true});
        const value = this._form.getValue();
        console.log(value)
    }
```
Now, we will add the firebase configuration to it as shown in the code snippet
below:
```javascript
    firebase
       .database()
       .ref('contact/')
       .push(value)
       .then(res => {
         Alert.alert('thank for reaching me')
       })
       .catch(err => {
         console.error(err);
       });
```
Here, we have used the firebase module to call the database function. Then, we have used the contact ref function and pushed tie value. As a result, we have shown an alert box.

Hence, we will get the following result in the emulator screens on the next page:

 

![](https://kriss.io/wp-content/uploads/2019/12/img_5de7f01f57514.png)

The result on firebase:

![](https://kriss.io/wp-content/uploads/2019/12/img_5de7f06e922bb.png)

## Summary

In this chapter we leaned how to set up the react-native-firebase in the react native application.Then, we learned how to make use of components from tcomb-form-native package in order to implement the form in the Contact screen. Then, we implemented the sending of message to the firebase.

The post [Build WordPress Client App with React Native #14 : Implementing Settings Screen](https://kriss.io/build-wordpress-client-app-with-react-native-14-implementing-settings-screen/) appeared first on [Kriss](https://kriss.io).