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

Add pageSnapping option for customizing horizontal scroll #721

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions lib/src/table_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class TableCalendar<T> extends StatefulWidget {
/// if the currently visible calendar page is changed.
final bool pageAnimationEnabled;

/// Set to false to disable horizontal page snapping, useful for custom scroll behavior.
final bool pageSnapping;

/// When set to true, `CalendarFormat.month` will always display six weeks,
/// even if the content would fit in less.
final bool sixWeekMonthsEnforced;
Expand Down Expand Up @@ -225,6 +228,7 @@ class TableCalendar<T> extends StatefulWidget {
this.daysOfWeekVisible = true,
this.pageJumpingEnabled = false,
this.pageAnimationEnabled = true,
this.pageSnapping = true,
this.sixWeekMonthsEnforced = false,
this.shouldFillViewport = false,
this.weekNumbersVisible = false,
Expand Down Expand Up @@ -502,6 +506,7 @@ class _TableCalendarState<T> extends State<TableCalendar<T>> {
pageAnimationCurve: widget.pageAnimationCurve,
availableCalendarFormats: widget.availableCalendarFormats,
simpleSwipeConfig: widget.simpleSwipeConfig,
pageSnapping: widget.pageSnapping,
sixWeekMonthsEnforced: widget.sixWeekMonthsEnforced,
onVerticalSwipe: _swipeCalendarFormat,
onPageChanged: (focusedDay) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/table_calendar_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TableCalendarBase extends StatefulWidget {
final TableBorder? tableBorder;
final Duration formatAnimationDuration;
final Curve formatAnimationCurve;
final bool pageSnapping;
final bool pageAnimationEnabled;
final Duration pageAnimationDuration;
final Curve pageAnimationCurve;
Expand Down Expand Up @@ -55,6 +56,7 @@ class TableCalendarBase extends StatefulWidget {
this.tableBorder,
this.formatAnimationDuration = const Duration(milliseconds: 200),
this.formatAnimationCurve = Curves.linear,
this.pageSnapping = true,
this.pageAnimationEnabled = true,
this.pageAnimationDuration = const Duration(milliseconds: 300),
this.pageAnimationCurve = Curves.easeOut,
Expand Down Expand Up @@ -209,6 +211,7 @@ class _TableCalendarBaseState extends State<TableCalendarBase> {
scrollPhysics: _canScrollHorizontally
? PageScrollPhysics()
: NeverScrollableScrollPhysics(),
pageSnapping: widget.pageSnapping,
firstDay: widget.firstDay,
lastDay: widget.lastDay,
startingDayOfWeek: widget.startingDayOfWeek,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/widgets/calendar_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CalendarCore extends StatelessWidget {
final PageController? pageController;
final ScrollPhysics? scrollPhysics;
final _OnCalendarPageChanged onPageChanged;
final bool pageSnapping;

const CalendarCore({
Key? key,
Expand All @@ -55,6 +56,7 @@ class CalendarCore extends StatelessWidget {
this.rowDecoration,
this.tableBorder,
this.scrollPhysics,
this.pageSnapping = true,
}) : assert(!dowVisible || (dowHeight != null && dowBuilder != null)),
super(key: key);

Expand All @@ -63,6 +65,7 @@ class CalendarCore extends StatelessWidget {
return PageView.builder(
controller: pageController,
physics: scrollPhysics,
pageSnapping: pageSnapping,
itemCount: _getPageCount(calendarFormat, firstDay, lastDay),
itemBuilder: (context, index) {
final baseDay = _getBaseDay(calendarFormat, index);
Expand Down