Skip to content

Commit

Permalink
Fix HandlerToRendererShim dispose (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot authored and rookiejava committed Aug 31, 2021
1 parent ffd222d commit 0fd7a99
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen
{
public class HandlerToRendererShim : IVisualElementRenderer
{
bool _disposed;

public HandlerToRendererShim(INativeViewHandler vh)
{
ViewHandler = vh;
Expand All @@ -22,13 +24,17 @@ public HandlerToRendererShim(INativeViewHandler vh)

public EvasObject NativeView => ViewHandler.ContainerView ?? ViewHandler.NativeView;


public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
public event EventHandler<PropertyChangedEventArgs> ElementPropertyChanged;

public void Dispose()
{
ViewHandler.Dispose();
if (!_disposed)
{
_disposed = true;
Platform.SetRenderer(Element, null);
ViewHandler.Dispose();
}
}

public void SetElement(VisualElement element)
Expand Down Expand Up @@ -63,8 +69,8 @@ public void SetElement(VisualElement element)
ViewHandler.SetParent(new MockParentHandler(element.RealParent as VisualElement));
}

NativeView.Deleted += OnNativeDeleted;
ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(oldElement, Element));

}

void OnBatchCommitted(object sender, EventArg<VisualElement> e)
Expand All @@ -77,6 +83,11 @@ void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
ElementPropertyChanged?.Invoke(this, new PropertyChangedEventArgs(e.PropertyName));
}

void OnNativeDeleted(object sender, EventArgs e)
{
Dispose();
}

public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
return ViewHandler.GetDesiredSize(widthConstraint, heightConstraint);
Expand Down

0 comments on commit 0fd7a99

Please sign in to comment.