How to make the overflow of tab bar icon clickable in react native?

Viewed 1858

I'm creating a custom tab bar using React Navigation 5 and createBottomTabNavigator of @react-navigation/bottom-tabs,

The Problem: The Red icon is only clickable within the tab bar range, once i have crossed the grey line of the tab bar i can not click the icon.

Style of the tabbar

And i have created it using the following code for the tab screen

<Tab.Screen
    name="Scan"
    component={Scan}
    options={({ navigation }) => {
      return {
        tabBarIcon: () => <MiddleIcon navigation={navigation} />,
      };
    }}
  />

I've tried wrapping the whole view in touchable opacity but it still only touchable within the range of the tab bar

MiddleIcon Component:

const MiddleIcon = ({ navigation }) => {
  return (
    <TouchableOpacity
      onPress={() => navigation.navigate('Scan')}
      style={styles.container}>
      <View style={styles.imageContainer}>
        <Image
          source={require('../../../assets/images/shared/scan_icon.png')}
        />
      </View>
    </TouchableOpacity>
  );
};

export default MiddleIcon;

const styles = StyleSheet.create({
  container: {
    position: 'absolute',
    bottom: 20,
    height: 58,
    width: 58,
    borderRadius: 58,
    backgroundColor: colors.primaryColor,
    justifyContent: 'center',
    alignItems: 'center',
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 3,
    },
    shadowOpacity: 0.29,
    shadowRadius: 4.65,
    elevation: 7,

    flex: 1,
  },
  icon: {
    width: 40,
    height: 40,
    tintColor: '#fff',
    alignContent: 'center',
  },
  imageContainer: {
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.25,
    shadowRadius: 3.84,

    elevation: 5,
    width: 30,
    height: 30,
  },
});

Question: How to make it clickable outside the boundaries of the bottom tab bar?

2 Answers

Use zIndex on the imageContainer style

Use TouchableOpacity on the Icons to make it Clickable from react-native-gesture-handler

Related