Skip to content

Commit

Permalink
feat(scrollViewer): Coerce the scroll mode with the visibility and hi…
Browse files Browse the repository at this point in the history
…de native SB when managed used.
  • Loading branch information
dr1rrb committed Aug 3, 2020
1 parent efcc30f commit f19e564
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 179 deletions.
Expand Up @@ -44,8 +44,6 @@ public ScrollBarVisibility HorizontalScrollBarVisibility
}
}

public ScrollMode HorizontalScrollMode { get; set; }

public ScrollBarVisibility VerticalScrollBarVisibility
{
get
Expand All @@ -62,8 +60,6 @@ public ScrollBarVisibility VerticalScrollBarVisibility
}
}

public ScrollMode VerticalScrollMode { get; set; }

View IScrollContentPresenter.Content
{
get { return Content as View; }
Expand Down
Expand Up @@ -30,8 +30,6 @@ internal partial interface IScrollContentPresenter
{
ScrollBarVisibility HorizontalScrollBarVisibility { get; set; }
ScrollBarVisibility VerticalScrollBarVisibility { get; set; }
ScrollMode HorizontalScrollMode { get; set; }
ScrollMode VerticalScrollMode { get; set; }
View Content { get; set; }

void OnMinZoomFactorChanged(float newValue);
Expand Down
Expand Up @@ -45,28 +45,6 @@ public ScrollBarVisibility HorizontalScrollBarVisibility
}
}

public ScrollMode _horizontalScrollMode;
public ScrollMode HorizontalScrollMode
{
get { return _horizontalScrollMode; }
set
{
_horizontalScrollMode = value;
UpdateScrollSettings();
}
}

private ScrollMode _verticalScrollMode;
public ScrollMode VerticalScrollMode
{
get { return _verticalScrollMode; }
set
{
_verticalScrollMode = value;
UpdateScrollSettings();
}
}

private ILayouter _layouter;

public NativeScrollContentPresenter()
Expand Down Expand Up @@ -161,9 +139,9 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
private void UpdateScrollSettings()
{
var verticalScrollVisible = VerticalScrollBarVisibility == ScrollBarVisibility.Auto || VerticalScrollBarVisibility == ScrollBarVisibility.Visible;
var verticalScrollEnabled = VerticalScrollBarVisibility != ScrollBarVisibility.Disabled && VerticalScrollMode != ScrollMode.Disabled;
var verticalScrollEnabled = VerticalScrollBarVisibility != ScrollBarVisibility.Disabled;
var horizontalScrollVisible = HorizontalScrollBarVisibility == ScrollBarVisibility.Auto || HorizontalScrollBarVisibility == ScrollBarVisibility.Visible;
var horizontalScrollEnabled = HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled && HorizontalScrollMode != ScrollMode.Disabled;
var horizontalScrollEnabled = HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled;

VerticalScrollBarEnabled = verticalScrollVisible;
HorizontalScrollBarEnabled = horizontalScrollVisible;
Expand Down
Expand Up @@ -122,10 +122,6 @@ public override void SetContentOffset(CGPoint contentOffset, bool animated)
}
}

public ScrollMode HorizontalScrollMode { get; set; }

public ScrollMode VerticalScrollMode { get; set; }

