Skip to content

Commit

Permalink
Fix blank page issue + update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechOsak committed Mar 27, 2024
1 parent b8dba55 commit d75332a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
15 changes: 15 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ Each view get as parameter day cell composable. Thanks to that your calendar can
<img src="readme/sample1.png" height="250"/>
<img src="readme/sample2.png" height="250"/>


Basic horizontal scrollable view:

```kotlin
HorizontalCalendarView(startDate = startDate) { monthOffset ->
CalendarView(
config = rememberCalendarState(
startDate = startDate,
monthOffset = monthOffset,
),
)
}

```

## Range selection:

```kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ interface RangeIllustrator {
* @param drawScope The drawing scope used for rendering.
*/
fun drawMiddle(drawScope: DrawScope)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
),
Expand Down

0 comments on commit d75332a

Please sign in to comment.