【问题标题】:How to make the overflow of tab bar icon clickable in react native?react-native - 如何使标签栏图标溢出可点击?
【发布时间】:2020-09-07 22:48:11
【问题描述】:

我正在使用 React Navigation 5 和 @react-navigation/bottom-tabscreateBottomTabNavigator 创建自定义标签栏,

问题:红色图标只能在标签栏范围内点击,一旦我越过了标签栏的灰线,我就无法点击该图标。

我已经使用以下代码为标签屏幕创建了它

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

我已经尝试将整个视图包裹在可触摸的不透明度中,但它仍然只能在标签栏的范围内触摸

MiddleIcon 组件

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,
  },
});

问题:如何让它在底部标签栏的边界之外可以点击?

【问题讨论】:

标签: react-native react-navigation react-navigation-bottom-tab


【解决方案1】:

在 imageContainer 样式上使用 zIndex

【讨论】:

【解决方案2】:

在图标上使用 TouchableOpacity 使其可从 react-native-gesture-handler 中点击

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多