
Security News
TypeScript Native Previews: 10x Faster Compiler Now on npm for Public Testing
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.
@react-navigation/material-top-tabs
Advanced tools
Integration for the animated tab view component from react-native-tab-view
@react-navigation/material-top-tabs is a library for React Native that provides a material-design styled top tab navigator. It allows you to create a tab-based navigation structure where the tabs are displayed at the top of the screen, similar to the tab layout in many popular mobile applications.
Basic Top Tab Navigator
This code demonstrates how to set up a basic top tab navigator with two tabs: Home and Settings. Each tab is associated with a screen component.
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import HomeScreen from './HomeScreen';
import SettingsScreen from './SettingsScreen';
const Tab = createMaterialTopTabNavigator();
function MyTabs() {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyTabs />
</NavigationContainer>
);
}
Customizing Tab Bar Options
This code shows how to customize the tab bar options, such as changing the active tint color, label style, and background color of the tab bar.
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import HomeScreen from './HomeScreen';
import SettingsScreen from './SettingsScreen';
const Tab = createMaterialTopTabNavigator();
function MyTabs() {
return (
<Tab.Navigator
tabBarOptions={{
activeTintColor: 'white',
labelStyle: { fontSize: 12 },
style: { backgroundColor: 'blue' },
}}
>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyTabs />
</NavigationContainer>
);
}
Lazy Loading Tabs
This code demonstrates how to enable lazy loading for the tabs. With lazy loading, the tab screens are not mounted until they are first focused.
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import HomeScreen from './HomeScreen';
import SettingsScreen from './SettingsScreen';
const Tab = createMaterialTopTabNavigator();
function MyTabs() {
return (
<Tab.Navigator lazy={true}>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyTabs />
</NavigationContainer>
);
}
@react-navigation/bottom-tabs provides a bottom tab navigator, which is similar to the top tab navigator but places the tabs at the bottom of the screen. It is useful for applications that prefer bottom navigation, which is common in many mobile apps.
react-native-tab-view is another library for creating tab-based navigation in React Native. It provides a customizable tab view component that can be used to create both top and bottom tab navigators. It offers more flexibility in terms of customization compared to @react-navigation/material-top-tabs.
react-navigation-tabs is a part of the React Navigation library that provides both top and bottom tab navigators. It is a more general-purpose tab navigation solution compared to @react-navigation/material-top-tabs, which is specifically focused on material design top tabs.
@react-navigation/material-top-tabs
React Navigation integration for animated tab view component from react-native-tab-view
.
Installation instructions and documentation can be found on the React Navigation website.
FAQs
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.
Research
Security News
Malicious npm packages targeting React, Vue, Vite, Node.js, and Quill remained undetected for two years while deploying destructive payloads.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.