use*_*752 5 react-native react-navigation react-navigation-bottom-tab react-navigation-v5
有没有办法实现这一目标?我正在使用 react-navigation 5 并根据Bottom-tab-navigator创建了一个自定义底部标签栏
我用于底部栏的代码如下
import React from 'react';
import { View, StyleSheet } from 'react-native';
import colors from 'styles/colors';
import TabBarItem from './TabBarItem/TabBarItem';
const homeIcon = require('assets/maps.png');
export enum Item {
  Home,
  ProfileView,
}
const DashboardTabBar: React.FC<{}> = ({ state, descriptors, navigation }) => {
  return (
    <View style={styles.container}>
      <View style={styles.innerContainer}>
        {state.routes.map((route, index) => {
          const { options } = descriptors[route.key];
          const isFocused = state.index === index;
          const onPress = () => {
            const event = navigation.emit({
              type: 'tabPress',
              target: route.key,
            });
            if (!isFocused && !event.defaultPrevented) {
              navigation.navigate(route.name);
            }
          };
          const onLongPress = () => {
            navigation.emit({
              type: 'tabLongPress',
              target: route.key,
            });
          };
          return (
            <TabBarItem
              icon={homeIcon}
              isFocused={isFocused}
              onPress={onPress}
              onLongPress={onLongPress}
              options={options}
              key={route.key}
            />
          );
        })}
      </View>
    </View>
  );
};
const styles = StyleSheet.create({
  container: {
    padding: 10,
    paddingBottom: 18,
    backgroundColor: 'red', // I tried with 'transparent' here, but i see a white background instead of transparent
  },
  innerContainer: {
    height: 60,
    backgroundColor: colors.GREY_L_10,
    flexDirection: 'row',
    justifyContent: 'space-evenly',
    alignItems: 'center',
    borderRadius: 50,
    borderWidth: 1,
    borderColor: colors.GREY,
  },
});
export default DashboardTabBar;
就我查看的代码而言,我找不到任何使其透明的方法。
在您的代码中的其他地方,您有一个使用 DashboardTabBar 组件的组件。您应该将带有样式对象的tabBarOptions道具添加到Tab.Navigator组件,如下所示:
    <Tab.Navigator
      tabBar={...}
      tabBarOptions={{
        style: {
          backgroundColor: 'transparent',
          position: 'absolute',
          left: 0,
          right: 0,
          bottom: 0,
          elevation: 0, <----to get rid of a shadow problem on Android
        },
      }}>
    { /* ...your screens go here */ }
</Tab.Navigator>
我在 iOS 和 Android 上都成功地做到了这一点。就个人而言,它对我的应用程序来说并不好看。
 

| 归档时间: | 
 | 
| 查看次数: | 2123 次 | 
| 最近记录: |