Skip to content

Commit

Permalink
🚧 feat: wip (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem authored Apr 27, 2023
1 parent 9914047 commit fc7dcb8
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public BSlideGroup(GroupType groupType) : base(groupType)
private int _prevItemsLength;
private StringNumber? _prevInternalValue;
private bool _prevIsOverflowing;
private CancellationTokenSource? _cts;

protected bool IsMobile { get; set; }

Expand Down Expand Up @@ -97,7 +98,6 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
DomEventJsInterop?.ResizeObserver(Ref.GetSelector(), OnResize);

IsMobile = await JsInvokeAsync<bool>(JsInteropConstants.IsMobile);
await SetWidths(Value);
}
else if (_prevItemsLength != Items.Count)
Expand All @@ -122,6 +122,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

public async Task SetWidths(StringNumber? selectedValue = null)
{
_cts?.Cancel();
_cts = new CancellationTokenSource();
await Task.Delay(16, _cts.Token);

(WrapperWidth, ContentWidth) = await GetWidths();

// The first time IsOverflowing is true, WrapperWidth will become smaller
Expand All @@ -148,7 +152,7 @@ public bool HasAffixes
{
var hasAffixes = !IsMobile && (IsOverflowing || Math.Abs(ScrollOffset) > 0);

if (ShowArrows == null) return hasAffixes;
if (ShowArrows is null) return hasAffixes;

return ShowArrows.Match(
str =>
Expand Down Expand Up @@ -279,7 +283,7 @@ protected static double CalculateNewOffset(string direction, double wrapperWidth
return sign * Math.Max(Math.Min(newAbsoluteOffset, contentWidth - wrapperWidth), 0);
}

private async Task OnResize()
protected async Task OnResize()
{
if (IsDisposed)
{
Expand Down

0 comments on commit fc7dcb8

Please sign in to comment.