Skip to content

Commit

Permalink
fix: Adjust ScrollContentPresenter.ViewportWidth/Height on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Apr 9, 2022
1 parent e92379f commit 9a4e884
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,13 @@ public async Task When_Presenter_Doesnt_Take_Up_All_Space()
Assert.AreEqual(ContentWidth - PresenterActualWidth, SUT.ScrollableWidth);
;
}

[TestMethod]
#if __WASM__
// Issue needs to be fixed first for WASM for Right and Bottom Margin missing
// Details here: https://github.com/unoplatform/uno/issues/7000
[Ignore]
#endif
public async Task When_ScrollViewer_Centered_With_Margin_Inside_Tall_Rectangle()
{
const int ContentHeight = 300;
Expand Down Expand Up @@ -243,14 +248,15 @@ public async Task When_ScrollViewer_Centered_With_Margin_Inside_Tall_Rectangle()
const double ScrollViewerHeight = ContentHeight + 2 * ContentMargin;
await WindowHelper.WaitForEqual(ScrollViewerHeight, () => SUT.ActualHeight);

// Issue needs to be fixed first for WASM for Right and Bottom Margin missing
// Details here: https://github.com/unoplatform/uno/issues/7000
#if !__WASM__
Assert.AreEqual(ScrollViewerHeight, SUT.ExtentHeight);
#endif
}

[TestMethod]
#if __WASM__
// Issue needs to be fixed first for WASM for Right and Bottom Margin missing
// Details here: https://github.com/unoplatform/uno/issues/7000
[Ignore]
#endif
public async Task When_ScrollViewer_Centered_With_Margin_Inside_Wide_Rectangle()
{
const int ContentWidth = 300;
Expand Down Expand Up @@ -279,11 +285,7 @@ public async Task When_ScrollViewer_Centered_With_Margin_Inside_Wide_Rectangle()
const double ScrollViewerWidth = ContentWidth + 2 * ContentMargin;
await WindowHelper.WaitForEqual(ScrollViewerWidth, () => SUT.ActualWidth);

// Issue needs to be fixed first for WASM for Right and Bottom Margin missing
// Details here: https://github.com/unoplatform/uno/issues/7000
#if !__WASM__
Assert.AreEqual(ScrollViewerWidth, SUT.ExtentWidth);
#endif
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private static double GetHorizontalScrollWheelDelta(Size size, double delta)

internal Size? CustomContentExtent => null;

private object RealContent => Content;

partial void InitializePartial()
{
#if __SKIA__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,7 @@ public object ScrollOwner
}
#endregion

private ScrollViewer Scroller => ScrollOwner as ScrollViewer;

internal object ManagedContent
{
get
{
#if __ANDROID__ || __IOS__
if (Content is NativeScrollContentPresenter nativePresenter)
{
return nativePresenter.Content;
}
#endif

return Content;
}
}
private ScrollViewer Scroller => ScrollOwner as ScrollViewer;

#if __WASM__
bool _forceChangeToCurrentView;
Expand Down Expand Up @@ -116,9 +101,29 @@ bool ILayoutConstraints.IsHeightConstrained(View requester)
return this.IsHeightConstrainedSimple() ?? (Parent as ILayoutConstraints)?.IsHeightConstrained(this) ?? false;
}

public double ViewportHeight => (DesiredSize.Height - Margin.Top - Margin.Bottom);
public double ViewportHeight
{
get
{
#if !__WASM__
return DesiredSize.Height - Margin.Top - Margin.Bottom;
#else // Issue needs to be fixed first for WASM for Right and Bottom Margin missing https://github.com/unoplatform/uno/issues/7000
return DesiredSize.Height - Margin.Top;
#endif
}
}

public double ViewportWidth => (DesiredSize.Width - Margin.Left - Margin.Right);
public double ViewportWidth
{
get
{
#if !__WASM__
return DesiredSize.Width - Margin.Left - Margin.Right;
#else // Issue needs to be fixed first for WASM for Right and Bottom Margin missing https://github.com/unoplatform/uno/issues/7000
return DesiredSize.Width - Margin.Left;
#endif
}
}

#if UNO_HAS_MANAGED_SCROLL_PRESENTER || __WASM__
protected override Size MeasureOverride(Size availableSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void OnBringIntoViewRequested(BringIntoViewRequestedEventArgs
{
base.OnBringIntoViewRequested(args);

UIElement content = ManagedContent as UIElement;
UIElement content = RealContent as UIElement;

if (args.Handled ||
args.TargetElement == this ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ internal Size ScrollBarSize
}
}

private object RealContent => Content;

private void TryRegisterEvents(ScrollBarVisibility visibility)
{
if (
Expand Down

0 comments on commit 9a4e884

Please sign in to comment.