Skip to content

Commit

Permalink
Add iOS/Android support for scrollbar visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Apr 20, 2024
1 parent 245a2d6 commit 64dce34
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
10 changes: 10 additions & 0 deletions VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
18 changes: 18 additions & 0 deletions VirtualListView/Controls/VirtualListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions VirtualListView/IVirtualListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public interface IVirtualListView : IView
IList<ItemPosition> SelectedItems { get; set; }

ItemPosition? SelectedItem { get; set; }

ScrollBarVisibility VerticalScrollbarVisibility { get; set; }

ScrollBarVisibility HorizontalScrollbarVisibility { get; set; }

event EventHandler<SelectedItemsChangedEventArgs> OnSelectedItemsChanged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 12 additions & 0 deletions VirtualListView/VirtualListViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IVirtualListView, VirtualListViewHandler> CommandMapper = new(ViewCommandMapper)
Expand Down Expand Up @@ -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);

Check failure on line 143 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateVerticalScrollbarVisibility' and no accessible extension method 'UpdateVerticalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 143 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateVerticalScrollbarVisibility' and no accessible extension method 'UpdateVerticalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 143 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateVerticalScrollbarVisibility' and no accessible extension method 'UpdateVerticalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 143 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateVerticalScrollbarVisibility' and no accessible extension method 'UpdateVerticalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)
}

public static void MapHorizontalScrollbarVisibility(VirtualListViewHandler handler, IVirtualListView virtualListView)
{
handler?.UpdateHorizontalScrollbarVisibility(virtualListView.HorizontalScrollbarVisibility);

Check failure on line 148 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateHorizontalScrollbarVisibility' and no accessible extension method 'UpdateHorizontalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 148 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateHorizontalScrollbarVisibility' and no accessible extension method 'UpdateHorizontalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 148 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateHorizontalScrollbarVisibility' and no accessible extension method 'UpdateHorizontalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 148 in VirtualListView/VirtualListViewHandler.cs

View workflow job for this annotation

GitHub Actions / Build

'VirtualListViewHandler' does not contain a definition for 'UpdateHorizontalScrollbarVisibility' and no accessible extension method 'UpdateHorizontalScrollbarVisibility' accepting a first argument of type 'VirtualListViewHandler' could be found (are you missing a using directive or an assembly reference?)
}

}

0 comments on commit 64dce34

Please sign in to comment.