Registry / web-framework / react-native-tab-view

react-native-tab-view

JSON →
library4.3.0jsnpmunverified

The `react-native-tab-view` package provides a highly customizable and performant tab view component for React Native applications. It allows developers to create intuitive interfaces where users can swipe horizontally between different content sections, similar to native tab patterns on iOS and Android. Currently at stable version 4.3.0, this library is actively maintained as part of the broader React Navigation ecosystem. Its release cadence aligns with the development cycle of its underlying dependencies and the React Navigation project, ensuring ongoing support and feature enhancements. Key differentiators include its reliance on `react-native-pager-view` for smooth, native-like gesture handling, support for lazy rendering of tab scenes to optimize performance, and a flexible API that allows for extensive customization of both the tab bar and individual tab content. This enables developers to build complex tab-based navigation patterns with rich user experience.

npm install react-native-tab-view
INSTALL
IMPORT
SIG · REACT-NATIVE-TAB-V
R
react-native-tab-view
web-frameworkjavascriptv4.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TabView
import { TabView } from 'react-native-tab-view';
const TabView = require('react-native-tab-view');
The primary TabView component. Ensure you use named import. CommonJS `require` is generally discouraged in modern React Native projects, especially for libraries designed with ESM in mind, and can lead to issues with tree-shaking and TypeScript inference.
SceneMap
import { SceneMap } from 'react-native-tab-view';
import SceneMap from 'react-native-tab-view/lib/SceneMap';
A utility function to efficiently map routes to scene components. Always import directly from the main package. Importing from internal `lib` or `src` subpaths is an anti-pattern and not guaranteed to be stable across versions.
TabBar
import { TabBar } from 'react-native-tab-view';
import { TabBar } from 'react-native-tab-view/src/TabBar';
The default TabBar component, which can be customized or replaced. Similar to SceneMap, avoid direct imports from internal directories.
NavigationState
import type { NavigationState, Route } from 'react-native-tab-view';
TypeScript types for defining the tab view's navigation state and individual route objects. Use `import type` for clarity and to ensure type-only imports are correctly handled by bundlers.

This quickstart demonstrates a basic TabView with three tabs, using `SceneMap` for efficient scene rendering and `useWindowDimensions` for responsive layout. It also includes an example of a customized `TabBar`.

