commonMain.com.kizitonwose.calendar.compose.weekcalendar.WeekCalendar.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compose-multiplatform Show documentation
Show all versions of compose-multiplatform Show documentation
A highly customizable calendar library for Compose Multiplatform, backed by LazyRow/LazyColumn.
package com.kizitonwose.calendar.compose.weekcalendar
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import com.kizitonwose.calendar.compose.CalendarDefaults.flingBehavior
import com.kizitonwose.calendar.core.Week
import com.kizitonwose.calendar.core.WeekDay
import com.kizitonwose.calendar.core.format.toIso8601String
@Composable
internal fun WeekCalendarImpl(
modifier: Modifier,
state: WeekCalendarState,
calendarScrollPaged: Boolean,
userScrollEnabled: Boolean,
reverseLayout: Boolean,
contentPadding: PaddingValues,
dayContent: @Composable BoxScope.(WeekDay) -> Unit,
weekHeader: (@Composable ColumnScope.(Week) -> Unit)? = null,
weekFooter: (@Composable ColumnScope.(Week) -> Unit)? = null,
) {
LazyRow(
modifier = modifier,
state = state.listState,
flingBehavior = flingBehavior(calendarScrollPaged, state.listState),
userScrollEnabled = userScrollEnabled,
reverseLayout = reverseLayout,
contentPadding = contentPadding,
) {
items(
count = state.weekIndexCount,
key = { offset -> state.store[offset].days.first().date.toIso8601String() },
) { offset ->
val week = state.store[offset]
Column(
modifier = Modifier
.then(
if (calendarScrollPaged) {
Modifier.fillParentMaxWidth()
} else {
Modifier.width(IntrinsicSize.Max)
},
),
) {
weekHeader?.invoke(this, week)
Row {
for (date in week.days) {
Box(
modifier = Modifier
.then(if (calendarScrollPaged) Modifier.weight(1f) else Modifier)
.clipToBounds(),
) {
dayContent(date)
}
}
}
weekFooter?.invoke(this, week)
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy