Skip to content

Commit

Permalink
Fix calendarFormat bug, improve scrolling animation
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksanderwozniak committed Apr 18, 2021
1 parent baeb497 commit 91130bb
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions lib/src/table_calendar_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ class _TableCalendarBaseState extends State<TableCalendarBase>
if (_focusedDay != widget.focusedDay ||
widget.calendarFormat != oldWidget.calendarFormat ||
widget.startingDayOfWeek != oldWidget.startingDayOfWeek) {
final shouldAnimate = _focusedDay != widget.focusedDay;

_focusedDay = widget.focusedDay;
_updatePage();
_updatePage(shouldAnimate: shouldAnimate);
}

if (widget.rowHeight != oldWidget.rowHeight ||
Expand All @@ -136,7 +138,7 @@ class _TableCalendarBaseState extends State<TableCalendarBase>
widget.availableGestures == AvailableGestures.all ||
widget.availableGestures == AvailableGestures.verticalSwipe;

void _updatePage() {
void _updatePage({bool shouldAnimate = false}) {
final currentIndex = _calculateFocusedPage(
widget.calendarFormat, widget.firstDay, _focusedDay);

Expand All @@ -149,17 +151,27 @@ class _TableCalendarBaseState extends State<TableCalendarBase>
_pageCallbackDisabled = true;
}

_previousIndex = currentIndex;
final rowCount = _getRowCount(widget.calendarFormat, _focusedDay);
_pageHeight.value = _getPageHeight(rowCount);
if (shouldAnimate && widget.animatedPageScrolling) {
if ((currentIndex - _previousIndex).abs() > 1) {
final jumpIndex =
currentIndex > _previousIndex ? currentIndex - 1 : currentIndex + 1;

_pageController.jumpToPage(jumpIndex);
}

if (widget.animatedPageScrolling) {
_pageController.animateToPage(currentIndex,
duration: widget.pageChangeAnimationDuration,
curve: widget.pageChangeAnimationCurve);
_pageController.animateToPage(
currentIndex,
duration: widget.pageChangeAnimationDuration,
curve: widget.pageChangeAnimationCurve,
);
} else {
_pageController.jumpToPage(currentIndex);
}

_previousIndex = currentIndex;
final rowCount = _getRowCount(widget.calendarFormat, _focusedDay);
_pageHeight.value = _getPageHeight(rowCount);

_pageCallbackDisabled = false;
}

Expand Down

0 comments on commit 91130bb

Please sign in to comment.