Skip to content

Commit

Permalink
Only change ViewHandlerDelegator for iOS/Catalyst
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpeppers committed Jun 20, 2024
1 parent cb3ecfd commit 0321a35
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ class ViewHandlerDelegator<TElement>
internal IPropertyMapper _mapper;
internal readonly CommandMapper _commandMapper;
IPlatformViewHandler _viewHandler;
#if IOS || MACCATALYST
TElement? _tempElement;
WeakReference<TElement>? _element;
public TElement? Element => _tempElement ?? _element?.GetTargetOrDefault();
#else
TElement? _element;
public TElement? Element => _element;
#endif
bool _disposed;

public ViewHandlerDelegator(
Expand Down Expand Up @@ -81,10 +86,14 @@ public void SetVirtualView(
{
#if WINDOWS
VisualElementRenderer<TElement, TNativeElement>.SetVirtualView(view, _viewHandler, onElementChanged, ref _element, ref _mapper, _defaultMapper, autoPackage);
#else
#elif IOS || MACCATALYST
// _tempElement is used here, because the Element property is accessed before SetVirtualView() returns
VisualElementRenderer<TElement>.SetVirtualView(view, _viewHandler, onElementChanged, ref _tempElement, ref _mapper, _defaultMapper, autoPackage);
// We use _element as a WeakReference, and clear _tempElement
_element = _tempElement is null ? null : new(_tempElement);
_tempElement = null;
#else
VisualElementRenderer<TElement>.SetVirtualView(view, _viewHandler, onElementChanged, ref _element, ref _mapper, _defaultMapper, autoPackage);
#endif
}

Expand Down

0 comments on commit 0321a35

Please sign in to comment.