How to create button group in React Native

In this React Native source code example, we are going to learn how to create button group in React Native.

This is a source code example you can copy and adopt to your React Native project without reinventing the wheels.

import React, {Component} from 'react';
import {StyleSheet, Text, View,TouchableOpacity} from 'react-native';

export default class App extends Component{
  render() {
    return (
      <View style={styles.container}>
          <TouchableOpacity style={styles.button1}>
            <Text>Button 1</Text>
          </TouchableOpacity>

          <TouchableOpacity style={styles.button2}>
            <Text>Button 2</Text>
          </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  button1:{
    paddingHorizontal:20,
    paddingVertical:15,
    backgroundColor:'#c37dc6',
    marginRight:20,
    borderRadius:8
  },
  button2:{
    paddingHorizontal:20,
    paddingVertical:15,
    backgroundColor:'#27ddc5',
    borderRadius:8
  },
  container: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
});

 

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment