fix: show a missing icon symbol instead of empty area in bottom tab bar

This commit is contained in:
Satyajit Sahoo
2021-03-06 19:00:38 +01:00
parent 36a9b4f866
commit 2bc4882692
5 changed files with 33 additions and 2 deletions

6
example/tsconfig.json Normal file
View File

@@ -0,0 +1,6 @@
{
"extends": "../tsconfig",
"compilerOptions": {
// Avoid expo-cli auto-generating a tsconfig
}
}

View File

@@ -17,6 +17,7 @@ import {
useTheme,
useLinkBuilder,
} from '@react-navigation/native';
import { MissingIcon } from '@react-navigation/elements';
import { EdgeInsets, useSafeAreaFrame } from 'react-native-safe-area-context';
import BottomTabItem from './BottomTabItem';
@@ -348,7 +349,12 @@ export default function BottomTabBar({
options.tabBarInactiveBackgroundColor
}
button={options.tabBarButton}
icon={options.tabBarIcon}
icon={
options.tabBarIcon ??
(({ color, size }) => (
<MissingIcon color={color} size={size} />
))
}
badge={options.tabBarBadge}
badgeStyle={options.tabBarBadgeStyle}
label={label}

View File

@@ -37,7 +37,7 @@ type Props = {
/**
* Icon to display for the tab.
*/
icon?: (props: {
icon: (props: {
focused: boolean;
size: number;
color: string;

View File

@@ -0,0 +1,18 @@
import * as React from 'react';
import { Text, TextStyle, StyleProp, StyleSheet } from 'react-native';
type Props = {
color?: string;
size?: number;
style?: StyleProp<TextStyle>;
};
export default function MissingIcon({ color, size, style }: Props) {
return <Text style={[styles.icon, { color, fontSize: size }, style]}></Text>;
}
const styles = StyleSheet.create({
icon: {
backgroundColor: 'transparent',
},
});

View File

@@ -9,6 +9,7 @@ export { default as useHeaderHeight } from './Header/useHeaderHeight';
export { default as getDefaultHeaderHeight } from './Header/getDefaultHeaderHeight';
export { default as getHeaderTitle } from './Header/getHeaderTitle';
export { default as MissingIcon } from './MissingIcon';
export { default as PlatformPressable } from './PlatformPressable';
export { default as ResourceSavingScene } from './ResourceSavingScene';
export { default as SafeAreaProviderCompat } from './SafeAreaProviderCompat';