Итак, у меня есть это требование.Чтобы сделать навигацию по вкладкам с таким точным внешним видом:
У меня не было проблем с оформлением панели вкладок с помощью градиента и кнопок.Я создал свой собственный с этим кодом:
export default createBottomTabNavigator({
(... routes here)
}, {
initialRouteName: "Inspiration",
tabBarComponent: props => <BottomTabBar {...props} />
})
Но теперь у меня проблемы с средней кнопкой.Моя панель выглядит следующим образом:
![This is how it looks now](https://i.stack.imgur.com/IMVAD.png)
Если я удаляю пользовательскую панель вкладок, удаляя эту строку:
tabBarComponent: props => <BottomTabBar {...props} />
Тогда теперь мойсредняя кнопка выглядит так, как должна, но, конечно, все остальные стили отсутствуют:
![Not close enough](https://i.stack.imgur.com/9SEww.png)
Вот так выглядит мой компонент BottomTabBar прямо сейчас:
import React from "react";
import { Image, StyleSheet, Text, TouchableOpacity } from "react-native";
import { TabBarBottomProps, NavigationRoute } from "react-navigation";
import LinearGradient from "react-native-linear-gradient";
const iconBag = require("./images/bag.png");
export default function BottomTabBar(props: TabBarBottomProps) {
const {
renderIcon,
getLabelText,
activeTintColor,
inactiveTintColor,
onTabPress,
onTabLongPress,
getAccessibilityLabel,
navigation
} = props;
const { routes, index: activeRouteIndex } = navigation.state;
function renderTabBarButton(routeIndex, route) {
const isRouteActive = routeIndex === activeRouteIndex;
const tintColor = isRouteActive ? activeTintColor : inactiveTintColor;
if (route.key == "Bag")
return <Image style={{ width: 100, height: 100 }} source={iconBag} />;
return (
<TouchableOpacity
key={routeIndex}
style={styles.tabButton}
onPress={() => onTabPress({ route })}
onLongPress={() => onTabLongPress({ route })}
accessibilityLabel={getAccessibilityLabel({ route })}
>
{renderIcon({ route, focused: isRouteActive, tintColor })}
<Text style={styles.tabText}>{getLabelText({ route })}</Text>
</TouchableOpacity>
);
}
return (
<LinearGradient colors={["#FFFFFF", "#DEDEDE"]} style={styles.container}>
{routes.map((route, routeIndex) => renderTabBarButton(routeIndex, route))}
</LinearGradient>
);
}
const styles = StyleSheet.create({
container: {
height: 60,
flexDirection: "row",
alignItems: "center",
borderWidth: 1,
borderColor: "#C4C4C4"
},
tabButton: {
flex: 1,
justifyContent: "center",
alignItems: "center"
},
tabText: {
fontFamily: "Source Sans Pro",
fontSize: 11,
color: "#454545",
marginTop: 1
}
});
Что я могу сделать?Любая помощь будет очень ценится!