import * as React from 'react'; import { View, StyleSheet, useWindowDimensions, Text } from 'react-native'; import { TabView, SceneMap, TabBar, NavigationState, Route } from 'react-native-tab-view'; // Define your scene components const FirstRoute = () => ( <View style={[styles.scene, { backgroundColor: '#ff4081' }]}> <Text>First Tab Content</Text> </View> ); const SecondRoute = () => ( <View style={[styles.scene, { backgroundColor: '#673ab7' }]}> <Text>Second Tab Content</Text> </View> ); const ThirdRoute = () => ( <View style={[styles.scene, { backgroundColor: '#00bcd4' }]}> <Text>Third Tab Content</Text> </View> ); // Map routes to scenes using SceneMap for performance optimization const renderScene = SceneMap({ first: FirstRoute, second: SecondRoute, third: ThirdRoute, }); export default function MyTabView() { const layout = useWindowDimensions(); const [index, setIndex] = React.useState(0); const [routes] = React.useState<Route[]>([ { key: 'first', title: 'First' }, { key: 'second', title: 'Second' }, { key: 'third', title: 'Third' }, ]); // Custom tab bar styling example const renderTabBar = (props: any) => ( <TabBar {...props} indicatorStyle={{ backgroundColor: 'white' }} style={{ backgroundColor: '#2196f3' }} renderLabel={({ route, focused, color }) => ( <Text style={{ color, margin: 8, fontWeight: focused ? 'bold' : 'normal' }}> {route.title} </Text> )} /> ); return ( <TabView navigationState={{ index, routes }} renderScene={renderScene} onIndexChange={setIndex} initialLayout={{ width: layout.width }} renderTabBar={renderTabBar} // Pass the custom TabBar style={styles.container} /> ); } const styles = StyleSheet.create({ container: { flex: 1, }, scene: { flex: 1, justifyContent: 'center', alignItems: 'center', }, });
Debug
Known issues
breaking`react-native-tab-view` version 4.x and above (including 4.3.0) requires `react-native-pager-view` version 6.0.0 or newer. Older versions of `react-native-tab-view` might have relied on `react-native-reanimated` or other internal pagers. Failure to install or properly link `react-native-pager-view` will lead to runtime errors.
fix
Ensure `react-native-pager-view` is installed via `yarn add react-native-pager-view` or `npm install react-native-pager-view`. For iOS, run `npx pod-install` in your `ios/` directory after installation.
affects: >=4.0.0
gotchaRendering many complex components in tabs can significantly impact performance. `SceneMap` optimizes rendering by memoizing scene components, but inline functions passed to `SceneMap` negate this optimization and can cause scenes to remount on every render.
fix
Define scene components as separate, top-level functional or class components. For passing props to scenes, use the `renderScene` prop directly instead of `SceneMap` and memoize your scene components manually using `React.memo` or `PureComponent`.
affects: >=1.0.0
gotchaWhen `TabView` is nested within another navigator (e.g., a Stack Navigator), swipe gestures for navigating back in the parent navigator might be blocked by the `TabView`'s horizontal swipe. This can lead to a poor user experience, particularly on iOS.
fix
This often requires careful configuration of `react-native-gesture-handler`. Solutions can involve adjusting `activeOffsetX` on parent gesture handlers or using libraries like `@react-navigation/native-stack` which provide better interop.
affects: >=1.0.0
gotchaNesting `TabView` inside another `TabView` or a horizontal `ScrollView` on Android is generally not supported due to underlying platform limitations. This can result in unpredictable behavior, including non-functional gestures or rendering glitches.
fix
Avoid nesting `TabView` within other horizontal scrolling components on Android. Re-architect your UI to use a different layout strategy if such nesting is attempted.
affects: >=1.0.0
gotchaRelying on fixed screen dimensions (e.g., `Dimensions.get('window').width`) for `initialLayout` can lead to layout issues on device rotation or when the app is used on devices with varying screen sizes or notches. This might cause tabs to appear misaligned or have incorrect widths.
fix
Always use the `useWindowDimensions` hook from `react-native` to dynamically get the screen width for `initialLayout`. This ensures the tab view adapts correctly to layout changes.
affects: >=1.0.0
Errors
Common errors & fixes
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. Check the render method of SceneView .
A scene component passed to `SceneMap` or `renderScene` is not correctly imported, exported, or is an inline function.
fix
Ensure all scene components are properly defined, exported, and imported as named or default exports. If using `SceneMap`, pass direct references to component functions, not inline arrow functions.
Invariant Violation: requireNativeComponent: "RNCViewPager" was not found in the UIManager. This error usually happens when there are issues with the native setup. Make sure you're running on a physical device or a properly configured emulator and that all native dependencies are linked correctly.
The native module for `react-native-pager-view` (or `ViewPagerAndroid` in older versions) is not correctly linked or installed, which is a required peer dependency for `react-native-tab-view` v4+.
fix
Install `react-native-pager-view` (`yarn add react-native-pager-view` or `npm install react-native-pager-view`). For iOS, navigate to your `ios/` directory and run `npx pod-install`. Rebuild your native app.
Type '{ layout: Layout; position: AnimatedInterpolation; jumpTo: (key: string) => void; navigationState: NavigationState<Route>; }' is missing the following properties from type '{ navigationState: NavigationState<Route>; scrollEnabled?: boolean | undefined; bounces?: boolean | undefined; activeColor?: string | undefined; inactiveColor?: string | undefined; ... }'
You are creating a custom `TabBar` component in TypeScript and its props do not match the expected `TabBarProps` interface, often missing optional properties or having incorrect types for required ones.
fix
When defining props for a custom `TabBar`, it's often safest to infer the full set of props using `React.ComponentProps<typeof TabBar>` or ensure your custom interface strictly extends `TabBarProps<Route>`. Explicitly define all required properties or mark them as optional if they have defaults.
Upgrade
Version history
4.3.0latest on npm
Audit
Dependencies
reactrequiredReact runtime for component lifecycle and rendering.
react-nativerequiredReact Native core components and APIs.
react-native-pager-viewrequiredProvides the underlying pager functionality for swipe gestures and scene management. Required since v4.
Agent activity
4 hits · last 30 days
node
4
Resources
react-native-tab-view — npm install react-native-tab-view · libregistry