diff --git a/library/api/library.api b/library/api/library.api index 6a9ca08..d016993 100644 --- a/library/api/library.api +++ b/library/api/library.api @@ -6,9 +6,9 @@ public final class com/boguszpawlowski/composecalendar/BuildConfig { } public final class io/github/boguszpawlowski/composecalendar/CalendarKt { - public static final fun Calendar (Lio/github/boguszpawlowski/composecalendar/CalendarState;Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZZLkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V - public static final fun SelectableCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZZLio/github/boguszpawlowski/composecalendar/CalendarState;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V - public static final fun StaticCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZZLio/github/boguszpawlowski/composecalendar/CalendarState;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V + public static final fun Calendar (Lio/github/boguszpawlowski/composecalendar/CalendarState;Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZZZLkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V + public static final fun SelectableCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZZZLio/github/boguszpawlowski/composecalendar/CalendarState;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V + public static final fun StaticCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZZZLio/github/boguszpawlowski/composecalendar/CalendarState;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V public static final fun rememberCalendarState (Ljava/time/YearMonth;Lio/github/boguszpawlowski/composecalendar/header/MonthState;Landroidx/compose/runtime/Composer;II)Lio/github/boguszpawlowski/composecalendar/CalendarState; public static final fun rememberSelectableCalendarState (Ljava/time/YearMonth;Ljava/util/List;Lio/github/boguszpawlowski/composecalendar/selection/SelectionMode;Lkotlin/jvm/functions/Function1;Lio/github/boguszpawlowski/composecalendar/header/MonthState;Lio/github/boguszpawlowski/composecalendar/selection/DynamicSelectionState;Landroidx/compose/runtime/Composer;II)Lio/github/boguszpawlowski/composecalendar/CalendarState; } @@ -73,9 +73,9 @@ public final class io/github/boguszpawlowski/composecalendar/ComposableSingleton } public final class io/github/boguszpawlowski/composecalendar/WeekCalendarKt { - public static final fun SelectableWeekCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZLio/github/boguszpawlowski/composecalendar/WeekCalendarState;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V - public static final fun StaticWeekCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZLio/github/boguszpawlowski/composecalendar/WeekCalendarState;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V - public static final fun WeekCalendar (Lio/github/boguszpawlowski/composecalendar/WeekCalendarState;Landroidx/compose/ui/Modifier;Ljava/time/LocalDate;Ljava/time/DayOfWeek;ZLkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V + public static final fun SelectableWeekCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZZLio/github/boguszpawlowski/composecalendar/WeekCalendarState;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V + public static final fun StaticWeekCalendar (Landroidx/compose/ui/Modifier;Ljava/time/DayOfWeek;Ljava/time/LocalDate;ZLio/github/boguszpawlowski/composecalendar/WeekCalendarState;ZLkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V + public static final fun WeekCalendar (Lio/github/boguszpawlowski/composecalendar/WeekCalendarState;Landroidx/compose/ui/Modifier;Ljava/time/LocalDate;Ljava/time/DayOfWeek;ZZLkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V public static final fun rememberSelectableWeekCalendarState (Ljava/time/DayOfWeek;Lio/github/boguszpawlowski/composecalendar/week/Week;Ljava/util/List;Lio/github/boguszpawlowski/composecalendar/selection/SelectionMode;Lkotlin/jvm/functions/Function1;Lio/github/boguszpawlowski/composecalendar/header/WeekState;Lio/github/boguszpawlowski/composecalendar/selection/DynamicSelectionState;Landroidx/compose/runtime/Composer;II)Lio/github/boguszpawlowski/composecalendar/WeekCalendarState; public static final fun rememberWeekCalendarState (Ljava/time/DayOfWeek;Lio/github/boguszpawlowski/composecalendar/week/Week;Lio/github/boguszpawlowski/composecalendar/header/WeekState;Landroidx/compose/runtime/Composer;II)Lio/github/boguszpawlowski/composecalendar/WeekCalendarState; } diff --git a/library/src/main/java/io/github/boguszpawlowski/composecalendar/Calendar.kt b/library/src/main/java/io/github/boguszpawlowski/composecalendar/Calendar.kt index 04367b3..63bf316 100644 --- a/library/src/main/java/io/github/boguszpawlowski/composecalendar/Calendar.kt +++ b/library/src/main/java/io/github/boguszpawlowski/composecalendar/Calendar.kt @@ -60,6 +60,7 @@ public class CalendarState( * @param today current day, defaults to [LocalDate.now] * @param showAdjacentMonths whenever to show or hide the days from adjacent months * @param horizontalSwipeEnabled whenever user is able to change the month by horizontal swipe + * @param weekDaysScrollEnabled if the week days should be scrollable * @param calendarState state of the composable * @param dayContent composable rendering the current day * @param monthHeader header for showing the current month and controls for changing it @@ -73,6 +74,7 @@ public fun SelectableCalendar( today: LocalDate = LocalDate.now(), showAdjacentMonths: Boolean = true, horizontalSwipeEnabled: Boolean = true, + weekDaysScrollEnabled: Boolean = true, calendarState: CalendarState = rememberSelectableCalendarState(), dayContent: @Composable BoxScope.(DayState) -> Unit = { DefaultDay(it) }, monthHeader: @Composable ColumnScope.(MonthState) -> Unit = { DefaultMonthHeader(it) }, @@ -87,6 +89,7 @@ public fun SelectableCalendar( today = today, showAdjacentMonths = showAdjacentMonths, horizontalSwipeEnabled = horizontalSwipeEnabled, + weekDaysScrollEnabled = weekDaysScrollEnabled, calendarState = calendarState, dayContent = dayContent, monthHeader = monthHeader, @@ -111,6 +114,7 @@ public fun SelectableCalendar( * @param today current day, defaults to [LocalDate.now] * @param showAdjacentMonths whenever to show or hide the days from adjacent months * @param horizontalSwipeEnabled whenever user is able to change the month by horizontal swipe + * @param weekDaysScrollEnabled if the week days should be scrollable * @param calendarState state of the composable * @param dayContent composable rendering the current day * @param monthHeader header for showing the current month and controls for changing it @@ -124,6 +128,7 @@ public fun StaticCalendar( today: LocalDate = LocalDate.now(), showAdjacentMonths: Boolean = true, horizontalSwipeEnabled: Boolean = true, + weekDaysScrollEnabled: Boolean = true, calendarState: CalendarState = rememberCalendarState(), dayContent: @Composable BoxScope.(DayState) -> Unit = { DefaultDay(it) }, monthHeader: @Composable ColumnScope.(MonthState) -> Unit = { DefaultMonthHeader(it) }, @@ -138,6 +143,7 @@ public fun StaticCalendar( today = today, showAdjacentMonths = showAdjacentMonths, horizontalSwipeEnabled = horizontalSwipeEnabled, + weekDaysScrollEnabled = weekDaysScrollEnabled, calendarState = calendarState, dayContent = dayContent, monthHeader = monthHeader, @@ -171,6 +177,7 @@ public fun Calendar( today: LocalDate = LocalDate.now(), showAdjacentMonths: Boolean = true, horizontalSwipeEnabled: Boolean = true, + weekDaysScrollEnabled: Boolean = true, dayContent: @Composable BoxScope.(DayState) -> Unit = { DefaultDay(it) }, monthHeader: @Composable ColumnScope.(MonthState) -> Unit = { DefaultMonthHeader(it) }, daysOfWeekHeader: @Composable BoxScope.(List) -> Unit = { DefaultDaysOfWeekHeader(it) }, @@ -194,6 +201,7 @@ public fun Calendar( monthState = calendarState.monthState, selectionState = calendarState.selectionState, today = today, + weekDaysScrollEnabled = weekDaysScrollEnabled, daysOfWeek = daysOfWeek, dayContent = dayContent, weekHeader = daysOfWeekHeader, @@ -206,6 +214,7 @@ public fun Calendar( showAdjacentMonths = showAdjacentMonths, selectionState = calendarState.selectionState, today = today, + weekDaysScrollEnabled = weekDaysScrollEnabled, daysOfWeek = daysOfWeek, dayContent = dayContent, weekHeader = daysOfWeekHeader, diff --git a/library/src/main/java/io/github/boguszpawlowski/composecalendar/WeekCalendar.kt b/library/src/main/java/io/github/boguszpawlowski/composecalendar/WeekCalendar.kt index fb0a3fe..57c9d6e 100644 --- a/library/src/main/java/io/github/boguszpawlowski/composecalendar/WeekCalendar.kt +++ b/library/src/main/java/io/github/boguszpawlowski/composecalendar/WeekCalendar.kt @@ -57,6 +57,7 @@ public class WeekCalendarState( * @param firstDayOfWeek first day of a week, defaults to current locale's * @param today current day, defaults to [LocalDate.now] * @param horizontalSwipeEnabled whenever user is able to change the week by horizontal swipe + * @param weekDaysScrollEnabled if the week days should be scrollable * @param calendarState state of the composable * @param dayContent composable rendering the current day * @param weekHeader header for showing the current week and controls for changing it @@ -68,6 +69,7 @@ public fun SelectableWeekCalendar( firstDayOfWeek: DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek, today: LocalDate = LocalDate.now(), horizontalSwipeEnabled: Boolean = true, + weekDaysScrollEnabled: Boolean = true, calendarState: WeekCalendarState = rememberSelectableWeekCalendarState(), dayContent: @Composable BoxScope.(DayState) -> Unit = { DefaultDay(it) }, weekHeader: @Composable ColumnScope.(WeekState) -> Unit = { @@ -81,6 +83,7 @@ public fun SelectableWeekCalendar( today = today, horizontalSwipeEnabled = horizontalSwipeEnabled, firstDayOfWeek = firstDayOfWeek, + weekDaysScrollEnabled = weekDaysScrollEnabled, dayContent = dayContent, weekHeader = weekHeader, daysOfWeekHeader = daysOfWeekHeader, @@ -114,6 +117,7 @@ public fun StaticWeekCalendar( today: LocalDate = LocalDate.now(), horizontalSwipeEnabled: Boolean = true, calendarState: WeekCalendarState = rememberWeekCalendarState(), + weekDaysScrollEnabled: Boolean = true, dayContent: @Composable BoxScope.(DayState) -> Unit = { DefaultDay(it) }, weekHeader: @Composable ColumnScope.(WeekState) -> Unit = { DefaultProperWeekHeader(it) @@ -126,6 +130,7 @@ public fun StaticWeekCalendar( today = today, horizontalSwipeEnabled = horizontalSwipeEnabled, firstDayOfWeek = firstDayOfWeek, + weekDaysScrollEnabled = weekDaysScrollEnabled, dayContent = dayContent, weekHeader = weekHeader, daysOfWeekHeader = daysOfWeekHeader, @@ -154,6 +159,7 @@ public fun WeekCalendar( today: LocalDate = LocalDate.now(), firstDayOfWeek: DayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek, horizontalSwipeEnabled: Boolean = true, + weekDaysScrollEnabled: Boolean = true, dayContent: @Composable BoxScope.(DayState) -> Unit = { DefaultDay(it) }, weekHeader: @Composable ColumnScope.(WeekState) -> Unit = { DefaultProperWeekHeader(it) @@ -176,6 +182,7 @@ public fun WeekCalendar( weekState = calendarState.weekState, selectionState = calendarState.selectionState, today = today, + weekDaysScrollEnabled = weekDaysScrollEnabled, dayContent = dayContent, daysOfWeekHeader = daysOfWeekHeader, ) @@ -184,6 +191,7 @@ public fun WeekCalendar( daysOfWeek = daysOfWeek, weekDays = calendarState.weekState.currentWeek.getWeekDays(today), selectionState = calendarState.selectionState, + weekDaysScrollEnabled = weekDaysScrollEnabled, dayContent = dayContent, daysOfWeekHeader = daysOfWeekHeader, ) diff --git a/library/src/main/java/io/github/boguszpawlowski/composecalendar/month/MonthContent.kt b/library/src/main/java/io/github/boguszpawlowski/composecalendar/month/MonthContent.kt index 47cc6e3..f2dc8dc 100644 --- a/library/src/main/java/io/github/boguszpawlowski/composecalendar/month/MonthContent.kt +++ b/library/src/main/java/io/github/boguszpawlowski/composecalendar/month/MonthContent.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyRow @@ -40,6 +41,7 @@ internal fun MonthPager( daysOfWeek: List, today: LocalDate, modifier: Modifier = Modifier, + weekDaysScrollEnabled: Boolean = true, dayContent: @Composable BoxScope.(DayState) -> Unit, weekHeader: @Composable BoxScope.(List) -> Unit, monthContainer: @Composable (content: @Composable (PaddingValues) -> Unit) -> Unit, @@ -66,25 +68,36 @@ internal fun MonthPager( ) } - LazyRow( - modifier = modifier.testTag("MonthPager"), - state = listState, - flingBehavior = flingBehavior, - verticalAlignment = Alignment.Top, - ) { - items(PagerItemCount) { index -> - MonthContent( - modifier = Modifier.fillParentMaxWidth(), - showAdjacentMonths = showAdjacentMonths, - selectionState = selectionState, - currentMonth = monthListState.getMonthForPage(index), - today = today, - daysOfWeek = daysOfWeek, - dayContent = dayContent, - weekHeader = weekHeader, - monthContainer = monthContainer + Column(modifier = Modifier.fillMaxWidth()) { + if (weekDaysScrollEnabled.not()) { + Box( + modifier = Modifier + .wrapContentHeight() + .fillMaxWidth(), + content = { weekHeader(daysOfWeek) }, ) } + LazyRow( + modifier = modifier.testTag("MonthPager"), + state = listState, + flingBehavior = flingBehavior, + verticalAlignment = Alignment.Top, + ) { + items(PagerItemCount) { index -> + MonthContent( + modifier = Modifier.fillParentMaxWidth(), + showAdjacentMonths = showAdjacentMonths, + selectionState = selectionState, + currentMonth = monthListState.getMonthForPage(index), + today = today, + weekDaysScrollEnabled = weekDaysScrollEnabled, + daysOfWeek = daysOfWeek, + dayContent = dayContent, + weekHeader = weekHeader, + monthContainer = monthContainer + ) + } + } } } @@ -96,17 +109,19 @@ internal fun MonthContent( daysOfWeek: List, today: LocalDate, modifier: Modifier = Modifier, + weekDaysScrollEnabled: Boolean = true, dayContent: @Composable BoxScope.(DayState) -> Unit, weekHeader: @Composable BoxScope.(List) -> Unit, monthContainer: @Composable (content: @Composable (PaddingValues) -> Unit) -> Unit, ) { Column { - Box( - modifier = modifier - .wrapContentHeight(), - content = { weekHeader(daysOfWeek) }, - ) - + if (weekDaysScrollEnabled) { + Box( + modifier = modifier + .wrapContentHeight(), + content = { weekHeader(daysOfWeek) }, + ) + } monthContainer { paddingValues -> Column( modifier = modifier diff --git a/library/src/main/java/io/github/boguszpawlowski/composecalendar/week/WeekPager.kt b/library/src/main/java/io/github/boguszpawlowski/composecalendar/week/WeekPager.kt index 32a3d27..fe75ee5 100644 --- a/library/src/main/java/io/github/boguszpawlowski/composecalendar/week/WeekPager.kt +++ b/library/src/main/java/io/github/boguszpawlowski/composecalendar/week/WeekPager.kt @@ -38,6 +38,7 @@ internal fun WeekPager( daysOfWeek: List, today: LocalDate, modifier: Modifier = Modifier, + weekDaysScrollEnabled: Boolean = true, dayContent: @Composable BoxScope.(DayState) -> Unit, daysOfWeekHeader: @Composable BoxScope.(List) -> Unit, ) { @@ -62,23 +63,35 @@ internal fun WeekPager( listState = listState, ) } - - LazyRow( - modifier = modifier.testTag("WeekPager"), - state = listState, - flingBehavior = flingBehavior, - verticalAlignment = Alignment.Top, + Column( + modifier = modifier, ) { - items(PagerItemCount) { index -> - WeekContent( - modifier = Modifier.fillParentMaxWidth(), - daysOfWeek = daysOfWeek, - weekDays = weekListState.getWeekForPage(index).getWeekDays(today = today), - selectionState = selectionState, - dayContent = dayContent, - daysOfWeekHeader = daysOfWeekHeader, + if (weekDaysScrollEnabled.not()) { + Box( + modifier = Modifier + .wrapContentHeight() + .fillMaxWidth(), + content = { daysOfWeekHeader(daysOfWeek) }, ) } + LazyRow( + modifier = modifier.testTag("WeekPager"), + state = listState, + flingBehavior = flingBehavior, + verticalAlignment = Alignment.Top, + ) { + items(PagerItemCount) { index -> + WeekContent( + modifier = Modifier.fillParentMaxWidth(), + daysOfWeek = daysOfWeek, + weekDays = weekListState.getWeekForPage(index).getWeekDays(today = today), + selectionState = selectionState, + weekDaysScrollEnabled = weekDaysScrollEnabled, + dayContent = dayContent, + daysOfWeekHeader = daysOfWeekHeader, + ) + } + } } } @@ -88,18 +101,21 @@ internal fun WeekContent( weekDays: WeekDays, daysOfWeek: List, modifier: Modifier = Modifier, + weekDaysScrollEnabled: Boolean = true, dayContent: @Composable BoxScope.(DayState) -> Unit, daysOfWeekHeader: @Composable BoxScope.(List) -> Unit, ) { Column( modifier = modifier, ) { - Box( - modifier = Modifier - .wrapContentHeight() - .fillMaxWidth(), - content = { daysOfWeekHeader(daysOfWeek) }, - ) + if (weekDaysScrollEnabled) { + Box( + modifier = Modifier + .wrapContentHeight() + .fillMaxWidth(), + content = { daysOfWeekHeader(daysOfWeek) }, + ) + } WeekRow( weekDays = weekDays, modifier = Modifier.fillMaxWidth(),