Skip to content

Commit

Permalink
🐛 fix(Swiper): Initial index doesn't work (#2102)
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem authored Aug 15, 2024
1 parent 17b870a commit 813bed3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/Masa.Blazor/Components/Swiper/MSwiper.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,7 @@ protected override IEnumerable<string> BuildComponentStyle()
protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();

if (_prevIndex != Index)
{
_prevIndex = Index;

if (_swiperProxy is null)
{
return;
}

await _swiperProxy.SlideToAsync(Index, Speed);
}
await SliderToIndexAsync(Speed);
}

protected override async Task OnAfterRenderAsync(bool firstRender)
Expand Down Expand Up @@ -154,9 +143,23 @@ await RunTaskInMicrosecondsAsync(async () =>
};
_swiperProxy = await SwiperJsModule.Init(Ref, options, _swiperInteropHandle);
await SliderToIndexAsync(0);
}, 16, _ctsForInit.Token);
}

private async Task SliderToIndexAsync(int speed)
{
if (_swiperProxy is null || _prevIndex == Index)
{
return;
}

_prevIndex = Index;

await _swiperProxy.SlideToAsync(Index, speed);
}

internal async Task UpdateIndexAsync(int index)
{
Index = index;
Expand Down

0 comments on commit 813bed3

Please sign in to comment.