How To Build WordPress App with React Native Part #17: Fixing react-native-render-html

Author profile picture


React native Developer ,Coffee addict

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 App Templates from instamobile
Here, the components from the react-native-render-html do not change the theme automatically. So, we need to fix them as well. For that, we are going to provide the higher-order component named
from the react-native-paper package and pass the screens into it.
First, we need to make imports to the Home.js file as shown in the code snippet below:
import {Headline,Card, withTheme} from 'react-native-paper';
Then, while exporting the Home screen Home component, we need to wrap it with the 
module fro the react-native-paper package as shown in the code snippet below:
export default withTheme(Home);
Now, we will be able to access the theme variable in the screen props a shown in the code snippet below:
render() {
        const {colors} = this.props.theme;
        return (
Next, we need to pass the color code to the tagStyles prop of the
 component as shown in the code snippet below:
      tagsStyles={{p: {color: colors}}}
This process is required in other screens as well. So instead of repeating the same process again and again, we are going to implement the new component which can be shared in all the screens.

Implementing Card component

Here, we are going to implement the card component which represents the list of cards that displays the articles in the Home, Categorie and Bookmark screens.
For that, we need to create a new file called Cards.js in the
folder. Then, we need to use the code from the following cdode snippet into the Cards.js file:
 import React, {Component, useContext} from 'react';
    import {View, StyleSheet, TouchableOpacity} from 'react-native';
    import {Avatar, Button, Card, Title, Paragraph} from 'react-native-paper';
    import HTMLRender from 'react-native-render-html';
    import moment from 'moment';
    export default ({item, navigation, textColor}) => {
      return (
          onPress={() =>
            navigation.navigate('SinglePost', {
                shadowOffset: {width: 5, height: 5},
                width: '90%',
                borderRadius: 12,
                alignSelf: 'center',
                marginBottom: 10,
              <Paragraph>Published on {moment(}</Paragraph>
            <Card.Cover source={{uri: item.jetpack_featured_media_url}} />
                  tagsStyles={{p: {color: textColor}}}
Here, we have imported and implemented every component necessary to display the card interface in the screens. The steps we have undertaken are provided below:
  • First, we receive the required prop parameters from the parent screens or components
  • Second, we implement the UI of Card component as same that was previously shown in the Home and other screens
  • We also configure the navigation from the react-navigation event passed down as prop
  • We configure the 
     from theme variable passed down as prop
Now, we need to import the Card.js file back to the Home.js file and use it to display the card templates in the Home screen. For that, we need to use the code from the following code snippet:
              onRefresh={() => this.onRefresh()}
              renderItem={({item}) => (
              keyExtractor={item =>}
Here, we have imported the Card.js file as a 
component and used it inside the 
component. The 
component is set with all the necessary props to pass down to Card.js.
Hence, we will get the following result in the emulator screens:


In this chapter, we learned how to use the 
component from the react-native-paper package in order to change our UI theme made using the components from this package to dark.


The Noonification banner

Subscribe to get your daily round-up of top tech stories!