Skip to content
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

Don't use loaded/unloaded on FlyoutPage #16241

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/Controls/src/Core/FlyoutPage/FlyoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,8 @@ static object GetDefaultValue(BindableObject bindable)
public FlyoutPage()
{
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<FlyoutPage>>(() => new PlatformConfigurationRegistry<FlyoutPage>(this));

this.Loaded += OnLoaded;
this.Unloaded += OnUnloaded;
(this as IControlsVisualElement).WindowChanged += OnWindowChanged;
this.SizeChanged += OnSizeChanged;
}

readonly Lazy<PlatformConfigurationRegistry<FlyoutPage>> _platformConfigurationRegistry;
Expand All @@ -319,15 +318,27 @@ public FlyoutPage()
return _platformConfigurationRegistry.Value.On<T>();
}

void OnUnloaded(object sender, EventArgs e)
void OnSizeChanged(object sender, EventArgs e)
{
DeviceDisplay.MainDisplayInfoChanged -= OnMainDisplayInfoChanged;
if (Handler is not null)
{
Handler?.UpdateValue(nameof(FlyoutBehavior));
SizeChanged -= OnSizeChanged;
}
}

void OnLoaded(object sender, EventArgs e)
void OnWindowChanged(object sender, EventArgs e)
{
DeviceDisplay.MainDisplayInfoChanged += OnMainDisplayInfoChanged;
Handler?.UpdateValue(nameof(FlyoutBehavior));
if (Window is null)
{
SizeChanged -= OnSizeChanged;
SizeChanged += OnSizeChanged;
DeviceDisplay.MainDisplayInfoChanged -= OnMainDisplayInfoChanged;
}
else
{
DeviceDisplay.MainDisplayInfoChanged += OnMainDisplayInfoChanged;
}
}

void OnMainDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e)
Expand Down
Loading