Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 9b80d79

Browse files
authored
PopupRenderer: check for isDisposed in OnElementPropertyChanged before taking action. Fixes #1947 (#1968)
1 parent ecbc831 commit 9b80d79

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/Android/PopupRenderer.android.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public override void Show()
9393

9494
protected virtual void OnElementPropertyChanged(object? sender, PropertyChangedEventArgs args)
9595
{
96-
if (Element is BasePopup basePopup)
96+
if (Element is BasePopup basePopup && !isDisposed)
9797
{
9898
if (args.PropertyName == BasePopup.VerticalOptionsProperty.PropertyName
9999
|| args.PropertyName == BasePopup.HorizontalOptionsProperty.PropertyName

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,15 @@ protected virtual void OnElementChanged(ElementChangedEventArgs<BasePopup?> e)
8787

8888
protected virtual void OnElementPropertyChanged(object? sender, PropertyChangedEventArgs args)
8989
{
90-
if (args.PropertyName == BasePopup.VerticalOptionsProperty.PropertyName ||
91-
args.PropertyName == BasePopup.HorizontalOptionsProperty.PropertyName ||
92-
args.PropertyName == BasePopup.SizeProperty.PropertyName ||
93-
args.PropertyName == BasePopup.ColorProperty.PropertyName)
90+
if (Element is BasePopup basePopup && !isDisposed)
9491
{
95-
ConfigureControl();
92+
if (args.PropertyName == BasePopup.VerticalOptionsProperty.PropertyName ||
93+
args.PropertyName == BasePopup.HorizontalOptionsProperty.PropertyName ||
94+
args.PropertyName == BasePopup.SizeProperty.PropertyName ||
95+
args.PropertyName == BasePopup.ColorProperty.PropertyName)
96+
{
97+
ConfigureControl();
98+
}
9699
}
97100

98101
ElementPropertyChanged?.Invoke(this, args);

src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,21 @@ protected virtual void OnElementChanged(ElementChangedEventArgs<BasePopup?> e)
108108

109109
protected virtual void OnElementPropertyChanged(object? sender, PropertyChangedEventArgs args)
110110
{
111-
if (args.PropertyName == BasePopup.VerticalOptionsProperty.PropertyName ||
112-
args.PropertyName == BasePopup.HorizontalOptionsProperty.PropertyName)
111+
if (Element is BasePopup basePopup && !isDisposed)
113112
{
114-
SetLayout();
115-
}
116-
else if (args.PropertyName == BasePopup.SizeProperty.PropertyName)
117-
{
118-
SetSize();
119-
}
120-
else if (args.PropertyName == BasePopup.ColorProperty.PropertyName)
121-
{
122-
SetBackgroundColor();
113+
if (args.PropertyName == BasePopup.VerticalOptionsProperty.PropertyName ||
114+
args.PropertyName == BasePopup.HorizontalOptionsProperty.PropertyName)
115+
{
116+
SetLayout();
117+
}
118+
else if (args.PropertyName == BasePopup.SizeProperty.PropertyName)
119+
{
120+
SetSize();
121+
}
122+
else if (args.PropertyName == BasePopup.ColorProperty.PropertyName)
123+
{
124+
SetBackgroundColor();
125+
}
123126
}
124127

125128
ElementPropertyChanged?.Invoke(this, args);

0 commit comments

Comments
 (0)