chaosifier / TabView

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

Delay sliding through pages #3

Closed masiri201 closed 6 years ago

masiri201 commented 6 years ago

There is a considerable delay when sliding through the pages on the tab view, when i click the tabs it's no problem, but when i slide the pages the tab takes a while to reload and select the proper one. If somebody knows the solution for this please help me.

chaosifier commented 6 years ago

I haven't faced such an issue yet. What are the contents of your tab items? It would be easier if you could share some code.

masiri201 commented 6 years ago

Hello, My tab Items are just content pages with a label on the middle for now.

The delay its not in the slide, the slide responds well and fast, it's the tab indicator that takes a while to change the tab.

List tabs = new List(); TabItem tabMaquinas = new TabItem("Máquinas", maquinas.Content); TabItem tabStock = new TabItem("Stock",stock.Content); TabItem tabNoticias = new TabItem("Notícias",noticias.Content); tabs.Add(tabMaquinas); tabs.Add(tabStock); tabs.Add(tabNoticias); TabViewControl tabView = new TabViewControl(tabs, 0) { HeaderBackgroundColor = Color.Transparent, HeaderSelectionUnderlineColor = (Color)Application.Current.Resources["CustomOrange"], HeaderSelectionUnderlineWidth = 50, HeaderTabTextColor = (Color)Application.Current.Resources["CustomGrayPressed"], VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; that is the code i have to initialize the tabview, i'm gonna say again, the issue is not with the slide, the tabs on top just take a while before they reload and change the tab. The Underline on the botttom of the tab is where it shows that theres a delay, i slide the page and it works then after a second or two the tab changes. BUT if i click the tab directly it works fine.

chaosifier commented 6 years ago

I tried by setting different views includeing images and stack layouts, but couln't recreate the problem. What are the contents of your TabItems?

zaoky commented 6 years ago

@chaosifier this is what @masiri201 is saying Delay Sliding

If I understood correctly :D

masiri201 commented 6 years ago

Yes that's exactly what i'm talking about @zaoky thanks for clarifying ;)

masiri201 commented 6 years ago

I've managed to fix this by adding

SetPosition(positionChangingArgs.NewPosition);

to the carousel view PropertyChanged Event so it looks like this:

`private bool _supressCarouselViewPositionChangedEvent = false; private void _carouselView_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(_carouselView.Position) && !_supressCarouselViewPositionChangedEvent) { var positionChangingArgs = new PositionChangingEventArgs() { Canceled = false, NewPosition = _carouselView.Position, OldPosition = _position };

            OnPositionChanging(ref positionChangingArgs);

            if (positionChangingArgs != null && positionChangingArgs.Canceled)
            {
                _supressCarouselViewPositionChangedEvent = true;
                _carouselView.PositionSelected -= _carouselView_PositionSelected;
                _carouselView.PropertyChanged -= _carouselView_PropertyChanged;
                _carouselView.Position = _position;
                _carouselView.PositionSelected += _carouselView_PositionSelected;
                _carouselView.PropertyChanged += _carouselView_PropertyChanged;
                _supressCarouselViewPositionChangedEvent = false;
            }

            SetPosition(positionChangingArgs.NewPosition);
        }
    }`
zaoky commented 6 years ago

Great @masiri201 you did it.

Many thanks for sharing your solution, it works great 🥇 !

zaoky commented 6 years ago

@masiri201 I guess you can close the issue since you found how to fix it, at least this is going to be as documentation. :)