Overview of react-native-curved-bottom-bar
masterreact-native-svg and @react-navigation/bottom-tabs.repository·master·Indexed 20 days ago
https://github.com/hoaphantn7604/react-native-curved-bottom-barA high-performance, customizable curved bottom navigation bar for React Native applications. Built on top of react-native-svg and @react-navigation/bottom-tabs, it features a central action button (circle) with support for both 'UP' and 'DOWN' curve types. The library provides specific implementations for both React Native CLI and Expo environments, allowing developers to control visibility via a ref and customize tab rendering through the tabBar and renderCircle props.
react-native-svg and @react-navigation/bottom-tabs.To use the library in an Expo project, import CurvedBottomBarExpo from react-native-curved-bottom-bar and wrap your application in a NavigationContainer from @react-navigation/native.
import React from 'react';
import { Alert, Animated, StyleSheet, TouchableOpacity, View } from 'react-native';
import { CurvedBottomBarExpo } from 'react-native-curved-bottom-bar';
import Ionicons from '@expo/vector-icons/Ionicons';
import { NavigationContainer } from '@react-navigation/native';
// ... Screen components ...
export default function App() {
const renderTabBar = ({ routeName, selectedTab, navigate }) => {
return (
<TouchableOpacity onPress={() => navigate(routeName)} style={styles.tabbarItem}>
{/* Icon logic here */}
</TouchableOpacity>
);
};
return (
<NavigationContainer>
<CurvedBottomBarExpo.Navigator
type="DOWN"
initialRouteName="title1"
renderCircle={({ selectedTab, navigate }) => (
<Animated.View style={styles.btnCircleUp}>
<TouchableOpacity onPress={() => Alert.alert('Click Action')}>
<Ionicons name={'apps-sharp'} color="gray" size={25} />
</TouchableOpacity>
</Animated.View>
)}
tabBar={renderTabBar}
>
<CurvedBottomBarExpo.Screen
name="title1"
position="LEFT"
component={() => <Screen1 />}
/>
<CurvedBottomBarExpo.Screen
name="title2"
position="RIGHT"
component={() => <Screen2 />}
/>
</CurvedBottomBarExpo.Navigator
</NavigationContainer>
);
}For React Native CLI projects, import CurvedBottomBar from react-native-curved-bottom-bar. Ensure you have installed vector icons (e.g., react-native-vector-icons) as required by your implementation.
import React from 'react';
import { Alert, Animated, StyleSheet, TouchableOpacity, View } from 'react-native';
import { CurvedBottomBar } from 'react-native-curved-bottom-bar';
import Ionicons from 'react-native-vector-icons/Ionicons';
import { NavigationContainer } from '@react-navigation/native';
// ... Screen components ...
export default function App() {
const renderTabBar = ({ routeName, selectedTab, navigate }) => {
return (
<TouchableOpacity onPress={() => navigate(routeName)} style={styles.tabbarItem}>
{/* Icon logic here */}
</TouchableOpacity>
);
};
return (
<NavigationContainer>
<CurvedBottomBar.Navigator
type="UP"
initialRouteName="title1"
renderCircle={({ selectedTab, navigate }) => (
<Animated.View style={styles.btnCircleUp}>
<TouchableOpacity onPress={() => Alert.alert('Click Action')}>
<Ionicons name={'apps-sharp'} color="gray" size={25} />
</TouchableOpacity>
</Animated.View>
)}
tabBar={renderTabBar}
>
<CurvedBottomBar.Screen
name="title1"
position="LEFT"
component={() => <Screen1 />}
/>
<CurvedBottomBar.Screen
name="title2"
position="RIGHT"
component={() => <Screen2 />}
/>
</CurvedBottomBar.Navigator
</NavigationContainer>
);
}To use this library, install the package via npm or yarn. Note that this library depends on react-native-svg and @react-navigation/bottom-tabs, which must also be installed in your project.
npm install react-native-curved-bottom-bar --save
# or
yarn add react-native-curved-bottom-barThe CurvedBottomBar.Navigator is the main component used to manage the curved bottom navigation. It accepts several props to control the visual style and behavior of the bar.
type: 'DOWN' or 'UP'. Determines if the center tab item has a downward or upward curve.initialRouteName: String. The name of the route to render on first load.tabBar: ({ routeName, selectedTab, navigate }) => JSX.Element. A function that returns the React element to display as the tab bar.renderCircle: ({ routeName, selectedTab, navigate }) => JSX.Element. A function that returns the React element for the center tab item.circlePosition: 'CENTER', 'LEFT', or 'RIGHT'. Position of the circle button.circleWidth: Number. Width of the center tab item (Min: 50px, Max: 60px).height: Number. Height of the container (Min: 50px, Max: 90px).width: Number. Width of the container.bgColor: String. Background color of the container.style: ViewStyle. Styling for the container view.shadowStyle: ViewStyle. Styling for the shadow view.borderTopLeftRight: Boolean. Applies border radius to the top left and top right of the container.borderColor: String. Border color.borderWidth: Number. Border width.You can control the visibility of the tab bar using the setVisible method via a component reference.
Method:
setVisible(visible: Boolean): Hides or shows the tab bar.Example:
// Assuming 'ref' is a ref to the Navigator
ref.current.setVisible(false);Use CurvedBottomBar.Screen to define the individual routes within the navigator.
name: String. The unique name of the route.position: 'LEFT', 'RIGHT', or 'CIRCLE'. Sets the position of the tab bar icon relative to the circle button. Use 'CIRCLE' only if you want the circle button to act as a tab view.component: (props) => JSX.Element. The component to render for this screen. Screen params are merged into the destination route.When using react-native-curved-bottom-bar in a local development environment or a monorepo where the package is not installed via a standard registry, you may need to configure react-native.config.js to point to the correct source directory. This ensures that the React Native CLI can correctly locate the native code for autolinking.
In the example provided, the dependencies object maps the package name to its root directory using path.join(__dirname, '..').
const path = require('path');
const pak = require('../package.json');
module.exports = {
dependencies: {
[pak.name]: {
root: path.join(__dirname, '..'),
},
},
};By default, the component renders simple text labels for tabs. You can override this behavior by providing a tabBar function prop. This function is called for every tab item (excluding the central circle).
The tabBar function receives:
routeName: The name of the route.selectedTab: The name of the currently focused route.navigate: A function to trigger navigation: (selectTab: string) => void.<BottomBarComponent
renderCircle={({ routeName, selectedTab, navigate }) => (
<MyCircleButton />
)}
tabBar={({ routeName, selectedTab, navigate }) => (
<TouchableOpacity onPress={() => navigate(routeName)}>
<Icon name={routeName === selectedTab ? 'home-active' : 'home-inactive'} />
</TouchableOpacity>
)}
>
{/* Screens */}
</BottomBarComponent>The BottomBarComponent (exported as default) is a custom navigator built on top of @react-navigation/bottom-tabs. It allows you to create a navigation bar with a curved shape and a central action button (circle).
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'DOWN' | 'UP' | 'DOWN' | Determines if the curve goes down or up. |
circlePosition | 'LEFT' | 'CENTER' | 'RIGHT' | 'CENTER' | The position of the central action button. |
bgColor | string | 'gray' | Background color of the bar. |
height | number | 65 | Height of the tab bar. |
circleWidth | number | 50 | Width of the central circle button. |
renderCircle | function | Required | A function to render the central button. Receives { routeName, selectedTab, navigate }. |
tabBar | function | Optional | A function to render individual tab items. Receives { routeName, selectedTab, navigate }. |
renderLeft / renderRight | function | N/A | (Implicitly handled via children position) |
borderTopLeftRight | boolean | false | Whether to apply borders to the top left/right edges. |
borderColor | string | 'gray' | Color of the border. |
borderWidth | number | 0 | Width of the border. |
shadowStyle | ViewStyle | undefined | Style applied to the CurvedViewComponent for shadows. |
style | ViewStyle | undefined | Style applied to the main container. |
initialRouteName | string | undefined | The name of the initial route. |
Children are passed as Tab.Screen equivalents. To control the layout, use the position prop on the children:
position='LEFT': Renders to the left of the circle.position='RIGHT': Renders to the right of the circle.position='CIRCLE' or 'CENTER': Defines the route used for the central action button.<BottomBarComponent
type="DOWN"
circlePosition="CENTER"
bgColor="white"
renderCircle={({ routeName, selectedTab, navigate }) => (
<TouchableOpacity onPress={() => navigate('SpecialRoute')}>
<View style={{ width: 50, height: 50, borderRadius: 25, backgroundColor: 'blue' }} />
</TouchableOpacity>
)}
>
<Tab.Screen name="Home" component={HomeScreen} position="LEFT" />
<Tab.Screen name="Settings" component={SettingsScreen} position="RIGHT" />
<Tab.Screen name="SpecialRoute" component={SpecialScreen} position="CIRCLE" />
</BottomBarComponent>If you want full control over how individual tab buttons are rendered, use the tabBar prop. This function is called for every tab item (excluding the center circle button).
It receives an object with:
routeName: The name of the route.selectedTab: The name of the currently focused route.navigate: A function to trigger navigation to that route.If tabBar is not provided, the component defaults to a simple TouchableOpacity containing the route name text.
<BottomBarComponent
tabBar={({ routeName, selectedTab, navigate }) => (
<TouchableOpacity onPress={() => navigate(routeName)}>
<MyCustomIcon
name={routeName}
active={selectedTab === routeName}
/>
</TouchableOpacity>
)}
>
{/* ... screens ... */}
</BottomBarComponent>When defining a screen within the CurvedBottomBar.Navigator, you can specify the position property to control where the menu item appears relative to the curved bar.
Available position values are:
'LEFT': Positioned on the left side.'RIGHT': Positioned on the right side.'CIRCLE': Positioned in the center, typically used for the prominent floating action button that interacts with the curve.'CENTER': Positioned in the center of the bar.// Example usage of the position prop in a screen configuration
<CurvedBottomBar.Screen
position="CIRCLE"
component={MyComponent}
options={{...}}
/>