FreshMvvm icon indicating copy to clipboard operation
FreshMvvm copied to clipboard

Need advice for rendering navigation tabs on bottom for Android

Open carsonCP opened this issue 8 years ago • 5 comments

My company is building an app for a client, and the client is hellbent on rendering navigation tabs along the bottom of the screen for Android. All our research points to creating a custom renderer for the TabbedPage class, but so far it hasn't worked, and we're not confident that will ever work in the FreshMVVM framework. We haven't found an alternative yet.

Can anyone recommend how to render FreshTabbedNavigationContainer's tabs along the bottom of the screen for Android (or all) platforms?

carsonCP avatar Aug 02 '17 15:08 carsonCP

Check out this package : https://github.com/thrive-now/BottomNavigationBarXF

mjmostachetti avatar Aug 05 '17 19:08 mjmostachetti

@carsonCP hi, did you find the solution for it.. actually I'm using FreshTabbedNavigationContainer too but no luck with bottom navigation bar menu in Android... if you have the solution for this please let me know I stuck in this.

Thanks

deepakthumbmunkeys avatar Sep 04 '17 08:09 deepakthumbmunkeys

I created my own class

public class FreshBottomTabbedNavigationContainer : BottomBarPage, IFreshNavigationService

Then you use it like you would the regular freshtabbedcontainer.

var tabbedNavigation = new FreshBottomTabbedNavigationContainer(); tabbedNavigation.AddTab<blahpagemodel>("blah", "blah.png"); tabbedNavigation.AddTab<stuffpagemodel>("stuff", "stuff.png"); tabbedNavigation.AddTab<thingspagemodel>("things", "things.png"); App.Current.MainPage = tabbedNavigation;

Hope that helps.

mjmostachetti avatar Sep 04 '17 19:09 mjmostachetti

I'm unable to display tab text in Android. @mjmostachetti I have tired the above logic. It's working on iOS but not in Android. Android is displaying only icons not text. Do you have any idea.

yalamandarao avatar Aug 03 '18 10:08 yalamandarao

here is the full implementation

public class FreshBottomTabbedNavigationContainer : BottomTabbedPage , IFreshNavigationService { List<Page> _tabs = new List<Page>(); public IEnumerable<Page> TabbedPages { get { return _tabs; } }

    public FreshBottomTabbedNavigationContainer() : this(Constants.DefaultNavigationServiceName)
    {

    }

    public FreshBottomTabbedNavigationContainer(string navigationServiceName)
    {
        NavigationServiceName = navigationServiceName;
        RegisterNavigation();
    }

    protected void RegisterNavigation()
    {
        FreshIOC.Container.Register<IFreshNavigationService>(this, NavigationServiceName);
    }

    public virtual Page AddTab<T>(string title, string icon, object data = null) where T : FreshBasePageModel
    {
        var page = FreshPageModelResolver.ResolvePageModel<T>(data);
        page.GetModel().CurrentNavigationServiceName = NavigationServiceName;
        _tabs.Add(page);
        var navigationContainer = CreateContainerPageSafe(page);
        navigationContainer.Title = title;
        if (!string.IsNullOrWhiteSpace(icon))
            navigationContainer.Icon = icon;
        Children.Add(navigationContainer);
        return navigationContainer;
    }

    internal Page CreateContainerPageSafe(Page page)
    {
        if (page is NavigationPage || page is MasterDetailPage || page is TabbedPage)
            return page;

        return CreateContainerPage(page);
    }

    protected virtual Page CreateContainerPage(Page page)
    {
        return new NavigationPage(page);
    }

    public System.Threading.Tasks.Task PushPage(Xamarin.Forms.Page page, FreshBasePageModel model, bool modal = false, bool animate = true)
    {
        if (modal)
            return this.CurrentPage.Navigation.PushModalAsync(CreateContainerPageSafe(page));
        return this.CurrentPage.Navigation.PushAsync(page);
    }

    public System.Threading.Tasks.Task PopPage(bool modal = false, bool animate = true)
    {
        if (modal)
            return this.CurrentPage.Navigation.PopModalAsync(animate);
        return this.CurrentPage.Navigation.PopAsync(animate);
    }

    public Task PopToRoot(bool animate = true)
    {
        return this.CurrentPage.Navigation.PopToRootAsync(animate);
    }

    public string NavigationServiceName { get; private set; }

    public void NotifyChildrenPageWasPopped()
    {
        foreach (var page in this.Children)
        {
            if (page is NavigationPage)
                ((NavigationPage)page).NotifyAllChildrenPopped();
        }
    }

    public Task<FreshBasePageModel> SwitchSelectedRootPageModel<T>() where T : FreshBasePageModel
    {
        var page = _tabs.FindIndex(o => o.GetModel().GetType().FullName == typeof(T).FullName);

        if (page > -1)
        {
            CurrentPage = this.Children[page];
            var topOfStack = CurrentPage.Navigation.NavigationStack.LastOrDefault();
            if (topOfStack != null)
                return Task.FromResult(topOfStack.GetModel());

        }
        return null;
    }
}

where BottomTabbedPage

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" android:TabbedPage.ToolbarPlacement="Bottom" x:Class="CustomControls.Controls.BottomTabbedPage"> <ContentPage.Content> </ContentPage.Content> </TabbedPage>

code behind not thing special there just InitializeComponent

public partial class BottomTabbedPage { public BottomTabbedPage() { InitializeComponent(); } }

minaairsupport avatar Oct 04 '18 18:10 minaairsupport