diff --git a/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs b/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs index 595d348..84e4f2c 100644 --- a/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs +++ b/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs @@ -232,6 +232,16 @@ void UpdateEmptyView() } } + void UpdateVerticalScrollbarVisibility(ScrollBarVisibility scrollBarVisibility) + { + PlatformView.ShowsVerticalScrollIndicator = scrollBarVisibility == ScrollBarVisibility.Always || scrollBarVisibility == ScrollBarVisibility.Default; + } + + void UpdateHorizontalScrollbarVisibility(ScrollBarVisibility scrollBarVisibility) + { + PlatformView.ShowsHorizontalScrollIndicator = scrollBarVisibility == ScrollBarVisibility.Always || scrollBarVisibility == ScrollBarVisibility.Default; + } + public void InvalidateData() { this.PlatformView.InvokeOnMainThread(() => { diff --git a/VirtualListView/Controls/VirtualListView.cs b/VirtualListView/Controls/VirtualListView.cs index 4eb3371..a6d0d73 100644 --- a/VirtualListView/Controls/VirtualListView.cs +++ b/VirtualListView/Controls/VirtualListView.cs @@ -77,7 +77,25 @@ public VirtualListViewItemTemplateSelector ItemTemplateSelector public static readonly BindableProperty ItemTemplateSelectorProperty = BindableProperty.Create(nameof(ItemTemplateSelector), typeof(VirtualListViewItemTemplateSelector), typeof(VirtualListView), default); + + public ScrollBarVisibility VerticalScrollbarVisibility + { + get => (ScrollBarVisibility)GetValue(VerticalScrollbarVisibilityProperty); + set => SetValue(VerticalScrollbarVisibilityProperty, value); + } + + public static readonly BindableProperty VerticalScrollbarVisibilityProperty = + BindableProperty.Create(nameof(VerticalScrollbarVisibility), typeof(ScrollBarVisibility), typeof(VirtualListView), ScrollBarVisibility.Default); + + + public ScrollBarVisibility HorizontalScrollbarVisibility + { + get => (ScrollBarVisibility)GetValue(HorizontalScrollbarVisibilityProperty); + set => SetValue(HorizontalScrollbarVisibilityProperty, value); + } + public static readonly BindableProperty HorizontalScrollbarVisibilityProperty = + BindableProperty.Create(nameof(HorizontalScrollbarVisibility), typeof(ScrollBarVisibility), typeof(VirtualListView), ScrollBarVisibility.Default); public DataTemplate SectionHeaderTemplate { diff --git a/VirtualListView/IVirtualListView.cs b/VirtualListView/IVirtualListView.cs index 0c80ea9..eea3308 100644 --- a/VirtualListView/IVirtualListView.cs +++ b/VirtualListView/IVirtualListView.cs @@ -25,6 +25,10 @@ public interface IVirtualListView : IView IList SelectedItems { get; set; } ItemPosition? SelectedItem { get; set; } + + ScrollBarVisibility VerticalScrollbarVisibility { get; set; } + + ScrollBarVisibility HorizontalScrollbarVisibility { get; set; } event EventHandler OnSelectedItemsChanged; diff --git a/VirtualListView/Platforms/Android/VirtualListViewHandler.android.cs b/VirtualListView/Platforms/Android/VirtualListViewHandler.android.cs index c40f6fc..4f4e8cc 100644 --- a/VirtualListView/Platforms/Android/VirtualListViewHandler.android.cs +++ b/VirtualListView/Platforms/Android/VirtualListViewHandler.android.cs @@ -164,4 +164,35 @@ void UpdateEmptyView() UpdateEmptyViewVisibility(); } } + + ScrollBarVisibility _defaultHorizontalScrollVisibility = ScrollBarVisibility.Default; + ScrollBarVisibility _defaultVerticalScrollVisibility = ScrollBarVisibility.Default; + + void UpdateVerticalScrollbarVisibility(ScrollBarVisibility scrollBarVisibility) + { + if (_defaultVerticalScrollVisibility == ScrollBarVisibility.Default) + _defaultVerticalScrollVisibility = + recyclerView.VerticalScrollBarEnabled ? ScrollBarVisibility.Always : ScrollBarVisibility.Never; + + var newVerticalScrollVisiblility = scrollBarVisibility; + + if (newVerticalScrollVisiblility == ScrollBarVisibility.Default) + newVerticalScrollVisiblility = _defaultVerticalScrollVisibility; + + recyclerView.VerticalScrollBarEnabled = newVerticalScrollVisiblility == ScrollBarVisibility.Always; + } + + void UpdateHorizontalScrollbarVisibility(ScrollBarVisibility scrollBarVisibility) + { + if (_defaultHorizontalScrollVisibility == ScrollBarVisibility.Default) + _defaultHorizontalScrollVisibility = + recyclerView.HorizontalScrollBarEnabled ? ScrollBarVisibility.Always : ScrollBarVisibility.Never; + + var newHorizontalScrollVisiblility = scrollBarVisibility; + + if (newHorizontalScrollVisiblility == ScrollBarVisibility.Default) + newHorizontalScrollVisiblility = _defaultHorizontalScrollVisibility; + + recyclerView.HorizontalScrollBarEnabled = newHorizontalScrollVisiblility == ScrollBarVisibility.Always; + } } \ No newline at end of file diff --git a/VirtualListView/Platforms/Windows/VirtualListViewHandler.windows.cs b/VirtualListView/Platforms/Windows/VirtualListViewHandler.windows.cs index c6ccb7d..9c0d766 100644 --- a/VirtualListView/Platforms/Windows/VirtualListViewHandler.windows.cs +++ b/VirtualListView/Platforms/Windows/VirtualListViewHandler.windows.cs @@ -4,6 +4,7 @@ using WGrid = Microsoft.UI.Xaml.Controls.Grid; using WVisibility = Microsoft.UI.Xaml.Visibility; using WFrameworkElement = Microsoft.UI.Xaml.FrameworkElement; +using WScrollBarVisibility = Microsoft.UI.Xaml.Controls.ScrollBarVisibility; using Microsoft.Maui.Platform; using Microsoft.UI.Xaml; @@ -164,4 +165,26 @@ void UpdateEmptyView() UpdateEmptyViewVisibility(); } + + void UpdateVerticalScrollbarVisibility(ScrollBarVisibility scrollBarVisibility) + { + scrollViewer.VerticalScrollBarVisibility = scrollBarVisibility switch + { + ScrollBarVisibility.Default => WScrollBarVisibility.Auto, + ScrollBarVisibility.Always => WScrollBarVisibility.Visible, + ScrollBarVisibility.Never => WScrollBarVisibility.Hidden, + _ => WScrollBarVisibility.Auto + }; + } + + void UpdateHorizontalScrollbarVisibility(ScrollBarVisibility scrollBarVisibility) + { + scrollViewer.HorizontalScrollBarVisibility = scrollBarVisibility switch + { + ScrollBarVisibility.Default => WScrollBarVisibility.Auto, + ScrollBarVisibility.Always => WScrollBarVisibility.Visible, + ScrollBarVisibility.Never => WScrollBarVisibility.Hidden, + _ => WScrollBarVisibility.Auto + }; + } } diff --git a/VirtualListView/VirtualListViewHandler.cs b/VirtualListView/VirtualListViewHandler.cs index 2e73958..06dd620 100644 --- a/VirtualListView/VirtualListViewHandler.cs +++ b/VirtualListView/VirtualListViewHandler.cs @@ -18,6 +18,8 @@ public partial class VirtualListViewHandler [nameof(IVirtualListView.IsRefreshEnabled)] = MapIsRefreshEnabled, [nameof(IVirtualListView.EmptyView)] = MapEmptyView, [nameof(IVirtualListView.SelectedItems)] = MapSelectedItems, + [nameof(IVirtualListView.VerticalScrollbarVisibility)] = MapVerticalScrollbarVisibility, + [nameof(IVirtualListView.HorizontalScrollbarVisibility)] = MapHorizontalScrollbarVisibility, }; public static CommandMapper CommandMapper = new(ViewCommandMapper) @@ -135,5 +137,15 @@ public static void MapIsFooterVisible(VirtualListViewHandler handler, IVirtualLi { handler?.InvalidateData(); } + + public static void MapVerticalScrollbarVisibility(VirtualListViewHandler handler, IVirtualListView virtualListView) + { + handler?.UpdateVerticalScrollbarVisibility(virtualListView.VerticalScrollbarVisibility); + } + + public static void MapHorizontalScrollbarVisibility(VirtualListViewHandler handler, IVirtualListView virtualListView) + { + handler?.UpdateHorizontalScrollbarVisibility(virtualListView.HorizontalScrollbarVisibility); + } } \ No newline at end of file