【问题标题】:How to hide BottomTabNavigator in certain screen in React Navigation (4.x)如何在 React Navigation (4.x) 的特定屏幕中隐藏 BottomTabNavigator
【发布时间】:2020-07-08 09:48:46
【问题描述】:

我需要在使用 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...
});

我怎样才能做到这一点?

【问题讨论】:

    标签: javascript android reactjs react-navigation


    【解决方案1】:

    您无需隐藏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);
    

    创建以下函数

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

    要关闭 DialogFragment,请使用 onClickLister 中的以下内容

    dismiss();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      相关资源
      最近更新 更多