Open bennoffsinger opened 7 years ago
You can update bottombar selected tab with
_bottomBar.SelectTabAtPosition(Element.Children.IndexOf(Element.CurrentPage), true);
I had to change default page so I updated tab in OnElementChanged
:
UpdateTabs ();
UpdateBarBackgroundColor ();
UpdateBarTextColor ();
_bottomBar.SelectTabAtPosition(Element.Children.IndexOf(Element.CurrentPage), true);
You may also need to update tabs in OnElementPropertyChanged
Thank you @IvanDev !
@bennoffsinger Did that solve your problem? Is there anything left to do in this issue?
Thank you @IvanDev . That did fix it for me.
@DominicFrei Would you agree that this should be out of the box behavior? If so, perhaps @IvanDev could submit a PR for this.
@IvanDev that was a helpful tip! The function does need to run after each tab change, otherwise the tabs were only visually updating the first time I programmatically changed CurrentPage. I added it in the OnElementPropertyChanged (for the CurrentPage property change) after the SwitchContent function since it needs to run after every CurrentPage change. It appears to be working solidly here now.
The code update:
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged (sender, e);
if (e.PropertyName == nameof (TabbedPage.CurrentPage)) {
SwitchContent (Element.CurrentPage);
_bottomBar.SelectTabAtPosition(Element.Children.IndexOf(Element.CurrentPage), true);
} else if (e.PropertyName == NavigationPage.BarBackgroundColorProperty.PropertyName) {
UpdateBarBackgroundColor ();
} else if (e.PropertyName == NavigationPage.BarTextColorProperty.PropertyName) {
UpdateBarTextColor ();
}
}
I'm not sure what happened to this function:
SelectTabAtPosition
Apparently it doesn't exist. I'm using v1.4.0.3.
I also reverted back to v1.4.0.2 and I don't see this function with that version either.
Where are you putting these code examples, in the PCL?
Looks like an update is coming soon https://github.com/thrive-now/BottomNavigationBarXF/pull/45
We should be good with new version, please verify
This fork https://www.nuget.org/packages/LH.BottomNavigationBar.XF/ that consists of the #45 fix until Thrive members can submit to nuget with the update
@lazmeister How are we doing on creating a new release?
One option is to check if the children of your BottomBarPage are of type ContentPage.
Has the nuget been released yet?
I was able to reproduce this in the BottomBarXFExample project. I added a NextPage button on each tab that simply navigates to the next page using the CurrentPage property. (As far as I can tell this is the appropriate way to programatically select a page -- Please tell me if that's not the case). When you click Next Page you can see that you have navigated to the appropriate page (the label changes as expected) but the tab selected in the tab bar doesn't change.
Add this to TabPage.xaml.cs: public BottomBarPage BottomBarPage { get; set; } public void OnNextTab(object sender, EventArgs args) { var currentChildIndex = BottomBarPage.Children.IndexOf(BottomBarPage.CurrentPage); var nextPageIndex = currentChildIndex + 1 == BottomBarPage.Children.Count ? 0 : currentChildIndex + 1; BottomBarPage.CurrentPage = BottomBarPage.Children[nextPageIndex]; }
In App.xaml.cs set the BottomBarPage property to give each tab access to the bottom bar: var tabPage = new TabPage () { Title = title, Icon = icon, BottomBarPage = bottomBarPage };
In the TabPage.xaml add the next button and wrap it and the grid in a stack view: