diff --git a/README.MD b/README.MD
index 55f7ace..cb911be 100644
--- a/README.MD
+++ b/README.MD
@@ -98,6 +98,21 @@ Each view get as parameter day cell composable. Thanks to that your calendar can
+
+Basic horizontal scrollable view:
+
+```kotlin
+HorizontalCalendarView(startDate = startDate) { monthOffset ->
+ CalendarView(
+ config = rememberCalendarState(
+ startDate = startDate,
+ monthOffset = monthOffset,
+ ),
+ )
+}
+
+```
+
## Range selection:
```kotlin
diff --git a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/RangeIllustrator.kt b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/RangeIllustrator.kt
index eb8d673..7ffffbf 100644
--- a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/RangeIllustrator.kt
+++ b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/range/RangeIllustrator.kt
@@ -27,4 +27,4 @@ interface RangeIllustrator {
* @param drawScope The drawing scope used for rendering.
*/
fun drawMiddle(drawScope: DrawScope)
-}
\ No newline at end of file
+}
diff --git a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt
index 902470e..def1584 100644
--- a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt
+++ b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt
@@ -1,11 +1,9 @@
package io.wojciechosak.calendar.view
import androidx.compose.foundation.BorderStroke
-import androidx.compose.foundation.background
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
-import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.OutlinedButton
diff --git a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/HorizontalCalendarView.kt b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/HorizontalCalendarView.kt
index 45d55e9..c7a1360 100644
--- a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/HorizontalCalendarView.kt
+++ b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/HorizontalCalendarView.kt
@@ -14,6 +14,7 @@ import androidx.compose.ui.unit.dp
import io.wojciechosak.calendar.animation.CalendarAnimator
import io.wojciechosak.calendar.config.CalendarConstants.INITIAL_PAGE_INDEX
import io.wojciechosak.calendar.config.CalendarConstants.MAX_PAGES
+import io.wojciechosak.calendar.config.rememberCalendarState
import kotlinx.datetime.LocalDate
/**
@@ -23,7 +24,7 @@ import kotlinx.datetime.LocalDate
* @param pagerState The PagerState used to control the horizontal paging behavior of the calendar.
* @param modifier The modifier for styling and layout of the calendar.
* @param pageSize The size of each page in the calendar. Default is [PageSize.Fill].
- * @param beyondBoundsPageCount The number of pages to keep loaded beyond the visible bounds. Default is 3.
+ * @param beyondBoundsPageCount The number of pages to keep loaded beyond the visible bounds. Default is 0.
* @param contentPadding The padding applied around the content of the day cell.
* @param calendarAnimator The animator used for animating calendar transitions.
* @param calendarView The composable function to display the content of each calendar page.
@@ -32,18 +33,29 @@ import kotlinx.datetime.LocalDate
@Composable
fun HorizontalCalendarView(
startDate: LocalDate,
- pagerState: PagerState =
- rememberPagerState(
- initialPage = INITIAL_PAGE_INDEX,
- pageCount = { MAX_PAGES },
- initialPageOffsetFraction = 0f,
- ),
+ pagerState: PagerState = rememberPagerState(
+ initialPage = INITIAL_PAGE_INDEX,
+ pageCount = { MAX_PAGES },
+ ),
modifier: Modifier = Modifier,
pageSize: PageSize = PageSize.Fill,
- beyondBoundsPageCount: Int = 3,
+ beyondBoundsPageCount: Int = 0,
contentPadding: PaddingValues = PaddingValues(0.dp),
calendarAnimator: CalendarAnimator = CalendarAnimator(startDate),
- calendarView: @Composable (monthOffset: Int) -> Unit,
+ calendarView: @Composable (monthOffset: Int) -> Unit = {
+ CalendarView(
+ day = { dayState ->
+ CalendarDay(
+ state = dayState,
+ onClick = { },
+ )
+ },
+ config = rememberCalendarState(
+ startDate = startDate,
+ monthOffset = it,
+ ),
+ )
+ },
) {
HorizontalPager(
state = pagerState,
@@ -52,15 +64,11 @@ fun HorizontalCalendarView(
beyondBoundsPageCount = beyondBoundsPageCount,
contentPadding = contentPadding,
) {
- if (pagerState.currentPage == it) {
- val index = it - INITIAL_PAGE_INDEX
- calendarAnimator.updatePagerState(pagerState)
- LaunchedEffect(Unit) {
- calendarAnimator.setAnimationMode(CalendarAnimator.AnimationMode.MONTH)
- }
- Column {
- calendarView(index)
- }
+ val index = it - INITIAL_PAGE_INDEX
+ calendarAnimator.updatePagerState(pagerState)
+ LaunchedEffect(Unit) {
+ calendarAnimator.setAnimationMode(CalendarAnimator.AnimationMode.MONTH)
}
+ Column { calendarView(index) }
}
}
diff --git a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/VerticalCalendarView.kt b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/VerticalCalendarView.kt
index c39b109..d976305 100644
--- a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/VerticalCalendarView.kt
+++ b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/VerticalCalendarView.kt
@@ -23,7 +23,7 @@ import kotlinx.datetime.LocalDate
* @param modifier The modifier for styling and layout of the calendar.
* @param pageSize The size of each page in the calendar. Default is [PageSize.Fill].
* @param contentPadding The padding applied around the content of the calendar.
- * @param beyondBoundsPageCount The number of pages to keep loaded beyond the visible bounds. Default is 3.
+ * @param beyondBoundsPageCount The number of pages to keep loaded beyond the visible bounds. Default is 0.
* @param calendarView The composable function to display the content of each calendar page.
*/
@OptIn(ExperimentalFoundationApi::class)
@@ -34,7 +34,7 @@ fun VerticalCalendarView(
modifier: Modifier = Modifier,
pageSize: PageSize = PageSize.Fill,
contentPadding: PaddingValues = PaddingValues(0.dp),
- beyondBoundsPageCount: Int = 3,
+ beyondBoundsPageCount: Int = 0,
calendarView: @Composable (monthOffset: Int) -> Unit,
) {
val pagerState =
diff --git a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/HorizontalCalendarScreen.kt b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/HorizontalCalendarScreen.kt
index 43230dc..112d16a 100644
--- a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/HorizontalCalendarScreen.kt
+++ b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/HorizontalCalendarScreen.kt
@@ -17,7 +17,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.wojciechosak.calendar.config.rememberCalendarState
import io.wojciechosak.calendar.utils.today
-import io.wojciechosak.calendar.view.CalendarDay
import io.wojciechosak.calendar.view.CalendarView
import io.wojciechosak.calendar.view.HorizontalCalendarView
import kotlinx.datetime.LocalDate
@@ -31,28 +30,13 @@ class HorizontalCalendarScreen : NamedScreen {
override fun Content() {
val startDate = LocalDate.today()
Column {
- HorizontalCalendarView(startDate = startDate) { monthOffset ->
- CalendarView(
- day = { dayState ->
- CalendarDay(
- state = dayState,
- onClick = { },
- )
- },
- config =
- rememberCalendarState(
- startDate = startDate,
- monthOffset = monthOffset,
- ),
- )
- }
+ HorizontalCalendarView(startDate = startDate)
HorizontalCalendarView(startDate = startDate) { monthOffset ->
CalendarView(
day = { dayState ->
SquareDay(dayState.date)
},
- config =
- rememberCalendarState(
+ config = rememberCalendarState(
startDate = startDate,
monthOffset = monthOffset,
),