Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] iOS: Tabview Item does not update width when switching orientation between portrait and landscape #1294

Open
abhcr opened this issue May 14, 2021 · 20 comments
Labels
a/TabView bug Something isn't working. Breaky break. s/unverified This issue needs verification/reproduction by a team member. PRs cannot be accepted/merged.

Comments

@abhcr
Copy link

abhcr commented May 14, 2021

Description

In iOS (iPhone and iPad), tabview contents does not update their width, height, and position when orientation is switched between portrait and landscape.

Steps to Reproduce

  1. Create Tabviews with 2 or more tabview items inside one of the pages in a shell tab.
  2. Switch between tabview items in portrait orientation in iOS.
  3. Change iOS device orientation to landscape.
  4. Now switch between tabview items. The layout will be off.

Expected Behavior

Tabview items should automatically update their layout to match the device orientation changes.

Actual Behavior

Tabview items does not update their layout to match the device orientation changes.

Basic Information

  • Version with issue: Xamarin Community Toolkit 1.1.0, Xamarin Forms 5.0.0.2012
  • Last known good version: NA
  • IDE: Visual Studio for Mac community edition.
  • Platform Target Frameworks:
    • iOS: 14.5
  • Affected Devices: iPhone, iPad

Workaround

NA

Reproduction imagery

Screenshot 2021-05-14 at 6 14 47 PM

Screenshot 2021-05-14 at 6 15 53 PM

Screenshot 2021-05-14 at 6 15 37 PM

Screenshot 2021-05-14 at 6 15 30 PM

Screenshot 2021-05-14 at 6 15 20 PM

Reproduce Link:
https://github.com/jamesmontemagno/app-peloton/blob/main/src/FitnessApp/Views/ClassesPage.xaml

@abhcr abhcr added bug Something isn't working. Breaky break. s/unverified This issue needs verification/reproduction by a team member. PRs cannot be accepted/merged. labels May 14, 2021
@AustinAHunter
Copy link

I am also experiencing this same issue on the latest version of Xamarin Forms and Toolkit. The only way it works without redeploying is by navigating away and back to the ContentPage with the TabView in the wanted orientation.

@superbeller
Copy link

How to fix it?

@vhugogarcia
Copy link

vhugogarcia commented Nov 11, 2021

I'm experiencing this issue exactly. @jfversluis I'm wondering if there is a workaround for this 👍🏻 .

I'm using XCT version 1.3.0

Thanks in advance.

@jcdup
Copy link

jcdup commented Nov 15, 2021

Is anyone looking into this or would it be better to look for a different tabview?

@bijington
Copy link
Contributor

A quick investigation points to it likely being the underlying CarouselView that is not resizing its contents correctly after the orientation change.

@jcdup
Copy link

jcdup commented Nov 17, 2021

Thanks for looking into the problem

@ravi-simrun
Copy link

Hi
we have the same issue, while rotating the device the tab view messed up and overlapped the content of tabs.
it happens in the case of using xamarin community toolkit in ios. it works fine in the case of android.
any solution?

@darrenlattin
Copy link

Any update on this or workaround?

@yonkahlon
Copy link

@darrenlattin I wasn't able to find a workaround. The toolkit is awesome, but for tabs I found Sharpnado.Tabs library to be quite impressive.

https://github.com/roubachof/Sharpnado.Tabs

@darrenlattin
Copy link

@darrenlattin I wasn't able to find a workaround. The toolkit is awesome, but for tabs I found Sharpnado.Tabs library to be quite impressive.

https://github.com/roubachof/Sharpnado.Tabs

no worries. i'll have to fix the orientation for now to portrait.

Cheers

@algostax
Copy link

Are there any chances this problem will be corrected in near future ?
I have to decide - wait for fix or switch to another tabview component ,,,

@bijington
Copy link
Contributor

Are there any chances this problem will be corrected in near future ?

I have to decide - wait for fix or switch to another tabview component ,,,

I would say it's unlikely this is going to get fixed any time soon. Sadly the underlying control appears to be causing these issues so without a big bit of work it won't be fixed.

Of course if someone from the community wanted to take a look that would certainly help 😃

@vhugogarcia
Copy link

However, somebody said that the issue is not the tabview but the carouselview control from Xamarin.Forms.

Maybe it is already fixed on the service pack 9. @jfversluis I am wondering if you have heard about a fix for the carousel view resizing when changing from portrait to landscape.

😀

@algostax
Copy link

@bijington @vhugogarcia @jfversluis
If the carouselview (ios) is responsible for this error I wonder how do people use that very popular component on ios ?
Is this connected to this issue: xamarin/Xamarin.Forms#8902 ?
(closed but some problems persist ...)
I really like xct:TabView which allowed me for extensive customizations of the tabbar. But now my customer requires to have ios and android both portrait and landscape views.

Are there any chances this problem will be corrected in near future ? I have to decide - wait for fix or switch to another tabview component ,,,

@bijington
Copy link
Contributor

@algostax I certainly don't have the bandwidth to look at this issue right now. Would you be able to look at whether CarouselView really is the cause and whether there might be a solution?

@dpuckett
Copy link

dpuckett commented May 9, 2022

Is there any update on this problem? We've just come across this, and am looking at needing to implement a completely different tool otherwise, or find a way to fix a single page orientation.

@AustinAHunter
Copy link

@dpuckett I personally decided to use Sharpnado.Tabs for my application instead of the toolkit's tabs. There are a bunch of different tab styling options built into Sharpnado and they don't have any problems with orientation changes like the toolkit's do. They take a little bit more work to setup, but a lot more customizable. If you haven't checked them out yet, I'd highly recommend giving them a shot.

@bijington
Copy link
Contributor

@AustinAHunter you beat me to that recommendation 😃 yes sadly we are in an unknown area of getting this issue resolved. There is a lot of time and effort being spent get other things completed.

@dpuckett Sharpnado is a great top ion. That being said if you are happy with limiting to a single orientation that is also a workaround. Of course this might not be ideal though.

@happyfr34k
Copy link

More than 2 years later, the bug is still there and the ticket still opened...
This means that this great component cannot be used, it's a shame...

@Axel-Schneider
Copy link

Axel-Schneider commented Oct 18, 2023

@happyfr34k @dpuckett

You can solve the TabbedPage problem by overriding TabbedPage's OnSizeAllocated as follows.

public class CustomTabbedPage : TabbedPage
{
   protected override void OnSizeAllocated(double width, double height)
   {
      base.OnSizeAllocated(width, height);
      UpdateChildrenLayout();
   }
}

Use this component instead of Xamarin's TabbedPage.

For the Carousel on iOS, you can override the ios CarouselViewRenderer as follows (I found this code on xamarin/Xamarin.Forms#8902 (comment)).

[assembly: ExportRenderer(typeof(CarouselView), typeof(CustomCarouselViewRenderer))]
namespace Project.iOS.Rederers
{
    public class CustomCarouselViewRenderer : CarouselViewRenderer
    {
        private double _width;

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs changedProperty)
        {
            base.OnElementPropertyChanged(sender, changedProperty);
            if (changedProperty.PropertyName != VisualElement.WidthProperty.PropertyName ||
                _width <= 0 ||
                Element.Width <= 0 ||
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                Element.Width == _width)
            {
                _width = Element.Width;
                return;
            }

            Controller.CollectionView.ReloadData();
        }
    }
}

It works for me.
Hope this helps 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/TabView bug Something isn't working. Breaky break. s/unverified This issue needs verification/reproduction by a team member. PRs cannot be accepted/merged.
Projects
None yet
Development

No branches or pull requests