xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] Xamarin shell tabs not appearing on iOS after screen rotation. #15684

Open developerfiveneosoftware opened 1 year ago

developerfiveneosoftware commented 1 year ago

Description1

The tab views don't render correctly after rotating an iOS device on version 16.3. If you have a shell app with multiple tabs at the top, it initially loads all the data and allows the user to select the tabs. Rotating to landscape seems fine. Rotating back to portrait causes all but the first tab to disappear. The user can no longer select the tab. Rotating back to landscape causes the tabs to appear again. Portrait however will only show the first tab.

Steps to Reproduce

1) Create a new Shell project 2) Add a tab with 2 or more items. e.g:

3)Rotate the device to landscape, then rotate back to portrait. Only the first tab is visible on the top.

Expected Behavior

The tabs should be seen in both landscape and portrait mode.

Actual Behavior

All but the first tab is not visible after the device has been rotated to landscape and back.

Basic Information

Environment

Show/Hide Visual Studio info ``` 1. Visual Studio: Microsoft Visual Studio Enterprise 2022 Version 17.4.2 VisualStudio.17.Release/17.4.2+33122.133 Microsoft .NET Framework Version 4.8.04084 Installed Version: Enterprise ASP.NET and Web Tools 17.4.326.54890 ASP.NET and Web Tools Azure App Service Tools v3.0.0 17.4.326.54890 Azure App Service Tools v3.0.0 Azure Functions and Web Jobs Tools 17.4.326.54890 Azure Functions and Web Jobs Tools C# Tools 4.4.0-6.22565.8+53091686b435746d62a5df56abfab0e71203d83a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Cookiecutter 17.0.22263.6 Provides tools for finding, instantiating and customizing templates in cookiecutter format. Extensibility Message Bus 1.4.1 (main@2ee106a) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.4.19 (8c0a575) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 6.4.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Progress Telerik UI for WPF Extension 2022.3.1108.1 Progress® Telerik® UI for WPF Extension Python - Profiling support 17.0.22263.6 Profiling support for Python projects. Python with Pylance 17.0.22263.6 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers. Razor (ASP.NET Core) 17.0.0.2246202+61cc048d36a3fc9246d2f04625988b19a18ab8f0 Provides languages services for ASP.NET Core Razor. SQL Server Data Tools 17.0.62207.28050 Microsoft SQL Server Data Tools TypeScript Tools 17.0.10921.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 4.4.0-6.22565.8+53091686b435746d62a5df56abfab0e71203d83a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 17.4.0-beta.22512.4+525d5109e389341bb90b144c24e2ad1ceec91e7b Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info Xamarin 17.4.0.301 (d17-4@96af3ae) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.4.0.138 (remotes/origin/d17-4@d36bba3cc9) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 17.4.2 (c457c97) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 13.1.0.1 (d17-4/13ba222) Xamarin.Android Reference Assemblies and MSBuild support. Mono: a96bde9 Java.Interop: xamarin/java.interop/d17-4@fcc33ce2 SQLite: xamarin/sqlite/3.39.3@23e1ae7 Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a Xamarin.iOS and Xamarin.Mac SDK 16.0.0.92 (3dd3dc52c) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. Visual Studio for Mac: Visual Studio > About Visual Studio > Show Details > Copy Information [button] 2.Visual Studio Community 2022 for Mac Preview Version 17.5 Preview (17.5 build 1741) Installation UUID: a72f0583-7de8-4408-a7f9-dcc89d0d1e3c Runtime .NET 7.0.1 (64-bit) Architecture: X64 Microsoft.macOS.Sdk 12.3.2372; git-rev-head:754abbf6a3563f6267e5717ae832b4ac25b1f2fb; git-branch:release/7.0.1xx-xcode13.3 Roslyn (Language Service) 4.5.0-3.23056.2+97881342e427ff5cdcba8f12b12ff8e6f3564431 NuGet Version: 6.4.0.117 .NET SDK (x64) SDK: /usr/local/share/dotnet/sdk/7.0.200-preview.22628.1/Sdks SDK Versions: 7.0.200-preview.22628.1 7.0.100 6.0.405 6.0.403 6.0.402 6.0.400 6.0.302 5.0.408 5.0.407 5.0.406 5.0.405 5.0.404 5.0.403 5.0.402 5.0.401 5.0.400 3.1.426 3.1.425 3.1.424 3.1.422 3.1.420 3.1.419 3.1.418 3.1.417 3.1.416 3.1.415 3.1.414 3.1.413 3.1.412 MSBuild SDKs: /Applications/Visual Studio (Preview).app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET Runtime (x64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.0 6.0.13 6.0.11 6.0.10 6.0.8 6.0.7 5.0.17 5.0.16 5.0.15 5.0.14 5.0.13 5.0.12 5.0.11 5.0.10 5.0.9 3.1.32 3.1.31 3.1.30 3.1.28 3.1.26 3.1.25 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Apple Developer Tools Xcode: 14.1 21534.1 Build: 14B47b Xamarin.Mac Version: 9.1.0.2 Visual Studio Community Hash: 956a059ba Branch: xcode14.2 Build date: 2022-12-15 06:15:43-0500 Xamarin Designer Version: 17.5.3.46 Hash: e4dd80b2bb Branch: remotes/origin/d17-5 Build date: 2023-01-24 22:18:43 UTC Xamarin.iOS Version: 16.0.0.72 Visual Studio Community Hash: 6756a1146 Branch: release/6.0.4xx-xcode14 Build date: 2022-09-21 08:51:06-0400 Xamarin.Android Version: 13.2.0.0 (Visual Studio Community) Commit: xamarin-android/d17-5/797e2e1 Android SDK: /Users/developer/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 12.1 (API level 32) 12.0 (API level 31) 8.1 (API level 27) 11.0 (API level 30) 10.0 (API level 29) 9.0 (API level 28) 13.0 (API level 33) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 33.0.2 SDK Build Tools Version: 33.0.0 Build Information: Mono: 6dd9def Java.Interop: xamarin/java.interop/main@149d70fe SQLite: xamarin/sqlite/3.40.0@fdc1e34 Xamarin.Android Tools: xamarin/xamarin-android-tools/main@9f02d77 Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.16.1 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.5.0.26 Hash: 2eaa6bb Branch: remotes/origin/HEAD Build date: 2023-01-24 22:18:48 UTC Android Device Manager Version: 0.0.0.1236 Hash: bd1b161 Branch: main~1 Build date: 2023-01-24 22:18:48 UTC Build Information Release ID: 1705001741 Git revision: baaf93527ad3efd87886b9b81bf5d6871f8ac51d Build date: 2023-01-24 22:16:45+00 Build branch: release-17.5 Build lane: release-17.5 Operating System Mac OS X 12.6.0 Darwin 21.6.0 Darwin Kernel Version 21.6.0 Mon Aug 22 20:17:10 PDT 2022 root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64 ```

