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] iOS Incorrect Behavior while using VisualStateTrigger MinWindowWidth with Locked Orientation #15787

Open dzeping96 opened 11 months ago

dzeping96 commented 11 months ago

Please let me know if any further explanation needed, English is not my first language.

Description

In XAML using VisualStateTrigger like below

<VisualStateGroup>
    <VisualState x:Name="ScreenSizeNormalVersion">
        <VisualState.StateTriggers>
            <AdaptiveTrigger MinWindowWidth="360" />
        </VisualState.StateTriggers>
        <VisualState.Setters>
            <Setter Property="FontSize" Value="12" />
        </VisualState.Setters>
    </VisualState>
    <VisualState x:Name="ScreenSizeLargeVersion">
        <VisualState.StateTriggers>
            <AdaptiveTrigger MinWindowWidth="600" />
        </VisualState.StateTriggers>
        <VisualState.Setters>
            <Setter Property="FontSize" Value="19" />
        </VisualState.Setters>
    </VisualState>
</VisualStateGroup>

works perfectly for portrait orientation, but it has weird behavior if I open it while my device landscape, although I disabled landscape orientation in Info.plist, it will open in portrait view, but the MinWindowWidth will get width of landscape.

Steps to Reproduce

  1. Use VisualStateTrigger with MinWindowWidth Property as mentioned above.
  2. Set only allow portrait orientation in Info.plist and GetSupportedInterfaceOrientations in AppDelegate.
  3. Use your iOS device, do not turn on Lock Portrait in your iPhone settings, go to home page, hold your device as landscape orientation, open your app while maintaining landscape orientation, the UI will be portrait, but it retrieves wrong FontSize value, because it will retrieve width as landscape instead of portrait.

Expected Behavior

VisualStateTrigger MinWindowWidth property will get corresponding value for portrait and landscape.

Actual Behavior

VisualStateTrigger MinWindowWidth property get landscape width even locked as portrait and UI is portrait.

Basic Information

Environment

Show/Hide Visual Studio info ``` Visual Studio Community 2022 for Mac Version 17.6.1 (build 452) Installation UUID: fb1a06e0-28af-4b23-8e51-5ec816347a94 Runtime .NET 7.0.3 (64-bit) Architecture: Arm64 Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2 Roslyn (Language Service) 4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa NuGet Version: 6.4.0.117 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/7.0.306/Sdks SDK Versions: 7.0.306 7.0.304 7.0.302 7.0.202 7.0.101 6.0.412 6.0.410 6.0.408 6.0.407 6.0.404 6.0.401 6.0.400 6.0.301 6.0.300 6.0.203 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET SDK (x64) SDK Versions: 6.0.412 6.0.410 6.0.408 6.0.407 6.0.404 6.0.401 6.0.400 6.0.301 6.0.300 6.0.106 6.0.105 6.0.104 5.0.408 5.0.407 3.1.426 3.1.423 3.1.422 3.1.420 3.1.419 3.1.418 .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.9 7.0.7 7.0.5 7.0.4 7.0.1 6.0.20 6.0.18 6.0.16 6.0.15 6.0.12 6.0.9 6.0.8 6.0.6 6.0.5 .NET Runtime (x64) Runtime: /usr/local/share/dotnet/x64/dotnet Runtime Versions: 6.0.20 6.0.18 6.0.16 6.0.15 6.0.12 6.0.9 6.0.8 6.0.6 6.0.5 6.0.4 5.0.17 5.0.16 3.1.32 3.1.29 3.1.28 3.1.26 3.1.25 3.1.24 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Apple Developer Tools Xcode: 14.3 21812 Build: 14E222b Xamarin.Mac Not Installed Xamarin.iOS Version: 16.4.0.6 Visual Studio Community Hash: 97731c92c Branch: xcode14.3 Build date: 2023-04-11 22:38:36-0400 Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2023-07-06 12:51:51 UTC Xamarin.Android Version: 13.2.0.6 (Visual Studio Community) Commit: xamarin-android/d17-5/a200af1 Android SDK: /Users/aft/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 12.0 (API level 31) 11.0 (API level 30) 10.0 (API level 29) 13.0 (API level 33) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 33.0.3 SDK Build Tools Version: 33.0.0 Build Information: Mono: 6dd9def Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@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.6.0.50 Hash: a715dca Branch: HEAD Build date: 2023-07-06 12:51:55 UTC Android Device Manager Version: 0.0.0.1309 Hash: 06e3e77 Branch: HEAD Build date: 2023-07-06 12:51:55 UTC Build Information Release ID: 1706010452 Git revision: 9c61cec4d4c4498378f5878b08459d6fd258659d Build date: 2023-07-06 12:50:14+00 Build branch: release-17.6 Build lane: release-17.6 Operating System Mac OS X 13.4.0 Darwin 22.5.0 Darwin Kernel Version 22.5.0 Mon Apr 24 20:53:44 PDT 2023 root:xnu-8796.121.2~5/RELEASE_ARM64_T8103 arm64 ```

Build Logs

Screenshots

Reproduction Link

Portrait Sample https://github.com/xamarin/Xamarin.Forms/assets/23049317/8faa918f-463f-460d-8030-66d1ddfd0d3a

Landscape Sample https://github.com/xamarin/Xamarin.Forms/assets/23049317/a703127e-f0f1-495b-8017-f44060da2e8e

Workaround

No at this moment.

NicolyLuisaG commented 10 months ago

It seems like you've encountered an issue with the behavior of your XAML layout and VisualStateTrigger when opening the app in landscape orientation. Even if you've disabled landscape orientation in your Info.plist, the MinWindowWidth value seems to be behaving as if in landscape mode. This might be due to how the adaptive triggers are calculated based on the available screen width. You could consider adjusting your design to handle landscape and portrait orientations differently, or look into any additional settings that might affect how the triggers are applied :)

dzeping96 commented 10 months ago

It seems like you've encountered an issue with the behavior of your XAML layout and VisualStateTrigger when opening the app in landscape orientation. Even if you've disabled landscape orientation in your Info.plist, the MinWindowWidth value seems to be behaving as if in landscape mode. This might be due to how the adaptive triggers are calculated based on the available screen width. You could consider adjusting your design to handle landscape and portrait orientations differently, or look into any additional settings that might affect how the triggers are applied :)

Hi @NicolyLuisaG, thanks for sharing your thoughts and opinion, that's exactly the issue I trying to explain. I will take your opinion to continue looking for any additional settings that might help to resolve this issue. I am also trying to bring out this issue for Xamarin Teams to see is there any possibilities it can be fixed on Xamarin side.

Thanks mates!