Skip to content

[Bug] iOS AutoDisconnectHandler appears to be breaking layout on re-appearing modal #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
brendonupson opened this issue Apr 4, 2025 · 18 comments · May be fixed by #33
Open

[Bug] iOS AutoDisconnectHandler appears to be breaking layout on re-appearing modal #31

brendonupson opened this issue Apr 4, 2025 · 18 comments · May be fixed by #33
Assignees
Labels
bug Something isn't working

Comments

@brendonupson
Copy link

Description

I have a shell app (bottom tabs) which launches modal pages. When a modal page contains a SegmentedControl and a subsequent modal page is displayed then dismissed, the segmented control appears in the wrong place on the original page.

Issue only seems to affect iOS.

If I add AutoDisconnectHandler="False", the problem does NOT occur. However, if I apply this "fix" I'm unsure if there are memory leak issues.

Steps to Reproduce

  1. Shell app with tabs
  2. Display a modal page containing Segmented Controls
  3. Push another modal page on to the stack (Merge develop into main #2 disappears but is still in the modal stack)
  4. Dismiss the modal (Merge develop into main #2 re-appears)
  5. Segmented Control (in Merge develop into main #2) is now in the wrong part of the page

Expected Behavior

  • Page layout should remain the same

Actual Behavior

  • Page layout is broken, segmented controls are pushed into the ui elements above

Basic Information

  • Version with issue: 1.4.16
  • Last known good version: N/A

Screenshots, Attachments, Links

@brendonupson brendonupson added the bug Something isn't working label Apr 4, 2025
@brendonupson
Copy link
Author

Image

@thomasgalliker
Copy link
Owner

You're absolutely right with all your assumptions. AutoDisconnectHandler="False" does not call the DisconnectHandler method in SegmentedControlHandlers (which sooner but rather later leads to memory leaks).
The problem that seems to happen here is that the handler for one of your SegmentedControls gets disconnected too soon. We have to find out what navigation scenario this is and how I can reproduce it in the sample app in this repository.

@thomasgalliker thomasgalliker self-assigned this Apr 4, 2025
@thomasgalliker
Copy link
Owner

I'm not familiar with shell apps. Would it be possible to get a very minimal shell app which causes this problem?

@brendonupson
Copy link
Author

The problem that seems to happen here is that the handler for one of your SegmentedControls gets disconnected too soon. We have to find out what navigation scenario this is and how I can reproduce it in the sample app in this repository.

I think the SegmentedControl is not properly checking the modal page stack, likely in HandlerCleanUpHelper.cs:
private static bool CheckIfPageIsUsed(Page targetPage)

I'll try to make a simple app to reproduce.

@thomasgalliker
Copy link
Owner

It is surely a problem is the CheckIfPageIsUsed method. The thing is, this method is growing with more scenarios :)

I wish MAUI would solve this DisconnectHandler problem for us... but at least for .net 8 they don't.

@brendonupson
Copy link
Author

Usage:

  • Click "Open Modal Page" from Tab1
  • Click "Open Another Modal Page"
  • Click "Close Modal Page"
  • Observe broken layout. If layout is not broken, click "Open Another Modal Page" again. After a couple of times it should trigger a ui layout.

https://github.com/brendonupson/SegControlTest

@brendonupson
Copy link
Author

Image
Image

@brendonupson
Copy link
Author

Maybe just needs line 79 in HandlerCleanUpHelper.cs changed from:

return pageExists;

to:

if(pageExists) return true;

Then the code will fall through and check further?

@vhugogarcia
Copy link

Hello @brendonupson , is this PR expected to fix the layout issue with the segmented control on modal pages? #32

cc: @thomasgalliker

Thanks in advance

@thomasgalliker
Copy link
Owner

Important question: How are you registering pages in the DI container? Singleton or transient?
If you register pages and viewmodels as singleton (which I do not recommend) you have to disable to AutoDisconnectHandler feature.

@thomasgalliker
Copy link
Owner

Ok, ignore my question regarding DI registrations. I just had a look at your sample app (very valuable; always in such situations!). There is something wrong in the automatic disconnect logic. SegmentedControlHandler on Modal1Page is (mistakenly) disconnected when Modal2Page is displayed.

@thomasgalliker
Copy link
Owner

There is a fix available for this problem. A new nuget pre-release will be available soon.

@vhugogarcia
Copy link

Thanks @thomasgalliker for the support, really appreciate it 🙂

@thomasgalliker
Copy link
Owner

@vhugogarcia and @brendonupson can you test Plugin.SegmentedControl.Maui 1.4.25-pre and let me know if it solves the problem? 👍🏻

"Buy Me A Coffee"

@brendonupson
Copy link
Author

Looks like it's fixed for me on iOS, yet to test Android

@vhugogarcia
Copy link

I out of the town today and this weekend, I can help to test on iOS and Android next Monday, I am sorry

@vhugogarcia
Copy link

Hello @thomasgalliker , I tried the version you provided, however, the issue is still present. Please see the video below. Also, find below the console log:
HandlerCleanUpHelper.AddCleanUpEvent for "SegmentedControl" on page "LocationPage"

I have the project locally cloned, if there is something you want me to try, let me know and I can update the code. I will also give it a try myself to see if I can find out the root cause.

Screen.Recording.2025-04-22.at.7.45.50.a.m.mov

@thomasgalliker
Copy link
Owner

@vhugogarcia I saw your video but it's hard to tell if this is a related problem. I need a sample reproduction app to debug the code, just as @brendonupson has provided one above. In case of @brendonupson, the problem with the HandlerCleanUpHelper could be solved in PR #33. Can you also provide a sample sample app which only demonstrates the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants