Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix(Swiper): Initial index doesn't work #2102

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading