-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WinUI] ScrollView Resize + Window Handler Resize (#1676)
* WinUI-only ScrollBarHandler (#1671) * Re-measure scrollviewer on native arrange The scrollviewer seems to need to measure again when the handler is being native arranged. Simply calling .arrange on the native view didn't reset the size to the requested bounds, it needs to be told to resize first, otherwise it stays >= the content size. * Resize root panel content on window size changed This resizes the root panel's contents when the window size changes * Measure Page in RootPanel MeasureOverride * Remove defunct code from demos * Modify ScrollView to allow native measure in addition to content measure Co-authored-by: E.Z. Hart <hartez@users.noreply.github.com> Co-authored-by: E.Z. Hart <hartez@gmail.com>
- Loading branch information
1 parent
6fb0c7a
commit e0ebddc
Showing
20 changed files
with
414 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace Microsoft.Maui.Controls | ||
{ | ||
public partial class ScrollView : IScrollView | ||
{ | ||
IView IScrollView.Content => Content; | ||
|
||
double IScrollView.HorizontalOffset | ||
{ | ||
get => ScrollX; | ||
set | ||
{ | ||
if (ScrollX != value) | ||
{ | ||
SetScrolledPosition(value, ScrollY); | ||
} | ||
} | ||
} | ||
|
||
double IScrollView.VerticalOffset | ||
{ | ||
get => ScrollY; | ||
set | ||
{ | ||
if (ScrollY != value) | ||
{ | ||
SetScrolledPosition(ScrollX, value); | ||
} | ||
} | ||
} | ||
|
||
void IScrollView.ScrollFinished() => SendScrollFinished(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using Microsoft.Maui.Graphics; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public interface IScrollView : IView | ||
{ | ||
// TODO ezhart 2021-07-08 It might make sense for IPage and IScrollView to derive from (the not yet created) IContentView | ||
|
||
/// <summary> | ||
/// Gets the view that contains the content of the ScrollView. | ||
/// </summary> | ||
public IView Content { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating the visibility rules for the horizontal scroll bar. | ||
/// </summary> | ||
ScrollBarVisibility HorizontalScrollBarVisibility { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating the visibility rules for the vertical scroll bar. | ||
/// </summary> | ||
ScrollBarVisibility VerticalScrollBarVisibility { get; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating the scroll orientation of the ScrollView. | ||
/// </summary> | ||
ScrollOrientation Orientation { get; } | ||
|
||
/// <summary> | ||
/// Gets the size of the scrollable content in the ScrollView. | ||
/// </summary> | ||
Size ContentSize { get; } | ||
|
||
/// <summary> | ||
/// Gets the current scroll position of the ScrollView along the horizontal axis. | ||
/// </summary> | ||
double HorizontalOffset { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the current scroll position of the ScrollView along the vertical axis. | ||
/// </summary> | ||
double VerticalOffset { get; set; } | ||
|
||
/// <summary> | ||
/// Allows the native ScrollView to inform that cross-platform code that a scroll operation has completed. | ||
/// </summary> | ||
void ScrollFinished(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Android.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using AndroidX.Core.Widget; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class ScrollViewHandler : ViewHandler<IScrollView, NestedScrollView> | ||
{ | ||
protected override NestedScrollView CreateNativeView() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static void MapContent(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapHorizontalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapVerticalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapOrientation(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapContentSize(ScrollViewHandler handler, IScrollView scrollView) { } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Standard.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class ScrollViewHandler : ViewHandler<IScrollView, object> | ||
{ | ||
protected override object CreateNativeView() => throw new NotImplementedException(); | ||
|
||
public static void MapContent(IViewHandler handler, IScrollView scrollView) { } | ||
public static void MapHorizontalScrollBarVisibility(IViewHandler handler, IScrollView scrollView) { } | ||
public static void MapVerticalScrollBarVisibility(IViewHandler handler, IScrollView scrollView) { } | ||
public static void MapOrientation(IViewHandler handler, IScrollView scrollView) { } | ||
public static void MapContentSize(IViewHandler handler, IScrollView scrollView) { } | ||
public static void MapRequestScrollTo(ScrollViewHandler handler, IScrollView scrollView, object? args) { } | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/Core/src/Handlers/ScrollView/ScrollViewHandler.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#nullable enable | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using Microsoft.Maui.Graphics; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class ScrollViewHandler : ViewHandler<IScrollView, ScrollViewer> | ||
{ | ||
protected override ScrollViewer CreateNativeView() | ||
{ | ||
return new ScrollViewer(); | ||
} | ||
|
||
protected override void ConnectHandler(ScrollViewer nativeView) | ||
{ | ||
base.ConnectHandler(nativeView); | ||
nativeView.ViewChanged += ViewChanged; | ||
} | ||
|
||
protected override void DisconnectHandler(ScrollViewer nativeView) | ||
{ | ||
base.DisconnectHandler(nativeView); | ||
nativeView.ViewChanged -= ViewChanged; | ||
} | ||
|
||
public static void MapContent(ScrollViewHandler handler, IScrollView scrollView) | ||
{ | ||
if (handler.MauiContext == null) | ||
{ | ||
return; | ||
} | ||
|
||
handler.NativeView.Content = scrollView.Content.ToNative(handler.MauiContext); | ||
} | ||
|
||
public static void MapHorizontalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) | ||
{ | ||
handler.NativeView?.UpdateScrollBarVisibility(scrollView.Orientation, scrollView.HorizontalScrollBarVisibility); | ||
} | ||
|
||
public static void MapVerticalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) | ||
{ | ||
handler.NativeView.VerticalScrollBarVisibility = scrollView.VerticalScrollBarVisibility.ToWindowsScrollBarVisibility(); | ||
} | ||
|
||
public static void MapOrientation(ScrollViewHandler handler, IScrollView scrollView) | ||
{ | ||
handler.NativeView?.UpdateScrollBarVisibility(scrollView.Orientation, scrollView.HorizontalScrollBarVisibility); | ||
} | ||
|
||
void ViewChanged(object? sender, ScrollViewerViewChangedEventArgs e) | ||
{ | ||
VirtualView.VerticalOffset = NativeView.VerticalOffset; | ||
VirtualView.HorizontalOffset = NativeView.HorizontalOffset; | ||
|
||
if (e.IsIntermediate == false) | ||
{ | ||
VirtualView.ScrollFinished(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#nullable enable | ||
using System; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class ScrollViewHandler | ||
{ | ||
public static PropertyMapper<IScrollView, ScrollViewHandler> ScrollViewMapper = new(ViewMapper) | ||
{ | ||
[nameof(IScrollView.Content)] = MapContent, | ||
[nameof(IScrollView.HorizontalScrollBarVisibility)] = MapHorizontalScrollBarVisibility, | ||
[nameof(IScrollView.VerticalScrollBarVisibility)] = MapVerticalScrollBarVisibility, | ||
[nameof(IScrollView.Orientation)] = MapOrientation, | ||
}; | ||
|
||
public ScrollViewHandler() : base(ScrollViewMapper) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using UIKit; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class ScrollViewHandler : ViewHandler<IScrollView, UIScrollView> | ||
{ | ||
public ScrollViewHandler(PropertyMapper mapper) : base(mapper) | ||
{ | ||
} | ||
|
||
protected override UIScrollView CreateNativeView() | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public static void MapContent(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapHorizontalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapVerticalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapOrientation(ScrollViewHandler handler, IScrollView scrollView) { } | ||
public static void MapContentSize(ScrollViewHandler handler, IScrollView scrollView) { } | ||
} | ||
} |
Oops, something went wrong.