-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from Blazored/progress-bar
Added ability to display progress bar on toasts
- Loading branch information
Showing
8 changed files
with
142 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Timers; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Blazored.Toast | ||
{ | ||
internal class CountdownTimer : IDisposable | ||
{ | ||
private Timer _timer; | ||
private int _timeout; | ||
private int _countdownTotal; | ||
private int _percentComplete; | ||
|
||
internal Action<int> OnTick; | ||
internal Action OnElapsed; | ||
|
||
internal CountdownTimer(int timeout) | ||
{ | ||
_countdownTotal = timeout; | ||
_timeout = (_countdownTotal * 1000) / 100; | ||
_percentComplete = 0; | ||
SetupTimer(); | ||
} | ||
|
||
internal void Start() | ||
{ | ||
_timer.Start(); | ||
} | ||
|
||
private void SetupTimer() | ||
{ | ||
_timer = new Timer(_timeout); | ||
_timer.Elapsed += HandleTick; | ||
_timer.AutoReset = false; | ||
} | ||
|
||
private void HandleTick(object sender, ElapsedEventArgs args) | ||
{ | ||
_percentComplete++; | ||
OnTick?.Invoke(_percentComplete); | ||
|
||
if (_percentComplete == 100) | ||
{ | ||
OnElapsed?.Invoke(); | ||
} | ||
else | ||
{ | ||
SetupTimer(); | ||
Start(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_timer.Dispose(); | ||
_timer = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters