Skip to content

Commit

Permalink
refactor: improve tick animation logic (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahani-deriv authored May 28, 2024
1 parent 1955485 commit 43e24db
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/src/deriv_chart/chart/basic_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class BasicChartState<T extends BasicChart> extends State<T>
/// The xAxis model of the chart.
XAxisModel get xAxis => context.read<XAxisModel>();

bool _isTickAnimationPlaying = false;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -184,6 +186,9 @@ class BasicChartState<T extends BasicChart> extends State<T>

topBoundQuoteAnimationController.dispose();
bottomBoundQuoteAnimationController.dispose();

_isTickAnimationPlaying = false;

_clearGestures();
super.dispose();
}
Expand All @@ -208,9 +213,11 @@ class BasicChartState<T extends BasicChart> extends State<T>
}

void _playNewTickAnimation() {
_currentTickAnimationController
..reset()
..forward();
if (!_isTickAnimationPlaying) {
_currentTickAnimationController
..reset()
..forward();
}
}

YAxisModel _setupYAxisModel(Size canvasSize) => yAxisModel = YAxisModel(
Expand Down Expand Up @@ -238,6 +245,13 @@ class BasicChartState<T extends BasicChart> extends State<T>
parent: _currentTickAnimationController,
curve: Curves.easeOut,
);
_currentTickAnimationController.addListener(() {
if (_currentTickAnimationController.status != AnimationStatus.completed) {
_isTickAnimationPlaying = true;
} else {
_isTickAnimationPlaying = false;
}
});
}

void _setupBoundsAnimation() {
Expand Down

0 comments on commit 43e24db

Please sign in to comment.