Skip to content

Commit

Permalink
fix(scrolleviewer): Avoid to load change visibility of the scrollbar …
Browse files Browse the repository at this point in the history
…before it's being flagged as IsFixedOrientation
  • Loading branch information
Dr.Rx committed Oct 22, 2020
1 parent 69d8156 commit b8962e3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task When_CreateVerticalScroller_Then_DoNotLoadAllTemplate()
.Count();

Assert.IsTrue(buttons > 0); // We make sure that we really loaded the right template
Assert.IsTrue(buttons <= 8); // Ideally it should be 4
Assert.IsTrue(buttons <= 4);
}
#endif
}
Expand Down
50 changes: 35 additions & 15 deletions src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,14 @@ protected override Size ArrangeOverride(Size finalSize)
{
ViewportArrangeSize = finalSize;

return base.ArrangeOverride(finalSize);
var s = base.ArrangeOverride(finalSize);

//UpdateDimensionProperties();
//UpdateZoomedContentAlignment();

return s;
}

/// <inheritdoc />
internal override void OnLayoutUpdated()
{
base.OnLayoutUpdated();
Expand Down Expand Up @@ -673,15 +677,24 @@ private void UpdateComputedVerticalScrollability(bool invalidate)
var visibility = VerticalScrollBarVisibility;
var mode = VerticalScrollMode;

ComputedVerticalScrollBarVisibility = ComputeScrollBarVisibility(scrollable, visibility);
ComputedIsVerticalScrollEnabled = ComputeIsScrollEnabled(scrollable, visibility, mode);
var computedVisibility = ComputeScrollBarVisibility(scrollable, visibility);
var computedEnabled = ComputeIsScrollEnabled(scrollable, visibility, mode);

if (_presenter is null)
{
ComputedVerticalScrollBarVisibility = computedVisibility; // Retro-compatibility, probably useless
ComputedIsVerticalScrollEnabled = computedEnabled; // Retro-compatibility, probably useless
return; // Control not ready yet
}

MaterializeVerticalScrollBarIfNeeded();
// Note: We materialize the ScrollBar BEFORE setting the ComputedVisibility in order to avoid
// auto materialization due to databound visibility.
// This would cause materialization of both Vertical and Horizontal templates of the ScrollBar
// as we wouldn't have set the IsFixedOrientation flag yet.
MaterializeVerticalScrollBarIfNeeded(computedVisibility);

ComputedVerticalScrollBarVisibility = computedVisibility;
ComputedIsVerticalScrollEnabled = computedEnabled;

// Support for the native scroll bars (delegated to the native _presenter).
_presenter.VerticalScrollBarVisibility = ComputeNativeScrollBarVisibility(visibility, mode, _verticalScrollbar);
Expand All @@ -697,15 +710,24 @@ private void UpdateComputedHorizontalScrollability(bool invalidate)
var visibility = HorizontalScrollBarVisibility;
var mode = HorizontalScrollMode;

ComputedHorizontalScrollBarVisibility = ComputeScrollBarVisibility(scrollable, visibility);
ComputedIsHorizontalScrollEnabled = ComputeIsScrollEnabled(scrollable, visibility, mode);
var computedVisibility = ComputeScrollBarVisibility(scrollable, visibility);
var computedEnabled = ComputeIsScrollEnabled(scrollable, visibility, mode);

if (_presenter is null)
{
ComputedHorizontalScrollBarVisibility = computedVisibility; // Retro-compatibility, probably useless
ComputedIsHorizontalScrollEnabled = computedEnabled; // Retro-compatibility, probably useless
return; // Control not ready yet
}

MaterializeHorizontalScrollBarIfNeeded();
// Note: We materialize the ScrollBar BEFORE setting the ComputedVisibility in order to avoid
// auto materialization due to databound visibility.
// This would cause materialization of both Vertical and Horizontal templates of the ScrollBar
// as we wouldn't have set the IsFixedOrientation flag yet.
MaterializeHorizontalScrollBarIfNeeded(computedVisibility);

ComputedHorizontalScrollBarVisibility = computedVisibility;
ComputedIsHorizontalScrollEnabled = computedEnabled;

// Support for the native scroll bars (delegated to the native _presenter).
_presenter.HorizontalScrollBarVisibility = ComputeNativeScrollBarVisibility(visibility, mode, _horizontalScrollbar);
Expand Down Expand Up @@ -775,9 +797,6 @@ protected override void OnApplyTemplate()
_horizontalScrollbar = null;
_isHorizontalScrollBarMaterialized = false;

MaterializeVerticalScrollBarIfNeeded();
MaterializeHorizontalScrollBarIfNeeded();

var scpTemplatePart = GetTemplateChild(Parts.WinUI3.Scroller) ?? GetTemplateChild(Parts.Uwp.ScrollContentPresenter);
_presenter = scpTemplatePart as IScrollContentPresenter;

Expand Down Expand Up @@ -873,6 +892,7 @@ private void ApplyScrollContentPresenterContent()

private void UpdateSizeChangedSubscription(bool isCleanupRequired = false)
{
// TODO HERE
if (!isCleanupRequired
&& Content is IFrameworkElement element)
{
Expand Down Expand Up @@ -919,9 +939,9 @@ private void ClearContentTemplatedParent(object oldContent)
private bool _isVerticalScrollBarMaterialized;
private bool _isHorizontalScrollBarMaterialized;

private void MaterializeVerticalScrollBarIfNeeded()
private void MaterializeVerticalScrollBarIfNeeded(Visibility computedVisibility)
{
if (!_isTemplateApplied || _isVerticalScrollBarMaterialized || ComputedVerticalScrollBarVisibility != Visibility.Visible)
if (!_isTemplateApplied || _isVerticalScrollBarMaterialized || computedVisibility != Visibility.Visible)
{
return;
}
Expand All @@ -939,9 +959,9 @@ private void MaterializeVerticalScrollBarIfNeeded()
AttachScrollBars();
}

private void MaterializeHorizontalScrollBarIfNeeded()
private void MaterializeHorizontalScrollBarIfNeeded(Visibility computedVisibility)
{
if (!_isTemplateApplied || _isHorizontalScrollBarMaterialized || ComputedHorizontalScrollBarVisibility != Visibility.Visible)
if (!_isTemplateApplied || _isHorizontalScrollBarMaterialized || computedVisibility != Visibility.Visible)
{
return;
}
Expand Down

0 comments on commit b8962e3

Please sign in to comment.