Introduction
As the name suggests, a material top tab navigator is what we shall find on the top of the screen that lets us switch among various sections simply by tapping on the tabs provided. We can do this task by swiping the pages horizontally in many cases. While moving from one section to the other, we see animated transitions that are by default a part of the navigator.
To create a top tab navigator, we must use the createMaterialTopTabNavigator function available in the React navigation library. We design it using the Material Theme tab bar at the top of the screen.
This discussion would have given you a brief idea about the top tab navigator. Let us now learn more about this topic and understand how we make it.
The React Navigation library's createMaterialTopTabNavigator function makes it easy to implement a top tab navigator. It provides the ability to build and display multi-screen routers. The tab screen component expands when it is focused. As discussed earlier, we can switch between different tabs by tapping or swiping horizontally on the top tab navigator. Standard transition animations are available.
We can write the code as follows:
createMaterialTopTabNavigator(RouteConfigs, TabNavigatorConfig);
Props in Top Tab Navigator
When we create a component in React Native, we need to adjust its properties according to us. The set of these properties is called props. Let us have a look at all such properties one by one.
- initialRouteName: The initialRouteName is a prop used to pass the name rendered when the navigator is first loaded.
- screenOptions: screenOptions are React Native props that we use as the default options for navigator screens. We use the default options to implement all screen navigators.
- tabBarPosition: This type of prop is used to set the position of the tab bar in the tab view. The default is "top."
- Lazy: We use Lazy props to see if a Boolean value indicates if the screen is lazy. By default, we display the screen in the viewport experience.
- lazyPlaceholder: lazyPlaceholder supports React Native functions that return React elements that we provide for routes that haven't been used yet. By default, the render value is zero.
- removeClippedSubviews: We use removeClippedSubviewsa to improve the Memory Hierarchy. It takes a Boolean value that indicates whether We need to hide views from the view hierarchy.
- KeyboardDismissMode: We use this property to get a string value that indicates whether to close the keyboard in response to a drag gesture. Other values for keyboard release mode are automatic, on-drag, and none.
- timingConfig: timingConfig sets the timing of the configuration object used for the timing animation that occurs when we press the tab. The other properties of TimingConfig are duration and count.
- Position: We use the animation value to listen for position updates. It changes from time to time when the user presses a tab.