0

I'm trying to customize bottom tab in my app. I'm using react-navigation/bottom-tabs: 5.8.0. I want the following style for bottom tab

enter image description here

Is it possible to have a customized style for bottom tab?. If anybody tried this before please help.Any help would be really appreciable.Thank you.

Linu Sherin
  • 1,712
  • 7
  • 38
  • 88
  • https://stackoverflow.com/questions/62676056/create-a-curved-bottom-navigation-before-after-implementation maybe my same question answers would help. – Alireza tk Sep 07 '20 at 05:47

1 Answers1

1

I would use custom tabbar to make the bottom bars i want

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

function MyTabBar({ state, descriptors, navigation }) {
  const focusedOptions = descriptors[state.routes[state.index].key].options;

  if (focusedOptions.tabBarVisible === false) {
    return null;
  }

  return (
    <View style={{ flexDirection: 'row' }}>
      {state.routes.map((route, index) => {
        const { options } = descriptors[route.key];
        const label =
          options.tabBarLabel !== undefined
            ? options.tabBarLabel
            : options.title !== undefined
            ? options.title
            : route.name;

        const isFocused = state.index === index;

        const onPress = () => {
          const event = navigation.emit({
            type: 'tabPress',
            target: route.key,
            canPreventDefault: true,
          });

          if (!isFocused && !event.defaultPrevented) {
            navigation.navigate(route.name);
          }
        };

        const onLongPress = () => {
          navigation.emit({
            type: 'tabLongPress',
            target: route.key,
          });
        };

        return (
          <TouchableOpacity
            accessibilityRole="button"
            accessibilityStates={isFocused ? ['selected'] : []}
            accessibilityLabel={options.tabBarAccessibilityLabel}
            testID={options.tabBarTestID}
            onPress={onPress}
            onLongPress={onLongPress}
            style={{ flex: 1 }}
          >
            <Text style={{ color: isFocused ? '#673ab7' : '#222' }}>
              {label}
            </Text>
          </TouchableOpacity>
        );
      })}
    </View>
  );
}

// ...

<Tab.Navigator tabBar={props => <MyTabBar {...props} />}>
  {...}
</Tab.Navigator>

https://reactnavigation.org/docs/bottom-tab-navigator/#tabbar

Redwan Nassim
  • 367
  • 3
  • 7