Skip to content

Commit

Permalink
Merge pull request #416 from chanan/FixFor415
Browse files Browse the repository at this point in the history
Fixes Issue 415
  • Loading branch information
jbomhold3 authored Dec 2, 2020
2 parents dfd2afe + 24005b8 commit 930f45c
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/BlazorStrap/Components/Carousel/BSCarousel.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public int ActiveIndex
set { _activeIndex = value; ActiveIndexChanged?.Invoke(); DoAnimations(); }
}

private bool _timerEnabled { get; set; } = true;
public bool AnimationRunning { get; set; } = false;
public List<BSCarouselIndicatorItemBase> CarouselIndicatorItems { get; } = new List<BSCarouselIndicatorItemBase>();
public List<BSCarouselItemBase> CarouselItems { get; } = new List<BSCarouselItemBase>();
Expand Down Expand Up @@ -105,32 +106,39 @@ public async Task Refresh()

public void ResetTimer()
{
Timer.Stop();
if (Interval == 0)
return;
if (Timer != null)
Timer.Stop();

Timer.Interval = CarouselItems[ActiveIndex].Interval;
Timer.Start();
if (_timerEnabled)
{
Timer.Interval = CarouselItems[ActiveIndex].Interval;
Timer.Start();
}
}

protected override void OnInitialized()
{
if (Timer == null)
if (Interval == 0)
_timerEnabled = false;

if (Timer == null && _timerEnabled)
{
Timer = new Timer(Interval);
Timer.Elapsed += OnTimerEvent;
Timer.AutoReset = true;
if (Interval == 0)
return;
Timer.Start();
}
}

private async Task DoAnimations()
{
if (CarouselItems.Count == 0) return;
Timer.Stop();
Timer.Interval = CarouselItems[ActiveIndex].Interval;

if (_timerEnabled)
{
Timer.Stop();
Timer.Interval = CarouselItems[ActiveIndex].Interval;
}
if (Direction == 0)
{
var oldindex = ActiveIndex == 0 ? NumberOfItems - 1 : ActiveIndex - 1;
Expand Down Expand Up @@ -181,7 +189,9 @@ public async Task AnimationEnd(BSCarouselItemBase sender)
await CarouselItems[ActiveIndex].Clean().ConfigureAwait(false);
CarouselItems[ActiveIndex].Active = true;
await InvokeAsync(StateHasChanged).ConfigureAwait(false);
Timer.Start();

if (_timerEnabled)
Timer.Start();
}
}
protected async Task OnKeyPress(KeyboardEventArgs e)
Expand Down Expand Up @@ -215,11 +225,13 @@ protected void OnMouseLeave()

protected override void OnParametersSet()
{
if (Interval != 0)
_timerEnabled = true;

if (Ride && ActiveIndex == 0)
{
if (Interval == 0)
return;
Timer.Start();
if (_timerEnabled)
Timer.Start();
}
}

Expand Down

0 comments on commit 930f45c

Please sign in to comment.