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