Skip to content

Commit

Permalink
Merge pull request #5951 from unoplatform/dev/dr/wasmNativeSB
Browse files Browse the repository at this point in the history
fix(scrollviewer): [WASM] Vertical native scrollbar could appears
  • Loading branch information
dr1rrb authored May 7, 2021
2 parents aca1a3a + dc33b68 commit 534d3ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Windows.UI.Xaml.Controls
public partial class ScrollContentPresenter : ContentPresenter, IScrollContentPresenter
{
private ScrollBarVisibility _verticalScrollBarVisibility;
private ScrollBarVisibility _horizotalScrollBarVisibility;
private ScrollBarVisibility _horizontalScrollBarVisibility;

internal Size ScrollBarSize
{
Expand Down Expand Up @@ -98,7 +98,7 @@ private void HandlePointerEvent(Input.PointerRoutedEventArgs e)
ScrollBarVisibility IScrollContentPresenter.VerticalScrollBarVisibility { get => VerticalScrollBarVisibility; set => VerticalScrollBarVisibility = value; }
internal ScrollBarVisibility VerticalScrollBarVisibility
{
get { return _verticalScrollBarVisibility; }
get => _verticalScrollBarVisibility;
set
{
if (_verticalScrollBarVisibility != value)
Expand All @@ -113,12 +113,12 @@ internal ScrollBarVisibility VerticalScrollBarVisibility
ScrollBarVisibility IScrollContentPresenter.HorizontalScrollBarVisibility { get => HorizontalScrollBarVisibility; set => HorizontalScrollBarVisibility = value; }
internal ScrollBarVisibility HorizontalScrollBarVisibility
{
get { return _horizotalScrollBarVisibility; }
get => _horizontalScrollBarVisibility;
set
{
if (_horizotalScrollBarVisibility != value)
if (_horizontalScrollBarVisibility != value)
{
_horizotalScrollBarVisibility = value;
_horizontalScrollBarVisibility = value;
SetClasses(HorizontalVisibilityClasses, (int)value);
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ private void UpdateComputedVerticalScrollability(bool invalidate)

#if !UNO_HAS_MANAGED_SCROLL_PRESENTER
// Support for the native scroll bars (delegated to the native _presenter).
_presenter.VerticalScrollBarVisibility = ComputeNativeScrollBarVisibility(visibility, mode, _verticalScrollbar);
_presenter.VerticalScrollBarVisibility = ComputeNativeScrollBarVisibility(scrollable, visibility, mode, _verticalScrollbar);
if (invalidate && _verticalScrollbar is null)
{
InvalidateMeasure(); // Useless for managed ScrollBar, it will invalidate itself if needed.
Expand Down Expand Up @@ -798,7 +798,7 @@ private void UpdateComputedHorizontalScrollability(bool invalidate)

#if !UNO_HAS_MANAGED_SCROLL_PRESENTER
// Support for the native scroll bars (delegated to the native _presenter).
_presenter.HorizontalScrollBarVisibility = ComputeNativeScrollBarVisibility(visibility, mode, _horizontalScrollbar);
_presenter.HorizontalScrollBarVisibility = ComputeNativeScrollBarVisibility(scrollable, visibility, mode, _horizontalScrollbar);
if (invalidate && _horizontalScrollbar is null)
{
InvalidateMeasure(); // Useless for managed ScrollBar, it will invalidate itself if needed.
Expand Down Expand Up @@ -835,12 +835,13 @@ private static bool ComputeIsScrollEnabled(double scrollable, ScrollBarVisibilit
&& visibility != ScrollBarVisibility.Disabled
&& mode != ScrollMode.Disabled;

private ScrollBarVisibility ComputeNativeScrollBarVisibility(ScrollBarVisibility visibility, ScrollMode mode, ScrollBar? managedScrollbar)
=> mode switch
private ScrollBarVisibility ComputeNativeScrollBarVisibility(double scrollable, ScrollBarVisibility visibility, ScrollMode mode, ScrollBar? managedScrollbar)
=> (scrollable, visibility, mode, managedScrollbar) switch
{
ScrollMode.Disabled => ScrollBarVisibility.Disabled,
_ when managedScrollbar is null && Uno.UI.Xaml.Controls.ScrollViewer.GetShouldFallBackToNativeScrollBars(this) => visibility,
_ when visibility == ScrollBarVisibility.Disabled => ScrollBarVisibility.Disabled,
(_, _, ScrollMode.Disabled, _) => ScrollBarVisibility.Disabled,
(0, ScrollBarVisibility.Auto, _, null) => ScrollBarVisibility.Hidden, // If scrollable is 0, the managed scrollbar won't be realized, we prefer to hide the native one until we are sure!
(_, _, _, null) when Uno.UI.Xaml.Controls.ScrollViewer.GetShouldFallBackToNativeScrollBars(this) => visibility,
(_, ScrollBarVisibility.Disabled, _, _) => ScrollBarVisibility.Disabled,
_ => ScrollBarVisibility.Hidden // If a managed scroll bar was set in the template, native scroll bar has to stay Hidden
};

Expand Down

0 comments on commit 534d3ba

Please sign in to comment.