简体   繁体   English

如何在 React Navigation (4.x) 的特定屏幕中隐藏 BottomTabNavigator

[英]How to hide BottomTabNavigator in certain screen in React Navigation (4.x)

I need to hide the bottom tab navigator in my 'Chat' screen in my app built with React Native and React Navigation.我需要在使用 React Native 和 React Navigation 构建的应用程序的“聊天”屏幕中隐藏底部选项卡导航器。 I have the following code:我有以下代码:

 const UserNavigation= createStackNavigator({ Profile:{screen:Profile}, Search:{screen:Search}, Feedback:{screen:Feedback}, Chat: {screen:Chat}, //I need to hide the bottom tab navigation bar in this screen }, const TabNavigator = createBottomTabNavigator({ User: UserNavigation, Settings: SettingsNavigation, // etc... });

How can I achieve this?我怎样才能做到这一点?

You no need to hide the BottomNavBar, instead you can make the Chat Fragment into DialogFragment.您无需隐藏BottomNavBar,而是可以将聊天片段制作成DialogFragment。 So it covers the Full Screen所以它覆盖了全屏

in Style.xml copy the following code在 Style.xml 中复制以下代码

<style name="MY.DIALOG" parent="AppTheme">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>

extend your ChatFragment from Fragment to DialogFragment, then copy the following将您的 ChatFragment 从 Fragment 扩展到 DialogFragment,然后复制以下内容

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.MY_DIALOG);
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            int width = ViewGroup.LayoutParams.MATCH_PARENT;
            int height = ViewGroup.LayoutParams.MATCH_PARENT;
            dialog.getWindow().setLayout(width, height);
        }
    }

pass the instance of DialogFrament传递 DialogFrament 的实例

loadDiaogFragment(new ChatFragment);

create the following function创建以下 function

private void loadDialogFragment(DialogFragment fragment) {
    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    fragment.show(transaction, "Load Fragment");
}

to close the DialogFragment use following inside onClickLister关闭 DialogFragment 使用以下 onClickLister

dismiss();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Navigation 将 4.x 升级到 5.x - React Navigation upgrading 4.x to 5.x 在react-navigation中从StackNavigator隐藏BottomTabNavigator的标题 - Hide a header of a BottomTabNavigator from a StackNavigator in react-navigation 如何在一个屏幕上隐藏反应导航标题 - How to hide react navigation header on one screen React Navigation bottomTabNavigator“createRouter 不是函数” - React Navigation bottomTabNavigator "createRouter is not a function" 如何隐藏特定屏幕上的底部标签栏(react-navigation 3.x) - How can I hide the bottom tab bar on a specific screen (react-navigation 3.x) 如何在 bottomTabNavigator 上添加一个按钮,而不是在 react native 中导航到屏幕? - How to add a button on the bottomTabNavigator rather than navigating to a screen in react native? React Native 嵌套导航以在登录/注册(StackNavigator)后实现带有选项卡(bottomTabNavigator)的登陆屏幕 - React Native nested navigation to achieve a landing screen with tabs (bottomTabNavigator) after Sign-In/Sign-Up(StackNavigator) 添加自定义按钮以响应导航底部TabNavigator? - Add custom button to react navigation bottomTabNavigator? 如何在本机反应中隐藏特定屏幕上的底部导航栏? - How to hide bottom navigation bar on a specific screen in react native? React Navigation如何在单个屏幕上隐藏标签栏顶部边框 - React Navigation how to hide tabbar top-border on a individual screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM