Footer Navbar

The FooterNavbar component provides a responsive and customizable bottom navigation bar for applications, commonly used for primary navigation paths.

Installation

$ cbui-cli install @crossbuildui/footernavbar

Import

MyComponent.tsx
1import { FooterNavbar } from '@/crossbuildui/footernavbar'; 2import type { FooterNavbarItemConfig, FooterNavbarVariant, FooterNavbarColor, FooterNavbarSize, FooterNavbarRadius } from '@/crossbuildui/footernavbar'; 3// import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; // Or your preferred icon library 4// import { View, Text } from 'react-native'; 5// import { useSafeAreaInsets } from 'react-native-safe-area-context'; // If using safeAreaBottom

FooterNavbar Component

Basic Usage

Provide an array of items to define the navigation links. Each item requires an id, label, and an icon render function.

MyComponent.tsx
1<FooterNavbar items={[ 2 { id: 'feed', label: 'Feed', icon: ({ color, size }) => <Icon name="rss" size={size} color={color} /> }, 3 { id: 'chat', label: 'Chat', icon: ({ color, size }) => <Icon name="chat" size={size} color={color} /> }, 4 { id: 'notifications', label: 'Alerts', icon: ({ color, size }) => <Icon name="bell" size={size} color={color} /> }, 5]} />

Variants

The navbar supports several visual styles through the variant prop: solid (default), bordered, flat, faded, and glass. The color prop sets the base color for these variants.

MyComponent.tsx
1<View style={{gap: 16}}> 2 <FooterNavbar items={itemsExample.slice(0,3)} variant="solid" color="primary" activeItemColor="white" inactiveItemColor="rgba(255,255,255,0.7)" /> 3 <FooterNavbar items={itemsExample.slice(0,3)} variant="bordered" color="secondary" activeItemColor="secondary" /> 4 <FooterNavbar items={itemsExample.slice(0,3)} variant="flat" color="success" activeItemColor="success" /> 5 <FooterNavbar items={itemsExample.slice(0,3)} variant="faded" color="warning" activeItemColor="warning" /> 6 <FooterNavbar items={itemsExample.slice(0,3)} variant="glass" glassIntensity={70} glassTint="light" activeItemColor="black" inactiveItemColor="gray" /> 7</View>

Sizes & Radius

Adjust the navbar's height and internal spacing with the size prop (sm, md, lg). Control the top border radius using the radius prop (none, sm, md, lg, full).

MyComponent.tsx
1<View style={{gap: 16}}> 2 <FooterNavbar items={itemsExample.slice(0,2)} size="sm" radius="sm" color="default" /> 3 <FooterNavbar items={itemsExample.slice(0,3)} size="md" radius="md" color="background" /> 4 <FooterNavbar items={itemsExample.slice(0,4)} size="lg" radius="lg" variant="flat" color="primary" /> 5</View>

Item Customization

Customize the appearance and behavior of items using props like activeItemColor, inactiveItemColor, hideLabels, iconSize, labelStyle, and itemStyle. Handle item presses with onItemPress. The active item can be uncontrolled (defaultActiveIndex) or controlled (activeIndex).

MyComponent.tsx
1<FooterNavbar 2 items={itemsExample} 3 activeItemColor="orange" 4 inactiveItemColor="grey" 5 hideLabels={false} 6 iconSize={20} // Smaller icons 7 labelStyle={{ fontWeight: 'bold', fontSize: 10 }} 8 itemStyle={{ paddingVertical: 4 }} // Custom padding for each item 9 onItemPress={(item, index) => console.log(`Pressed ${item.label} at index ${index}`)} 10 defaultActiveIndex={1} 11/>

Controlled Active Item

Manage the active item state externally by providing the activeIndex prop and updating it via the onItemPress callback.

MyComponent.tsx
1function ControlledFooterNavbar() { 2 const [activeIndex, setActiveIndex] = React.useState(0); 3 const navItems = [ 4 { id: 'tab1', label: 'Tab 1', icon: ({ color, size }) => <Icon name="numeric-1-box" size={size} color={color} /> }, 5 { id: 'tab2', label: 'Tab 2', icon: ({ color, size }) => <Icon name="numeric-2-box" size={size} color={color} /> }, 6 ]; 7 8 return ( 9 <View> 10 <FooterNavbar 11 items={navItems} 12 activeIndex={activeIndex} 13 onItemPress={(item, index) => setActiveIndex(index)} 14 /> 15 <Text style={{ textAlign: 'center', marginTop: 10 }}> 16 Active Tab: {navItems[activeIndex]?.label} 17 </Text> 18 </View> 19 ); 20}

Safe Area Handling

Set safeAreaBottom= to automatically add padding to the bottom of the navbar, respecting the device's safe area insets. This requires react-native-safe-area-context.

MyComponent.tsx
1// This example assumes you are in a React Native environment 2// with react-native-safe-area-context installed and configured. 3<FooterNavbar 4 items={itemsExample.slice(0,3)} 5 safeAreaBottom={true} 6 // The navbar will have paddingBottom equal to the bottom safe area inset. 7/>

