Bug 58441 - Tabs bar on TabbedPage doesn't scroll to selected Tab if set programmatically.
Summary: Tabs bar on TabbedPage doesn't scroll to selected Tab if set programmatically.
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.5
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-27 17:54 UTC by dpedrinha
Modified: 2017-11-27 04:45 UTC (History)
3 users (show)

Tags: ac android tabbedpage tablayout currentpage
Is this bug a regression?: ---
Last known good build:


Attachments
Sample project (596.72 KB, application/x-zip-compressed)
2017-07-27 17:54 UTC, dpedrinha
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 58441 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description dpedrinha 2017-07-27 17:54:51 UTC
Created attachment 23852 [details]
Sample project

If I have more tabs than fit the screen, on Android I can set the tabmode to scrollable.

But if I programmatically set the selected item (either with SelectedItem or CurrentPage) to a tab out of the screen, on Android, the tabs doesn't scroll to the selected tab, always showing the first tabs.

On UWP it's working fine, on iOS it doesn't work because it uses the "more" button.

But on Android, it is selecting the right Child, displaying its content, but not scrolling the tabs to show the right tab (if it's out of the screen) on the tabs bar.

If I scroll the tabs manually, the correct tab is selected, but this user experience is really bad.

I'm attaching a sample project to test it. Once the Open TabbedPage is clicked, it will open the TabbedPage and show the Tab 10 content, but the tabs will still be showing Tab 1, 2, 3 and 4.
Comment 1 Jimmy [MSFT] 2017-07-28 14:53:30 UTC
I was able to reproduce this issue on Android using the attached repro project. 

### Steps to Reproduce
1. Run the attached Android project
2. Press "Open TabbedPage"


### Expected Results
The TabbedPage will display and the tab bar will show that "Tab 10" is selected.


### Actual Results
The TabbedPage is opened and the "Tab 10" page contents are displayed however the tab bar does not show the "Tab 10" tab unless you scroll to it.


### Additional Information
This happens when the Android TabLayout TabMode is set to be scrollable. If using the default, fixed setting then all the tabs are visible but sized to fit horizontally.


### Version Tests
2.3.6.121   BAD
2.3.5-pre6  BAD
2.3.4.247   BAD
Comment 2 dpedrinha 2017-08-01 19:44:30 UTC
I managed to workaround the problem with an Android Renderer.

(thanks to this guy: https://stackoverflow.com/questions/45356270/how-to-force-xamarin-forms-tabbedpage-to-scroll-to-selected-tab-progammatically/45406150#45406150 )

So I guess all it needs is to fix it in the default Android Renderer.

public class MyTabbedPageRenderer : TabbedPageRenderer
    {
        private TabLayout tabLayout = null;

        protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {
            base.OnElementChanged(e);

            this.tabLayout = (TabLayout)this.GetChildAt(1);

            var selectPosition = this.tabLayout.SelectedTabPosition;

            tabLayout.TabMode = TabLayout.ModeScrollable;
            tabLayout.TabGravity = TabLayout.GravityFill;

            Handler h = new Handler();
            Action myAction = () =>
            {
                tabLayout.GetTabAt(selectPosition).Select();
            };

            h.PostDelayed(myAction, 200);
        }
    }
Comment 3 Melbourne Developer 2017-11-27 04:45:21 UTC
This is still a bug.

The bug isn't so much that it's hard to change. The bug is that it defaults to the wrong mode. The mode that it defaults to is mismatched with other platforms. Out of the box, any controls in Xamarin Forms should behave exactly the same as controls on other platforms, even when this does not match the platform's default behaviour.