Screenshots

Simulator Screen Shot - iPhone 14 Pro Max - 2023-02-07 at 14 38 49

Simulator Screen Shot - iPhone 14 Pro Max - 2023-02-07 at 14 39 02

Simulator Screen Shot - iPhone 14 Pro Max - 2023-02-07 at 14 39 12

Reproduction Link

https://github.com/developerfiveneosoftware/iosTabBug.git

Workaround

No work around found.

developerfiveneosoftware commented 1 year ago

This seems to have been fixed as part of https://github.com/dotnet/maui/pull/14330 for Maui. Is it possible to reproduce this for Xamarin?

developerfiveneosoftware commented 1 year ago

I have done some more digging after the MAUI comment and have managed to get a working version with the following code:

`using System; using CoreGraphics; using Foundation; using UIKit; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(myApp.AppShell), typeof(myApp.iOS.Renderers.TabbedShellRenderer))] namespace myApp.iOS.Renderers { public class TabbedShellRenderer : ShellRenderer {

    protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
    {
        var shellSectionRenderer = new TabbedShellSectionRenderer(this);
        return shellSectionRenderer;
    }
}

public class TabbedShellSectionRenderer : ShellSectionRenderer
{
    public TabbedShellSectionRenderer(IShellContext context) : base(context)
    {

    }

    protected override IShellSectionRootRenderer CreateShellSectionRootRenderer(ShellSection shellSection, IShellContext shellContext)
    {
        var renderer = new TabbedShellSectionRootRenderer(shellSection, shellContext);
        return renderer;
    }

}

public class TabbedShellSectionRootRenderer : ShellSectionRootRenderer
{
    public TabbedShellSectionRootRenderer(ShellSection section, IShellContext context) : base(section, context)
    {

    }

    protected override IShellSectionRootHeader CreateShellSectionRootHeader(IShellContext shellContext)
    {
        var renderer = new TabbedShellSectionRootHeader(shellContext);
        return renderer;
    }
}

public class TabbedShellSectionRootHeader : ShellSectionRootHeader
{
    public TabbedShellSectionRootHeader(IShellContext context) : base(context)
    {

    }

    public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
    {
        var cell = base.GetCell(collectionView, indexPath) as ShellSectionHeaderCell;

        var cellSize = cell.GetFrame();
        var layout = new UICollectionViewFlowLayout();

        layout.ItemSize = cellSize.Size;

        collectionView.CollectionViewLayout = layout;

        return cell;
    }
}

public class CustomUICollectionViewFlowLayout : UICollectionViewFlowLayout
{
    public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
    {
        return base.LayoutAttributesForElementsInRect(rect);
    }
}

}

`

This was with help from this post on stack overflow: https://stackoverflow.com/questions/63202507/how-do-you-access-the-top-tab-toolbar-for-ios-on-shell-pages

I thought I would put this here as it may be helpful for fixing it on XAMARIN.

I am unsure of the process on how to continue and if this is an appropriate long term fix.