Glass Variant In-Depth

The glass variant applies a frosted glass effect using expo-blur. Customize it with glassIntensity (0-100) and glassTint ('light', 'dark', or 'default' - which adapts to the theme). Item colors may need adjustment for optimal contrast against the blurred background.

MyComponent.tsx
1<View style={{gap: 16, padding: 10, backgroundColor: 'rgba(100,100,150,0.3)' /* Example page background */ }}> 2 <Text style={{color: 'white'}}>Light Tint Glass Navbar:</Text> 3 <FooterNavbar 4 items={itemsExample.slice(0,3)} 5 variant="glass" 6 glassTint="light" 7 glassIntensity={90} 8 activeItemColor="blue" 9 inactiveItemColor="darkgray" 10 radius="md" 11 /> 12 <Text style={{color: 'white', marginTop: 10}}>Dark Tint Glass Navbar:</Text> 13 <FooterNavbar 14 items={itemsExample.slice(0,3)} 15 variant="glass" 16 glassTint="dark" 17 glassIntensity={60} 18 activeItemColor="white" 19 inactiveItemColor="lightgray" 20 radius="lg" 21 style={{ borderTopColor: 'rgba(255,255,255,0.2)' }} // Custom border for dark glass 22 /> 23</View>

Props Overview

PROPTYPEDEFAULTDESCRIPTION
itemsFooterNavbarItemConfig[]-Array of item configurations. Required.
variantFooterNavbarVariant'solid'Visual style of the navbar.
colorFooterNavbarColor'background'Base color for the navbar (background/border).
sizeFooterNavbarSize'md'Size of the navbar and its items.
radiusFooterNavbarRadius'none'Top border radius of the navbar.
hideLabelsbooleanfalseIf true, hides all item labels.
activeItemColorstringTheme's primaryColor for the active item's icon and label.
inactiveItemColorstringTheme's foregroundColor for inactive items' icon and label.
onItemPress(item, index) => void-Callback when an item is pressed.
activeIndexnumber-Controlled active item index.
defaultActiveIndexnumber0Initial active index (uncontrolled).
styleStyleProp<ViewStyle>-Custom styles for the navbar container.
itemStyleStyleProp<ViewStyle>-Custom styles for each item's Pressable container.
iconSizenumber-Overrides default icon size derived from size.
labelStyleStyleProp<TextStyle>-Custom styles for item labels.
safeAreaBottombooleanfalseAdd padding for bottom safe area insets.
glassTint'default' | 'light' | 'dark'Theme-derivedTint for the 'glass' variant.
glassIntensitynumber80Intensity (0-100) for the 'glass' variant.

FooterNavbarItemConfig Props

Each object in the items array should conform to FooterNavbarItemConfig:

PROPTYPEDESCRIPTION
idstringUnique identifier for the item. Required.
icon(props: { color, size, isActive }) => ReactElementFunction returning an icon element. Required.
labelstringOptional label text for the item.
hrefstringOptional href, passed to onItemPress.
accessibilityLabelstringAccessibility label for the item.
pressablePropsPressablePropsCustom props for the item's Pressable component.

Styling

Customize the FooterNavbar's appearance using:

  • style: Applied to the main navbar container (View or BlurView). Use for borders, shadows, custom background colors (for non-glass variants), etc.
  • itemStyle: Applied to each individual item's root Pressable component. Useful for adjusting padding or hit area of items.
  • labelStyle: Applied to the Text component for item labels. Allows customization of font, color (though active/inactive colors are preferred), etc.
  • iconSize: Directly sets the size passed to the icon render function.
  • For the glass variant, the backgroundColor in the main style prop will be overridden by transparency to allow the BlurView to be effective. The blurViewStyle (internal) handles the blur effect itself.
MyComponent.tsx
1<FooterNavbar 2 items={itemsExample.slice(0,2)} 3 variant="solid" 4 color="#333333" // Custom background color 5 activeItemColor="cyan" 6 inactiveItemColor="#888888" 7 style={{ 8 borderTopWidth: 3, 9 borderTopColor: 'cyan', 10 shadowColor: '#00ffff', 11 shadowOffset: { width: 0, height: -3 }, 12 shadowOpacity: 0.5, 13 shadowRadius: 5, 14 elevation: 10, // For Android 15 }} 16 itemStyle={{ 17 // Custom style for each FooterNavbarItem Pressable 18 // e.g., to add more padding or a background on hover (web) 19 }} 20 labelStyle={{ 21 fontFamily: 'Arial, sans-serif', // Custom font for labels 22 textTransform: 'uppercase', 23 }} 24 iconSize={28} // Larger icons 25/>

Accessibility

The FooterNavbar component aims to be accessible:

  • Each FooterNavbarItem is a Pressable with accessibilityRole="button".
  • The accessibilityState of each item includes { selected: isActive }.
  • An accessibilityLabel for each item is derived from its label prop or can be explicitly set via the accessibilityLabel in FooterNavbarItemConfig.
  • Ensure icons are decorative or have appropriate labels if they convey meaning not covered by the text label.