Closed ESO-ST closed 2 months ago
Verified on VS 17.10.0 Preview 4.0(8.0.20). Can repro this issue on iOS 17.2. WebViewCrashMidLoad.zip
I've added the repro to our sandbox project here
https://github.com/dotnet/maui/tree/fix_21948
The bug here is that our code that searches for the keywindow doesn't work because mopups is using it's own UIWindow
So when our life cycle code tries to search for the keywindow it doesn't return anything.
Some possible thoughts on fixes
1) in a single window scenario (no SceneDelegate) just locate the one UIWindow 2) instead of tying lifecycle events to the delegate events can we inherit from UIWindow and tie activate/deactive to events inside UIWindow instead so that it's a little closer to the source?
we should probably do one regardless if two is a better solution for this scenario
Workaround
@PureWeen Observed the same issue on iOS only with mopups, tried to use your work around. This is not working when UIWindow from binding library is the key window, as IWindow.Activated is not triggered when base.OnActivated(application) is called in AppDelegate(after minimize and try to bring app to foreground). As the window created by maui is not activated in previous scenario, we will see an exception in OnResignActivation that the window is already deactivated.
@PureWeen
I have added below in OnActivated, this is helping as a work around for scenario mentioned in previous comment:
public override void OnActivated(UIApplication application)
{
base.OnActivated(application);
if (Application.Windows.FirstOrDefault() is App.WindowFix windowFix && !windowFix.IsActivated)
{
(windowFix as IWindow).Activated();
}
}
Description
when we minimize the app and then restore it, we get a 'window was already activated' crash.
This takes place when we are showing a popup page, and then close this popup page (with a slight delay) and immediately minimize the app then restore it. Please see the repro project and follow the repro steps.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/ESO-ST/WebViewCrashMidLoad/tree/WindowWasAlreadyActivatedCrash https://github.com/dotnet/maui/tree/fix_21948
Version with bug
8.0.20 SR4
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
No response
Did you find any workaround?
no
Relevant log output
No response