import type { Route } from '@react-navigation/native'; import React from 'react'; import { StyleProp, StyleSheet, TextStyle, View, ViewStyle, } from 'react-native'; import Badge from './Badge'; type Props = { route: Route; horizontal: boolean; badge?: string | number; badgeStyle?: StyleProp; activeOpacity: number; inactiveOpacity: number; activeTintColor: string; inactiveTintColor: string; renderIcon: (props: { focused: boolean; color: string; size: number; }) => React.ReactNode; style: StyleProp; }; export default function TabBarIcon({ route: _, horizontal, badge, badgeStyle, activeOpacity, inactiveOpacity, activeTintColor, inactiveTintColor, renderIcon, style, }: Props) { const size = 25; // We render the icon twice at the same position on top of each other: // active and inactive one, so we can fade between them. return ( {renderIcon({ focused: true, size, color: activeTintColor, })} {renderIcon({ focused: false, size, color: inactiveTintColor, })} {badge} ); } const styles = StyleSheet.create({ icon: { // We render the icon twice at the same position on top of each other: // active and inactive one, so we can fade between them: // Cover the whole iconContainer: position: 'absolute', alignSelf: 'center', alignItems: 'center', justifyContent: 'center', height: '100%', width: '100%', // Workaround for react-native >= 0.54 layout bug minWidth: 25, }, iconVertical: { flex: 1, }, iconHorizontal: { height: '100%', marginTop: 3, }, badge: { position: 'absolute', left: 3, }, badgeVertical: { top: 3, }, badgeHorizontal: { top: 7, }, });