pocheshire / BottomNavigationBar

Bottom Navigation Bar for Xamarin
214 stars 70 forks source link

How to animate when selecting a tab programmatically? #29

Closed geft closed 7 years ago

geft commented 7 years ago

I found this but it's private.

private void selectTabAtPosition(int position, boolean animate) {
        BottomBarTab oldTab = getCurrentTab();
        BottomBarTab newTab = getTabAtPosition(position);

        oldTab.deselect(animate);
        newTab.select(animate);

        updateSelectedTab(position);
        shiftingMagic(oldTab, newTab, animate);
        handleBackgroundColorChange(newTab, false);
    }
pocheshire commented 7 years ago
public void SelectTabAtPosition(int position, bool animate)
{
    if (_items == null || _items.Length == 0)
    {
        throw new InvalidOperationException("Can't select tab at " +
            "position " + position + ". This BottomBar has no items set yet.");
    }
    else if (position > _items.Length - 1 || position < 0)
    {
        throw new ArgumentOutOfRangeException("Can't select tab at position " +
            position + ". This BottomBar has no items at that position.");
    }

    var oldTab = ItemContainer.FindViewWithTag(TAG_BOTTOM_BAR_VIEW_ACTIVE);
    var newTab = ItemContainer.GetChildAt(position);

    UnselectTab(oldTab, animate);
    SelectTab(newTab, animate);

    UpdateSelectedTab(position);
    ShiftingMagic(oldTab, newTab, animate);
}

https://github.com/pocheshire/BottomNavigationBar/blob/v1/src/bottom-navigation-bar/BottomBar.cs