chaosifier / TabView

TabView control for Xamarin.Forms.
MIT License
124 stars 32 forks source link

The event PositionChanged gets called multiple times by using SetPosition(int p). #25

Closed Jerajo closed 4 years ago

Jerajo commented 5 years ago

I extended the class to solve the issue #23 by using a custom BindableObject. But when I update the position the event PositionChanged gets called multiple times.

    private void IndexChanged(object sender, PositionChangedEventArgs e)
    {
        // gets called with values: old=0 new=1,  old=1 new=0, old=0 new=1.
       // some times twice other times three times.
        if (this.CurrentIndex == e.NewPosition) return;
        userChange = true;
        this.CurrentIndex = e.NewPosition;
    }

    private static void CurrentIndexPropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var control = bindable as TabViewControlExtended;
        if (control == null || control.userChange == true) return;
        if (control?.SelectedTabIndex == (int)newValue) return;
        control.userChange = false;
        control.SelectedTabIndex = (int)newValue; // by changins the atribute
        //control?.SetPosition((int)newValue); // and also by using this metod
    }
chaosifier commented 4 years ago

The issue has been fix. Will update the nuget package shortly.