dotnet / dotnet/maui

ContentView doesn't get correct layout when hosted in legacy renderer

Open
#3,657 12 comments 0 reactions 0 assignees View on GitHub
area-layout platform/ios s/needs-attention s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

Some controls like the current flyout implementation (and controls in our application) call `Platform.GetRenderer` on the child control(s). If the child control is `ContentView` (or a derived type like `RefreshView`) it gets backed by some default renderer instead of `ContentViewHandler`. That causes the whole layout logic for `ContentView.Content` to be missing and not called on iOS (and possibly other platforms). _On reinspection the control is still backed by `ContentViewHandler` but it never gets the layout calls like when hosted directly._

I placed breakpoints in our control. If the `ContentView`-derived control was placed directly on a `Page` it was correctly backed by `ContentViewHandler` and `IContentView.CrossPlatformArrange` got called from `ContentView.LayoutSubviews`. However, when placed on `FlyoutPage` the method `IContentView.CrossPlatformArrange` never gets called.

Some issues like https://github.com/dotnet/maui/issues/2485 exhibit the same behavior and may have identical root cause.

### Steps to Reproduce

Test app: [Archive.zip](https://github.com/dotnet/maui/files/7652581/Archive.zip)

Run it. If it worked correctly you'd get `InvalidOperationException("IF YOU GOT HERE THE BUG IS FIXED");` from the layout call. However, it does not and hence it won't crash.

### Version with bug

Preview 10 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

iOS, I was *not* able test on other platforms

### Affected platform versions

All

### Did you find any workaround?

_No response_

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Run the linked Archive.zip test app on iOS and compare a ContentView hosted directly on a Page with one hosted on FlyoutPage. Trace Platform.GetRenderer and IContentView.CrossPlatformArrange; the issue is fixed when the FlyoutPage-hosted control receives the layout call and the repro reaches its InvalidOperationException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.