DEV Community

vidvatek
vidvatek

Posted on • Originally published at vidvatek.com

How to Create Icon Button with Text in React Native

Hey there! In this tutorial, I'll walk you through the process of crafting stylish and interactive icon buttons with accompanying text in React Native.

We'll delve into the intricacies of combining icons and text to create a more engaging user experience for your mobile apps.

This tutorial focuses on demonstrating how to create stylish and functional custom buttons with both icons and text in React Native.

By the end of this article, you'll have a clear understanding of implementing how to create icon buttons with text in react native and react native button styles.

Let's dive into the step-by-step process of creating and styling the React native button with icons and text.

Step 1: Set Up Your React Native Project

Ensure that you have a React Native project set up using either Expo or React Native CLI. You can use the following command for React Native CLI:

expo init IconButtonExample
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Dependencies

For this example, we'll use React Native Vector Icons for the icon. Install these packages using npm or yarn:

# For React Native Vector Icons
npm install react-native-vector-icons
Enter fullscreen mode Exit fullscreen mode

Step 3: Import Necessary Components

In your component file (e.g., App.js), import the required components:

import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import FontAwesome from 'react-native-vector-icons/FontAwesome';

export default function App() {
    return (
      <View style={styles.container}>
        <TouchableOpacity
          style={{ 
            backgroundColor:'red',
            borderWidth:1,
            padding:10,
            borderColor:'red'
          }}
        >
        <Text style={{ color:'white', fontSize:17,fontWeight: '400' }}><FontAwesome name='trash-o' size={20} color='white'/> Delete</Text>
        </TouchableOpacity>
      </View>
    );
}

const styles = StyleSheet.create({
  container: {
    flex:1,
    backgroundColor: '#fff',
    justifyContent: 'center',
    alignItems:'center'
  },
});
Enter fullscreen mode Exit fullscreen mode

Step 4: Run Your React Native App

Run your app using the following command:

expo start
Enter fullscreen mode Exit fullscreen mode

Now, you should have a basic icon button with text in your React Native app.

Top comments (0)