Skip to content

Commit

Permalink
fix(effectiveviewport): [Android] The SCP is now the element flagged …
Browse files Browse the repository at this point in the history
…as ScrollHost, like on UWP
  • Loading branch information
dr1rrb committed Oct 6, 2021
1 parent 39ea361 commit 43f56d0
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void SetVerticalOffset( double offset)
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.ScrollContentPresenter", "void ScrollContentPresenter.SetVerticalOffset(double offset)");
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false || false || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Foundation.Rect MakeVisible( global::Windows.UI.Xaml.UIElement visual, global::Windows.Foundation.Rect rectangle)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ partial void EnsureFocusedElementInViewPartial()

if (Visible && FocusManager.GetFocusedElement() is UIElement focusedElement)
{
var scrollContentViewer = focusedElement.FindFirstParent<IScrollContentPresenter>();
var scrollContentViewer = focusedElement.FindFirstParent<ScrollContentPresenter>();
if (scrollContentViewer != null)
{
_padScrollContentPresenter = scrollContentViewer.Pad(OccludedRect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

namespace Windows.UI.Xaml.Controls
{
public sealed partial class ListViewBaseScrollContentPresenter : ContentPresenter, IScrollContentPresenter
public sealed partial class ListViewBaseScrollContentPresenter : IScrollContentPresenter, INativeScrollContentPresenter
{

private Thickness _oldPadding;
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
//
// This class is about to be replaced by an implementation of INativeScrollContentPresenter which only adapts the 'NativePanel'.
// For now it inherits from the ScrollContentPresenter as it's used directly in teh SV template,
// and also sets itself as the Native implementation (acts as the adapter to the NativePanel for now)
//
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE

public bool IsZoomEnabled { get; set; }
public float MinimumZoomScale { get; set; }
Expand All @@ -23,6 +28,11 @@ public sealed partial class ListViewBaseScrollContentPresenter : ContentPresente
[global::Uno.NotImplemented]
public bool BringIntoViewOnFocusChange { get; set; }

public ListViewBaseScrollContentPresenter()
{
Native = this;
}

Size? IScrollContentPresenter.CustomContentExtent
{
get
Expand All @@ -37,61 +47,35 @@ public sealed partial class ListViewBaseScrollContentPresenter : ContentPresente
}
}

void IScrollContentPresenter.SmoothScrollTo(int physicalDeltaX, int physicalDeltaY)
=> NativePanel?.SmoothScrollTo(physicalDeltaX, physicalDeltaY);

public override void ScrollTo(int x, int y)
{
NativePanel?.ScrollTo(x, y);
}

public void SmoothScrollTo(int x, int y)
Thickness INativeScrollContentPresenter.Padding
{
NativePanel?.SmoothScrollTo(x, y);
}

IDisposable IScrollContentPresenter.Pad(Rect occludedRect)
{
var viewPortPoint = UIElement.TransformToVisual(this, null).TransformPoint(new Point());
var viewPortSize = new Size(ActualWidth, ActualHeight);
var viewPortRect = new Rect(viewPortPoint, viewPortSize);
var intersection = viewPortRect;
intersection.Intersect(occludedRect);

if (!intersection.IsEmpty)
get => NativePanel?.Padding ?? default;
set
{
_oldPadding = NativePanel.Padding;
SetOccludedRectPadding(new Thickness(_oldPadding.Left, _oldPadding.Top, _oldPadding.Right, intersection.Height));
if (NativePanel is {} native)
{
native.Padding = value;
}
}

return Disposable.Create(() => SetOccludedRectPadding(_oldPadding));
}

private Thickness _occludedRectPadding;
private void SetOccludedRectPadding(Thickness occludedRectPadding)
{
_occludedRectPadding = occludedRectPadding;
NativePanel.Padding = occludedRectPadding;
}

public Rect MakeVisible(UIElement visual, Rect rectangle)
{
if (visual is FrameworkElement fe)
{
var scrollRect = new Rect(
_occludedRectPadding.Left,
_occludedRectPadding.Top,
ActualWidth - _occludedRectPadding.Right,
ActualHeight - _occludedRectPadding.Bottom
);

var visualPoint = UIElement.TransformToVisual(visual, null).TransformPoint(new Point());
var visualRect = new Rect(visualPoint, new Size(fe.ActualWidth, fe.ActualHeight));

var deltaX = Math.Min(visualRect.Left - scrollRect.Left, Math.Max(0, visualRect.Right - scrollRect.Right));
var deltaY = Math.Min(visualRect.Top - scrollRect.Top, Math.Max(0, visualRect.Bottom - scrollRect.Bottom));
void INativeScrollContentPresenter.SmoothScrollBy(int physicalDeltaX, int physicalDeltaY)
=> NativePanel?.SmoothScrollBy(physicalDeltaX, physicalDeltaY);

NativePanel.SmoothScrollBy(ViewHelper.LogicalToPhysicalPixels(deltaX), ViewHelper.LogicalToPhysicalPixels(deltaY));
}

return rectangle;
}
bool INativeScrollContentPresenter.Set(
double? horizontalOffset,
double? verticalOffset,
float? zoomFactor,
bool disableAnimation,
bool isIntermediate)
=> throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ namespace Windows.UI.Xaml.Controls
/// An Uno-only class which allows the <see cref="ScrollViewer"/> within a <see cref="ListViewBase"/> template
/// to host a native collection view.
/// </summary>
public sealed partial class ListViewBaseScrollContentPresenter : ContentPresenter, IScrollContentPresenter
public sealed partial class ListViewBaseScrollContentPresenter : ScrollContentPresenter, IScrollContentPresenter, INativeScrollContentPresenter
{
public ScrollBarVisibility HorizontalScrollBarVisibility
ScrollBarVisibility INativeScrollContentPresenter.HorizontalScrollBarVisibility
{
get
{
return NativePanel?.HorizontalScrollBarVisibility ?? ScrollBarVisibility.Auto;
}

get => NativePanel?.HorizontalScrollBarVisibility ?? ScrollBarVisibility.Auto;
set
{
if (NativePanel != null)
Expand All @@ -44,13 +40,9 @@ public ScrollBarVisibility HorizontalScrollBarVisibility
}
}

public ScrollBarVisibility VerticalScrollBarVisibility
ScrollBarVisibility INativeScrollContentPresenter.VerticalScrollBarVisibility
{
get
{
return NativePanel?.VerticalScrollBarVisibility ?? ScrollBarVisibility.Auto;
}

get => NativePanel?.VerticalScrollBarVisibility ?? ScrollBarVisibility.Auto;
set
{
if (NativePanel != null)
Expand All @@ -60,24 +52,18 @@ public ScrollBarVisibility VerticalScrollBarVisibility
}
}

public bool CanHorizontallyScroll
bool INativeScrollContentPresenter.CanHorizontallyScroll
{
get => HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled;
get => NativePanel?.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled;
set { }
}

public bool CanVerticallyScroll
bool INativeScrollContentPresenter.CanVerticallyScroll
{
get => VerticalScrollBarVisibility != ScrollBarVisibility.Disabled;
get => NativePanel?.VerticalScrollBarVisibility != ScrollBarVisibility.Disabled;
set { }
}

object IScrollContentPresenter.Content
{
get { return Content; }
set { Content = value; }
}

internal NativeListViewBase NativePanel => (Content as ItemsPresenter)?.Panel as NativeListViewBase;

public void OnMaxZoomFactorChanged(float newValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public override void DidZoom(UIScrollView scrollView)
{
// Note: untested, more may be needed to support zooming. On ScrollContentPresenter we set ViewForZoomingInScrollView (not
// obvious what it would be in the case of a list).
Owner.XamlParent?.ScrollViewer?.OnZoomInternal((float)Owner.ZoomScale);
Owner.XamlParent?.ScrollViewer?.Presenter?.OnNativeZoom((float)Owner.ZoomScale);
}
#endif

Expand All @@ -446,7 +446,7 @@ private void InvokeOnScroll()
var clampedOffset = shouldReportNegativeOffsets ?
Owner.ContentOffset :
Owner.ContentOffset.Clamp(CGPoint.Empty, Owner.UpperScrollLimit);
Owner.XamlParent?.ScrollViewer?.OnScrollInternal(clampedOffset.X, clampedOffset.Y, isIntermediate: _isInAnimatedScroll);
Owner.XamlParent?.ScrollViewer?.Presenter?.OnNativeScroll(clampedOffset.X, clampedOffset.Y, isIntermediate: _isInAnimatedScroll);
}

#if !MACCATALYST // Fix on .NET 6 Preview 6 https://github.com/unoplatform/uno/issues/5873
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public override void OnScrolled(int dx, int dy)

private void InvokeOnScroll()
{
XamlParent?.ScrollViewer?.OnScrollInternal(
XamlParent?.ScrollViewer?.Presenter?.OnNativeScroll(
ViewHelper.PhysicalToLogicalPixels(NativeLayout.HorizontalOffset),
ViewHelper.PhysicalToLogicalPixels(NativeLayout.VerticalOffset),
isIntermediate: _isInAnimatedScroll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Linq;

namespace Windows.UI.Xaml.Controls
{
internal interface INativeScrollContentPresenter
{
ScrollBarVisibility HorizontalScrollBarVisibility { get; set; }
ScrollBarVisibility VerticalScrollBarVisibility { get; set; }

bool CanHorizontallyScroll { get; set; }
bool CanVerticallyScroll { get; set; }

object Content { get; set; }

Thickness Padding { get; set; }

bool Set(
double? horizontalOffset = null,
double? verticalOffset = null,
float? zoomFactor = null,
bool disableAnimation = true,
bool isIntermediate = false);

#if __ANDROID__
// To avoid massive refactor DO NOT USE, use 'Set' instead
void SmoothScrollBy(int physicalDeltaX, int physicalDeltaY);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal partial interface IScrollContentPresenter
bool BringIntoViewOnFocusChange { get; set; }

void ScrollTo(int x, int y);

void SmoothScrollTo(int x, int y);
IDisposable Pad(Rect occludedRect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ namespace Windows.UI.Xaml.Controls
/// </summary>
internal partial interface IScrollContentPresenter
{
ScrollBarVisibility HorizontalScrollBarVisibility { get; set; }
ScrollBarVisibility VerticalScrollBarVisibility { get; set; }
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
//
// This interface is obsolete and should not used anymore.
// The logic is being move into the SCP which then re-routes to the INativeScrollContentPresenter
//
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE

ScrollBarVisibility NativeHorizontalScrollBarVisibility { set; }
ScrollBarVisibility NativeVerticalScrollBarVisibility { set; }

bool CanHorizontallyScroll { get; set; }
bool CanVerticallyScroll { get; set; }
Expand All @@ -28,8 +35,6 @@ internal partial interface IScrollContentPresenter

void OnMinZoomFactorChanged(float newValue);
void OnMaxZoomFactorChanged(float newValue);

Rect MakeVisible(UIElement visual, Rect rectangle);
}
}
#endif
Loading

0 comments on commit 43f56d0

Please sign in to comment.