Browse Source

FIx bringing an item into view.

pull/4091/head
Steven Kirk 6 years ago
parent
commit
6c19e729a3
  1. 6
      src/Avalonia.Controls/Repeater/ItemsRepeater.cs
  2. 40
      src/Avalonia.Controls/Repeater/ViewportManager.cs

6
src/Avalonia.Controls/Repeater/ItemsRepeater.cs

@ -80,6 +80,7 @@ namespace Avalonia.Controls
static ItemsRepeater() static ItemsRepeater()
{ {
ClipToBoundsProperty.OverrideDefaultValue<ItemsRepeater>(true); ClipToBoundsProperty.OverrideDefaultValue<ItemsRepeater>(true);
RequestBringIntoViewEvent.AddClassHandler<ItemsRepeater>((x, e) => x.OnRequestBringIntoView(e));
} }
/// <summary> /// <summary>
@ -743,6 +744,11 @@ namespace Avalonia.Controls
} }
} }
private void OnRequestBringIntoView(RequestBringIntoViewEventArgs e)
{
_viewportManager.OnBringIntoViewRequested(e);
}
private void InvalidateMeasureForLayout(object sender, EventArgs e) => InvalidateMeasure(); private void InvalidateMeasureForLayout(object sender, EventArgs e) => InvalidateMeasure();
private void InvalidateArrangeForLayout(object sender, EventArgs e) => InvalidateArrange(); private void InvalidateArrangeForLayout(object sender, EventArgs e) => InvalidateArrange();

40
src/Avalonia.Controls/Repeater/ViewportManager.cs

@ -306,8 +306,11 @@ namespace Avalonia.Controls
public void OnMakeAnchor(IControl anchor, bool isAnchorOutsideRealizedRange) public void OnMakeAnchor(IControl anchor, bool isAnchorOutsideRealizedRange)
{ {
_makeAnchorElement = anchor; if (_makeAnchorElement != anchor)
_isAnchorOutsideRealizedRange = isAnchorOutsideRealizedRange; {
_makeAnchorElement = anchor;
_isAnchorOutsideRealizedRange = isAnchorOutsideRealizedRange;
}
} }
public void OnBringIntoViewRequested(RequestBringIntoViewEventArgs args) public void OnBringIntoViewRequested(RequestBringIntoViewEventArgs args)
@ -334,13 +337,12 @@ namespace Avalonia.Controls
////} ////}
} }
// Register to rendering event to go back to how things were before where any child can be the anchor. // Register action to go back to how things were before where any child can be the anchor.
_isBringIntoViewInProgress = true; if (!_isBringIntoViewInProgress)
////if (!m_renderingToken) {
////{ _isBringIntoViewInProgress = true;
//// winrt::Windows::UI::Xaml::Media::CompositionTarget compositionTarget{ nullptr }; Dispatcher.UIThread.Post(OnCompositionTargetRendering);
//// m_renderingToken = compositionTarget.Rendering(winrt::auto_revoke, { this, &ViewportManagerWithPlatformFeatures::OnCompositionTargetRendering }); }
////}
} }
} }
@ -362,6 +364,26 @@ namespace Avalonia.Controls
return targetChild; return targetChild;
} }
private void OnCompositionTargetRendering()
{
_isBringIntoViewInProgress = false;
_makeAnchorElement = null;
// Now that the item has been brought into view, we can let the anchor provider pick a new anchor.
////foreach (var child in _owner.Children)
////{
//// if (!child.CanBeScrollAnchor)
//// {
//// var info = ItemsRepeater.GetVirtualizationInfo(child);
//// if (info.IsRealized && info.IsHeldByLayout)
//// {
//// child.CanBeScrollAnchor = true;
//// }
//// }
////}
}
public void ResetScrollers() public void ResetScrollers()
{ {
_scroller = null; _scroller = null;

Loading…
Cancel
Save