dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.95k stars 1.7k forks source link

[iOS] UIScrollView Custom Handler's Zoom View changes position after button click or resuming from OnSleep state #20632

Open Takashi125 opened 6 months ago

Takashi125 commented 6 months ago

Description

I'm currently porting our Xamarin.Forms application that has a custom ScrollViewer implementing UIKit's ScrollView. But there's a bug that whenever the screen's zoomed and the app resumes from a sleep state, the view changes its position, shrinks its ScrollHeight , and zooming out positions the page on the upper left of the screen.

Update: Pressing the button inside the grid while on zoomed state also produces the same bug.

Steps to Reproduce

  1. Load the repro project (including setting an app identifier if testing on a physical device)
  2. Start the application on an iOS device or simulator
  3. Pinch zoom in the app
  4. Go back to the home screen, then go back to the app
  5. ScrollView height shrinks, and when you pinch zoom out, the main page's offset moves to the upper left of the screen

Link to public reproduction project repository

https://github.com/Takashi125/UIScrollViewBugProj

Version with bug

7.0.101 , 8.0.3 GA

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17, iOS 15

Did you find any workaround?

No response

Relevant log output

No response

Takashi125 commented 3 months ago

Unfortunately, I wasn't able to figure out a workaround on a ScrollViewHandler. Instead, I reused XF's ScrollViewRenderer, and manually set the Frame of the ViewForZooming as a workaround. this eliminates the bug where the screen repositions itself off the screen after sleep or button tap.

            var frameSize = new CGSize(this.Width, this.Height);
            var nativeView = ((UIKit.UIView)zoomableSV.Handler.PlatformView);
            nativeView.Subviews[0].Frame = new CGRect(x: 0, y: 0, width: frameSize.Width , height: frameSize.Height);