1
votes

I want to remove Tabbar from TabbedPage. I got it working but it leaves blank space or page height is not updated after hiding Tabbar.

Note that when we swipe through the pages, the blank goes and never comes back. This issue appears only for the first time.

I have tried from this link. But it doesn't work.

Also tried following

private void Element_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            try
            {
                TabBar.Hidden = true;

                //TabBar.Bounds = new CoreGraphics.CGRect(View.Subviews[0].Frame.X, View.Subviews[0].Frame.Y,
                //                                                     View.Subviews[0].Frame.Width, 0);

                if (TabBar.Hidden)
                {
                    // page
                    View.Subviews[0].Frame = new CoreGraphics.CGRect(0, 0, View.Subviews[1].Frame.Width, NativeView.Frame.Height);

                    // Tabbar
                    View.Subviews[1].Frame = new CoreGraphics.CGRect(View.Subviews[0].Frame.X, View.Subviews[0].Frame.Y,
                                                                     View.Subviews[0].Frame.Width, 0);
                }
                else
                {
                    View.Subviews[1].Frame = new CoreGraphics.CGRect(View.Subviews[1].Frame.X, View.Subviews[1].Frame.Y,
                                                                     View.Subviews[1].Frame.Width, 49);
                    View.Subviews[0].Frame = new CoreGraphics.CGRect(View.Subviews[0].Frame.X, View.Subviews[0].Frame.Y,
                                                                     View.Subviews[0].Frame.Width, View.Subviews[0].Frame.Height - 49);
                }

                //if (TabBar.Hidden)
                //    View.Subviews[1].Frame = new CoreGraphics.CGRect(View.Subviews[1].Frame.X, View.Subviews[1].Frame.Y, View.Subviews[1].Frame.Width, 0);
                //else
                //    View.Subviews[1].Frame = new CoreGraphics.CGRect(View.Subviews[1].Frame.X, View.Subviews[1].Frame.Y, View.Subviews[1].Frame.Width, 49);
            }
            catch (Exception ex)
            {
                //TraceLog("Element_PropertyChanged" + ex.Message);
            }
}

EDIT

I open tabbed page on list view item clicked. I allow to add multiple tabs dynamically. Also I have created custom tabbar using ContentView that I update when pages are added or removed from TabbedPage.

The sequence is : - User opens first tab. - Click on home icon given on tabbed page. - open the second page by click on another list item - swipe through the page and the page height will be normal.

Here is the code on ListView_ItemTapped (Not posted exactly how is it actually but you can get idea :) )

MultiTab ObjMultiTab = new MultiTab(); // Initialize tabbed page

// Get data from server 
ObjMultiTab.Data = ObjData; 
int Id = Convert.ToInt32(ObjData.id); 

if (ActiveList.ContainsKey(Id)) // Dictionary that contains info about index and pageid that are already open 
{ 
   TabId = ActiveList[ObjData.id]; 
   CurrentPage = Children[TabId]; // If user taps on already opend page 
} 
else 
{ 
   Count += 1; ActiveList.Add(Id, Count); 
   Children.Add(new SecondTabbedPage(TableData)); // Or add new child 
   CurrentPage = Children[Count]; 
} 

await Application.Current.MainPage.Navigation.PushModalAsync(ObjMultiTab); 

Is there any way to remove blank space for the first time also ?

2
Can you add codes in your xamarin.forms project about the TabbedPage? I did not see the blank space on my side.nevermore
@JackHua-MSFT please see the update.Ruhika

2 Answers

0
votes

Adding following function to the renderer removed blank space from TabbedPage.

public override void ViewDidLayoutSubviews()
{
    base.ViewDidLayoutSubviews();

    TabBar.Hidden = true;

    var page = View.Subviews[0];
    var tabbar = View.Subviews[1];

    tabbar.Bounds = CGRect.Empty;
    page.Bounds = UIScreen.MainScreen.Bounds;
}
0
votes

There is a solution that doesn't require any renders and works on both Android and iOS.

Wrap the TabbedPage in a NavigationPage so the structure of your app becomes

  • NavigationPage (root)
    • TappedPage
      • NavigationPage
        • ContentPage (with tabbar)
    • ContentPage (without tabbar)

On the TabbedPage you have to hide the navigationbar of the 'root' NavigationPage, otherwise you have 2 navbars.

<TabbedPage
    ...
    HasNavigationBar="False"> 

If you push a page using the 'root' NavigationPage, the tabbar is hidden and there is no blank space at the bottom.

--- Edit ---

See my example at: https://github.com/Jfcobuss/HideTabbarExample/tree/master/HideTabbarExample

Downside of this solution is

  • It is bit of an hacky workaround

  • The title next to back-button is the title of the TabbedPage, not the current tab

  • The animation to the next page is not as fluent as default