How to add a line at top of the bottom tab when the current tab is active in react navigation 5

≡放荡痞女 提交于 2021-01-29 10:02:30

问题


I want to add the line at the top of the bottom tabs, how to add this? like this issue https://github.com/react-navigation/react-navigation/issues/8957

React navigation versions:

"@react-navigation/bottom-tabs": "^5.9.2",
"@react-navigation/native": "^5.7.6",
"@react-navigation/stack": "^5.9.3",
"react": "16.13.1",
"react-native": "0.63.3",

回答1:


You can use a custom button like below

const CustomTabButton = (props) => (
  <TouchableOpacity
    {...props}
    style={
      props.accessibilityState.selected
        ? [props.style, { borderTopColor: 'red', borderTopWidth: 2 }]
        : props.style
    }
  />
);

And provide it as the tabBarButton when initializing the navigation.

<Tab.Navigator>
  <Tab.Screen
    name="Home"
    component={HomeScreen}
    options={{
      tabBarButton: CustomTabButton,
    }}
  />
  <Tab.Screen
    name="Settings"
    component={SettingsScreen}
    options={{
      tabBarButton: CustomTabButton,
    }}
  />
</Tab.Navigator>

You can try the below snack https://snack.expo.io/6lMAe57lM



来源:https://stackoverflow.com/questions/64384419/how-to-add-a-line-at-top-of-the-bottom-tab-when-the-current-tab-is-active-in-rea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!