public override void SetNeedsLayout()
{
base.SetNeedsLayout();
Expand Down Expand Up @@ -172,8 +168,8 @@ private void UpdateDelayedTouches()
if (TouchesManager.Listeners == 0)
{
// This prevents unnecessary touch delays (which affects the pressed visual states of buttons) when user can't scroll.
var canScrollVertically = VerticalScrollMode != ScrollMode.Disabled && ContentSize.Height > Frame.Height;
var canScrollHorizontally = HorizontalScrollMode != ScrollMode.Disabled && ContentSize.Width > Frame.Width;
var canScrollVertically = VerticalScrollBarVisibility != ScrollBarVisibility.Disabled && ContentSize.Height > Frame.Height;
var canScrollHorizontally = HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled && ContentSize.Width > Frame.Width;
DelaysContentTouches = canScrollHorizontally || canScrollVertically;
}
else
Expand Down
Expand Up @@ -163,8 +163,8 @@ public override void Layout()
private CGSize AdjustContentSize(CGSize measuredSize)
{
//ScrollMode does not affect the measure pass, so we only take it into account when setting the ContentSize of the UIScrollView and not in the SizeThatFits
var isHorizontalScrollDisabled = HorizontalScrollMode == ScrollMode.Disabled || HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled;
var isVerticalScrollDisabled = VerticalScrollMode == ScrollMode.Disabled || VerticalScrollBarVisibility == ScrollBarVisibility.Disabled;
var isHorizontalScrollDisabled = HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled;
var isVerticalScrollDisabled = VerticalScrollBarVisibility == ScrollBarVisibility.Disabled;

//UIScrollView will not scroll if its ContentSize is smaller than the available size
//Therefore, force the ContentSize dimension to 0 when we do not want to scroll
Expand Down Expand Up @@ -252,7 +252,7 @@ private nfloat GetAdjustedArrangeWidth(IFrameworkElement child, nfloat horizonta
}

// Apply ScrollMode
if (HorizontalScrollMode == ScrollMode.Disabled || HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled)
if (HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled)
{
// Make it at most as big as the view port
adjustedWidth = (nfloat)Math.Min(adjustedWidth, viewPortWidth);
Expand Down Expand Up @@ -331,7 +331,7 @@ private nfloat GetAdjustedArrangeHeight(IFrameworkElement child, nfloat vertical
}

// Apply ScrollMode
if (VerticalScrollMode == ScrollMode.Disabled || VerticalScrollBarVisibility == ScrollBarVisibility.Disabled)
if (VerticalScrollBarVisibility == ScrollBarVisibility.Disabled)
{
// Make it at most as big as the view port
adjustedHeight = (nfloat)Math.Min(adjustedHeight, viewPortHeight);
Expand Down
Expand Up @@ -35,10 +35,6 @@ public NativeScrollContentPresenter()

public CGPoint UpperScrollLimit { get; }

public ScrollMode HorizontalScrollMode { get; set; }

public ScrollMode VerticalScrollMode { get; set; }

public float MinimumZoomScale { get; set; }

public float MaximumZoomScale { get; set; }
Expand Down
Expand Up @@ -19,10 +19,10 @@ public partial class ScrollContentPresenter : ContentPresenter, IScrollContentPr
{
protected override Size MeasureOverride(Size size)
{
var child = Content as UIElement;
if (child != null)
if (Content is UIElement child)
{
var slotSize = size;

if (VerticalScrollBarVisibility != ScrollBarVisibility.Disabled)
{
slotSize.Height = double.PositiveInfinity;
Expand All @@ -32,6 +32,12 @@ protected override Size MeasureOverride(Size size)
slotSize.Width = double.PositiveInfinity;
}

#if __WASM__
Console.WriteLine($"[{this}-{HtmlId}] MEASURE:"
+ $" available: {size}"
+ $" availableForChild: {slotSize}");
#endif

child.Measure(slotSize);

return new Size(
Expand All @@ -45,11 +51,9 @@ protected override Size MeasureOverride(Size size)

protected override Size ArrangeOverride(Size finalSize)
{
var child = Content as UIElement;
if (child != null)
if (Content is UIElement child)
{
var slotSize = finalSize;

var desiredChildSize = child.DesiredSize;

if (VerticalScrollBarVisibility != ScrollBarVisibility.Disabled)
Expand All @@ -61,6 +65,13 @@ protected override Size ArrangeOverride(Size finalSize)
slotSize.Width = Math.Max(desiredChildSize.Width, finalSize.Width);
}

#if __WASM__
Console.WriteLine($"[{this}-{HtmlId}] ARRANGE:"
+ $" available: {finalSize}"
+ $" availableForChild: {slotSize}"
+ $" desiredByChild: {desiredChildSize}");
#endif

child.Arrange(new Rect(new Point(0, 0), slotSize));
}

Expand Down
Expand Up @@ -19,10 +19,6 @@ public partial class ScrollContentPresenter : ContentPresenter
{
private ScrollBarVisibility _verticalScrollBarVisibility;
private ScrollBarVisibility _horizotalScrollBarVisibility;
private ScrollMode _horizontalScrollMode1;
private ScrollMode _verticalScrollMode1;

private static readonly string[] HorizontalModeClasses = { "scrollmode-x-disabled", "scrollmode-x-enabled", "scrollmode-x-auto" };

internal Size ScrollBarSize
{
Expand Down Expand Up @@ -97,27 +93,29 @@ private void HandlePointerEvent(Input.PointerRoutedEventArgs e)
}
}

public ScrollMode HorizontalScrollMode
{
get => _horizontalScrollMode1;
set
{
_horizontalScrollMode1 = value;
SetClasses(HorizontalModeClasses, (int)value);
}
}

private static readonly string[] VerticalModeClasses = { "scrollmode-y-disabled", "scrollmode-y-enabled", "scrollmode-y-auto" };

public ScrollMode VerticalScrollMode
{
get => _verticalScrollMode1;
set
{
_verticalScrollMode1 = value;
SetClasses(VerticalModeClasses, (int)value);
}
}
//private static readonly string[] HorizontalModeClasses = { "scrollmode-x-disabled", "scrollmode-x-enabled", "scrollmode-x-auto" };

//public ScrollMode HorizontalScrollMode
//{
// get => _horizontalScrollMode1;
// set
// {
// _horizontalScrollMode1 = value;
// SetClasses(HorizontalModeClasses, (int)value);
// }
//}

//private static readonly string[] VerticalModeClasses = { "scrollmode-y-disabled", "scrollmode-y-enabled", "scrollmode-y-auto" };

//public ScrollMode VerticalScrollMode
//{
// get => _verticalScrollMode1;
// set
// {
// _verticalScrollMode1 = value;
// SetClasses(VerticalModeClasses, (int)value);
// }
//}

public float MinimumZoomScale { get; private set; }

Expand All @@ -130,8 +128,16 @@ public ScrollBarVisibility VerticalScrollBarVisibility
get { return _verticalScrollBarVisibility; }
set
{
_verticalScrollBarVisibility = value;
SetClasses(VerticalVisibilityClasses, (int)value);
#if __WASM__
Console.WriteLine($"[{this}-{HtmlId}] setting VerticalScrollBarVisibility:{value} ({(int)value} - {VerticalVisibilityClasses[(int)value]})"
+ $" (was: {_verticalScrollBarVisibility} ({(int)_verticalScrollBarVisibility} - {VerticalVisibilityClasses[(int)_verticalScrollBarVisibility]}))");
#endif

if (_verticalScrollBarVisibility != value)
{
_verticalScrollBarVisibility = value;
SetClasses(VerticalVisibilityClasses, (int)value);
}
}
}
private static readonly string[] HorizontalVisibilityClasses = { "scroll-x-auto", "scroll-x-disabled", "scroll-x-hidden", "scroll-x-visible" };
Expand All @@ -141,8 +147,11 @@ public ScrollBarVisibility HorizontalScrollBarVisibility
get { return _horizotalScrollBarVisibility; }
set
{
_horizotalScrollBarVisibility = value;
SetClasses(HorizontalVisibilityClasses, (int)value);
if (_horizotalScrollBarVisibility != value)
{
_horizotalScrollBarVisibility = value;
SetClasses(HorizontalVisibilityClasses, (int)value);
}
}
}

Expand Down

0 comments on commit f19e564

Please sign in to comment.