Toggle Button Group with Text and Icon Tabs

Screen is created using these React Native Core Components: <SafeAreaView />, <Text />, <View />, <TouchableOpacity />

import React from 'react';
import {
  StyleSheet,
  SafeAreaView,
  Text,
  View,
  TouchableOpacity,
} from 'react-native';
import FeatherIcon from 'react-native-vector-icons/Feather''@expo/vector-icons/Feather';

const tabs = [
  { name: 'My Account', icon: 'user' },
  { name: 'Company', icon: 'shopping-cart' },
  { name: 'Team', icon: 'users' },
];

export default function Example() {
  const [value, setValue] = React.useState(0);

  return (
    <SafeAreaView style={{ flex: 1, backgroundColor: '#fff' }}>
      <Text style={styles.title}>Welcome, Alex!</Text>

      <View style={styles.tabs}>
        {tabs.map(({ name, icon }, index) => {
          const isActive = index === value;

          return (
            <View
              key={name}
              style={[
                styles.tabWrapper,
                isActive && { borderBottomColor: '#6366f1' },
              ]}>
              <TouchableOpacity
                onPress={() => {
                  setValue(index);
                }}>
                <View style={styles.tab}>
                  <FeatherIcon
                    color={isActive ? '#6366f1' : '#6b7280'}
                    name={icon}
                    size={16} />

                  <Text
                    style={[styles.tabText, isActive && { color: '#6366f1' }]}>
                    {name}
                  </Text>
                </View>
              </TouchableOpacity>
            </View>
          );
        })}
      </View>

      <View style={styles.placeholder}>
        <View style={styles.placeholderInset}>
          {/* Replace with your content */}
        </View>
      </View>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  title: {
    paddingHorizontal: 16,
    fontSize: 32,
    fontWeight: '700',
    color: '#1d1d1d',
    marginBottom: 12,
  },
  tabs: {
    flexDirection: 'row',
  },
  /** Tab */
  tab: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    position: 'relative',
    overflow: 'hidden',
    paddingVertical: 10,
  },
  tabWrapper: {
    flexGrow: 1,
    flexShrink: 1,
    flexBasis: 0,
    borderColor: '#e5e7eb',
    borderBottomWidth: 2,
  },
  tabText: {
    fontSize: 13,
    fontWeight: '600',
    color: '#6b7280',
    marginLeft: 5,
  },
  /** Placeholder */
  placeholder: {
    flexGrow: 1,
    flexShrink: 1,
    flexBasis: 0,
    height: 400,
    marginTop: 0,
    paddingVertical: 24,
    paddingHorizontal: 16,
    backgroundColor: 'transparent',
  },
  placeholderInset: {
    borderWidth: 4,
    borderColor: '#e5e7eb',
    borderStyle: 'dashed',
    borderRadius: 9,
    flexGrow: 1,
    flexShrink: 1,
    flexBasis: 0,
  },
});

Dependencies

Before getting started, make sure you have all the necessary dependencies for this component. Follow the steps below to install any missing dependencies.

Explore more components

Over 100 Ready to Use React Native Components for all your needs.

Never miss a beat

Stay in the loop with our latest updates and offers - no spam, just the good stuff!