繁体   English   中英

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

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

我需要在使用 React Native 和 React Navigation 构建的应用程序的“聊天”屏幕中隐藏底部选项卡导航器。 我有以下代码:

 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... });

我怎样才能做到这一点?

您无需隐藏BottomNavBar,而是可以将聊天片段制作成DialogFragment。 所以它覆盖了全屏

在 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>

将您的 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);
        }
    }

传递 DialogFrament 的实例

loadDiaogFragment(new ChatFragment);

创建以下 function

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

关闭 DialogFragment 使用以下 onClickLister

dismiss();

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM