簡體   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