The Founded.in

    About Us

    The Founded.in is dedicated to sharing insights and knowledge on various topics.

    Quick Links

    • Home
    • Categories
    • About
    • Contact

    Categories

    • Technology
    • Education
    • Lifestyle
    • Travel
    • Food

    Follow Us

    © 2025 The Founded.in. All rights reserved.

    Privacy PolicyTerms of Service

    Disclaimer: The content on this blog is provided for informational purposes only and reflects the opinions of the authors. We do not guarantee the accuracy, reliability, or completeness of any information. Any matching functionality within the site is for user convenience only and should not be considered as professional advice or recommendations. External links provided are not endorsed, and we are not responsible for the content of any linked sites. Use of this site and its features is at your own risk. By using this site, you agree to this disclaimer and the terms of service.

    5 Different Ways to Create Buttons in React Native: A Complete Guide

    In React Native, you can create buttons using various methods depending on your styling needs and functionality. Below are different approaches with examples:

    1. Using Button Component (Built-in)

    The simplest way is to use the Button component provided by React Native.

    import React from 'react';
    import { Button, View, Alert } from 'react-native';
    
    const App = () => {
      return (
        <View style={{ margin: 20 }}>
          <Button
            title="Press Me"
            onPress={() => Alert.alert('Button Pressed')}
          />
        </View>
      );
    };
    
    export default App;
    

    2. Using TouchableOpacity for Customizable Buttons

    TouchableOpacity allows you to create more customizable buttons with different styles.

    import React from 'react';
    import { TouchableOpacity, Text, StyleSheet, Alert } from 'react-native';
    
    const CustomButton = () => {
      return (
        <TouchableOpacity style={styles.button} onPress={() => Alert.alert('Custom Button Pressed')}>
          <Text style={styles.buttonText}>Press Me</Text>
        </TouchableOpacity>
      );
    };
    
    const styles = StyleSheet.create({
      button: {
        backgroundColor: '#007bff',
        padding: 10,
        borderRadius: 5,
        alignItems: 'center',
      },
      buttonText: {
        color: '#fff',
        fontSize: 16,
      },
    });
    
    export default CustomButton;
    

    3. Using TouchableHighlight for Highlight Effects

    TouchableHighlight gives a visual feedback (highlight) when the button is pressed.

    import React from 'react';
    import { TouchableHighlight, Text, StyleSheet, Alert } from 'react-native';
    
    const HighlightButton = () => {
      return (
        <TouchableHighlight
          style={styles.button}
          underlayColor="#0056b3"
          onPress={() => Alert.alert('Highlight Button Pressed')}
        >
          <Text style={styles.buttonText}>Press Me</Text>
        </TouchableHighlight>
      );
    };
    
    const styles = StyleSheet.create({
      button: {
        backgroundColor: '#007bff',
        padding: 10,
        borderRadius: 5,
        alignItems: 'center',
      },
      buttonText: {
        color: '#fff',
        fontSize: 16,
      },
    });
    
    export default HighlightButton;
    

    4. Using TouchableWithoutFeedback for Custom Gestures

    TouchableWithoutFeedback provides even more flexibility, but you need to manage your own styles and feedback.

    import React from 'react';
    import { TouchableWithoutFeedback, Text, View, StyleSheet, Alert } from 'react-native';
    
    const FeedbackButton = () => {
      return (
        <TouchableWithoutFeedback onPress={() => Alert.alert('Button Pressed')}>
          <View style={styles.button}>
            <Text style={styles.buttonText}>Press Me</Text>
          </View>
        </TouchableWithoutFeedback>
      );
    };
    
    const styles = StyleSheet.create({
      button: {
        backgroundColor: '#28a745',
        padding: 10,
        borderRadius: 5,
        alignItems: 'center',
      },
      buttonText: {
        color: '#fff',
        fontSize: 16,
      },
    });
    
    export default FeedbackButton;
    

    5. Using Pressable for More Advanced Touch Handling

    Pressable gives you full control over touch events, allowing you to respond to different states like press, hover, etc.

    import React from 'react';
    import { Pressable, Text, StyleSheet, Alert } from 'react-native';
    
    const PressableButton = () => {
      return (
        <Pressable
          style={({ pressed }) => [
            {
              backgroundColor: pressed ? '#0056b3' : '#007bff',
            },
            styles.button,
          ]}
          onPress={() => Alert.alert('Pressable Button Pressed')}
        >
          <Text style={styles.buttonText}>Press Me</Text>
        </Pressable>
      );
    };
    
    const styles = StyleSheet.create({
      button: {
        padding: 10,
        borderRadius: 5,
        alignItems: 'center',
      },
      buttonText: {
        color: '#fff',
        fontSize: 16,
      },
    });
    
    export default PressableButton;
    

    Each method offers different flexibility, with the built-in Button being the easiest but least customizable, while TouchableOpacity, TouchableHighlight, and Pressable allow for deeper control over the button’s appearance and behavior.