Skip to content

Commit

Permalink
Add Popup disposed check on Android (#1614)
Browse files Browse the repository at this point in the history
* Add disposed check

* Changes to additional guard conditions

* Add popup binding release

* Update Popup.shared.cs

---------

Co-authored-by: Brandon Minnick <[email protected]>
  • Loading branch information
cat0363 and TheCodeTraveler authored Feb 17, 2024
1 parent 9628467 commit c6654f3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,17 @@ protected virtual async Task OnClosed(object? result, bool wasDismissedByTapping
((IPopup)this).OnClosed(result);
((IResourceDictionary)resources).ValuesChanged -= OnResourcesChanged;

RemoveBinding(Popup.ContentProperty);
RemoveBinding(Popup.ColorProperty);
RemoveBinding(Popup.SizeProperty);
RemoveBinding(Popup.CanBeDismissedByTappingOutsideOfPopupProperty);
RemoveBinding(Popup.VerticalOptionsProperty);
RemoveBinding(Popup.HorizontalOptionsProperty);
RemoveBinding(Popup.StyleProperty);

await popupDismissedTaskCompletionSource.Task.WaitAsync(token);

if (Parent is not null)
{
Parent.RemoveLogicalChild(this);
}
Parent?.RemoveLogicalChild(this);

dismissWeakEventManager.HandleEvent(this, new PopupClosedEventArgs(result, wasDismissedByTappingOutsideOfPopup), nameof(Closed));
}
Expand Down Expand Up @@ -403,6 +408,5 @@ static void OnColorChanged(BindableObject bindable, object oldValue, object newV
void IPropertyPropagationController.PropagatePropertyChanged(string propertyName) =>
PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, ((IVisualTreeElement)this).GetVisualChildren());

IReadOnlyList<IVisualTreeElement> IVisualTreeElement.GetVisualChildren() =>
Content is null ? Array.Empty<IVisualTreeElement>() : new[] { Content };
IReadOnlyList<IVisualTreeElement> IVisualTreeElement.GetVisualChildren() => Content is null ? [] : [Content];
}

0 comments on commit c6654f3

Please sign in to comment.