提交 f5d1a2e6 编写于 作者: D David

fix(reg): Android, do not clear pointer state if view is going to be re-used in same layouting pass

上级 12175afb
......@@ -238,12 +238,32 @@ namespace Windows.UI.Xaml.Controls
return NativeLayout.CanCurrentlyScrollVertically(direction);
}
private bool _trackDetachedViews;
private readonly List<UnoViewHolder> _detachedViews = new();
internal void StartDetachedViewTracking()
=> _trackDetachedViews = true;
internal void StopDetachedViewTrackingAndNotifyPendingAsRecycled()
{
_trackDetachedViews = false;
// This should be invoked only from the LV.CleanContainer()
// **BUT** the container is not Cleaned/Prepared by the LV on Android
// https://github.com/unoplatform/uno/issues/11957
foreach (var detachedView in _detachedViews)
{
UIElement.PrepareForRecycle(detachedView.ItemView);
}
}
protected override void AttachViewToParent(View child, int index, ViewGroup.LayoutParams layoutParams)
{
var vh = GetChildViewHolder(child);
if (vh != null)
{
vh.IsDetached = false;
_detachedViews.Remove(vh);
}
base.AttachViewToParent(child, index, layoutParams);
}
......@@ -257,11 +277,11 @@ namespace Windows.UI.Xaml.Controls
if (vh != null)
{
vh.IsDetached = true;
// This should be invoked only from the LV.CleanContainer()
// **BUT** the container is not Cleaned/Prepared by the LV on Android
// https://github.com/unoplatform/uno/issues/11957
UIElement.PrepareForRecycle(view);
if (_trackDetachedViews)
{
// Avoid memory leak by adding them only when needed
_detachedViews.Add(vh);
}
}
}
base.DetachViewFromParent(index);
......@@ -273,6 +293,7 @@ namespace Windows.UI.Xaml.Controls
if (vh != null)
{
vh.IsDetached = false;
_detachedViews.Remove(vh);
}
#if DEBUG
if (!vh.IsDetachedPrivate)
......
......@@ -1252,6 +1252,8 @@ namespace Windows.UI.Xaml.Controls
return;
}
XamlParent?.NativePanel.StartDetachedViewTracking();
var needsScrapOnMeasure = isMeasure && availableExtent > 0 && availableBreadth > 0 && ChildCount > 0;
var updatedAfterCollectionChange = false;
if (_isRecycleLayoutRequested)
......@@ -1302,6 +1304,8 @@ namespace Windows.UI.Xaml.Controls
AssertValidState();
}
XamlParent?.NativePanel.StopDetachedViewTrackingAndNotifyPendingAsRecycled();
if (!isMeasure)
{
// Update HorizontalScrollRange and VerticalScrollRange because they're used by the ScrollViewer to get ExtentWidth and ExtentHeight.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册