Skip to content

Commit

Permalink
Fix ScrollView ContentSize and Padding margin (#291)
Browse files Browse the repository at this point in the history
* Fix ScrollView ContentSize and Padding margin

* Fix MapRequestScrollTo

* Update src/Core/src/Handlers/ScrollView/ScrollViewHandler.Tizen.cs

Co-authored-by: 허강호/Common Platform Lab(SR)/Principal Engineer/삼성전자 <[email protected]>

* Update src/Core/src/Handlers/ScrollView/ScrollViewHandler.Tizen.cs

Co-authored-by: 허강호/Common Platform Lab(SR)/Principal Engineer/삼성전자 <[email protected]>

* Remove MapContentSize

Co-authored-by: 허강호/Common Platform Lab(SR)/Principal Engineer/삼성전자 <[email protected]>
  • Loading branch information
myroot and rookiejava committed Dec 7, 2021
1 parent a811184 commit f044413
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
32 changes: 22 additions & 10 deletions src/Core/src/Handlers/ScrollView/ScrollViewHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,27 @@ void OnScrolled(object? sender, EventArgs e)

void OnContentLayoutUpdated(object? sender, LayoutEventArgs e)
{
// It is workaround,
// in some case, before set a size of ScrollView, if content was filled with sized items,
// after size of ScrollView was updated, a content position was moved to somewhere.
if (VirtualView != null && VirtualView.PresentedContent != null)
{
var frame = VirtualView.PresentedContent.Frame;
VirtualView.PresentedContent.ToNative(MauiContext!)?.Move((int)e.Geometry.X + frame.X.ToScaledPixel(), (int)e.Geometry.Y + frame.Y.ToScaledPixel());
}

UpdateContentSize();
}

void UpdateContentSize()
{
_ = Canvas ?? throw new InvalidOperationException($"{nameof(Canvas)} cannot be null");

// TODO: should consider Padding.HorizontalThickness/VerticalThickness here.
Canvas.MinimumWidth = VirtualView.ContentSize.Width.ToScaledPixel();
Canvas.MinimumHeight = VirtualView.ContentSize.Height.ToScaledPixel();
if (VirtualView == null || VirtualView.PresentedContent == null)
return;

Canvas.MinimumWidth = (VirtualView.PresentedContent.Margin.HorizontalThickness + VirtualView.PresentedContent.Frame.Width + VirtualView.Padding.HorizontalThickness).ToScaledPixel();
Canvas.MinimumHeight = (VirtualView.PresentedContent.Margin.VerticalThickness + VirtualView.PresentedContent.Frame.Height + VirtualView.Padding.VerticalThickness).ToScaledPixel();

// elm-scroller updates the CurrentRegion after render
EcoreMainloop.Post(() =>
Expand Down Expand Up @@ -101,11 +112,6 @@ public static void MapContent(ScrollViewHandler handler, IScrollView scrollView)
handler.UpdateContentSize();
}

public static void MapContentSize(ScrollViewHandler handler, IScrollView scrollView)
{
handler.UpdateContentSize();
}

public static void MapHorizontalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView)
{
handler.NativeView?.UpdateHorizontalScrollBarVisibility(scrollView.HorizontalScrollBarVisibility);
Expand All @@ -128,8 +134,14 @@ public static void MapRequestScrollTo(ScrollViewHandler handler, IScrollView scr
var x = request.HoriztonalOffset;
var y = request.VerticalOffset;

var region = new Rectangle(x, y, scrollView.Width, scrollView.Height).ToEFLPixel();
handler.NativeView.ScrollTo(region, true);
var region = new ElmSharp.Rect
{
X = x.ToScaledPixel(),
Y = y.ToScaledPixel(),
Width = handler.NativeView!.Geometry.Width,
Height = handler.NativeView!.Geometry.Height
};
handler.NativeView.ScrollTo(region, !request.Instant);

if (request.Instant)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/ScrollView/ScrollViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class ScrollViewHandler
[nameof(IScrollView.HorizontalScrollBarVisibility)] = MapHorizontalScrollBarVisibility,
[nameof(IScrollView.VerticalScrollBarVisibility)] = MapVerticalScrollBarVisibility,
[nameof(IScrollView.Orientation)] = MapOrientation,
#if __IOS__ || TIZEN
#if __IOS__
[nameof(IScrollView.ContentSize)] = MapContentSize
#endif
};
Expand Down

0 comments on commit f044413

Please sign in to comment.