Closed s-septimiu closed 1 month ago
Initially, I wanted to use the CalendarView alone, and have my own header with left-right arrows so I can change the month in the view, but that doesn't work.
If you help me using only the calendarview, as I don't need the sliding animation, I just need to swap months in the calendarView.. that would be great! @WojciechOsak
Hey @s-septimiu, I can not reproduce it, but I've found similar issue in jetpack compose, could you try this: https://stackoverflow.com/questions/76865105/jetpack-compose-horizontalpager-exception in your project?
Anyway if you don't want to use swipe animation you can use pagerState like this:
val pagerState = rememberPagerState(
initialPage = 100000 / 2,
pageCount = { 100000 },
)
val scope = rememberCoroutineScope()
Column {
Row {
Button(onClick = {
scope.launch { pagerState.scrollToPage(pagerState.currentPage - 1) }
}) {
Text("LEFT")
}
Button(onClick = {
scope.launch {
pagerState.scrollToPage(pagerState.currentPage + 1)
}
}) {
Text("RIGHT")
}
}
HorizontalCalendarView(
startDate = LocalDate.today(),
pagerState = pagerState
) { monthOffset ->
CalendarView(
config = rememberCalendarState(
startDate = LocalDate.today(),
monthOffset = monthOffset,
showNextMonthDays = true,
showPreviousMonthDays = true,
showHeader = true,
showWeekdays = true,
),
)
}
}
To use it only with CalendarView you need something like this:
val config = rememberCalendarState(
startDate = LocalDate.today(),
monthOffset = 0,
showNextMonthDays = true,
showPreviousMonthDays = true,
showHeader = true,
showWeekdays = true,
)
Column {
Row {
Button(onClick = {
val currentConfig = config.value
config.value = config.value.copy(
monthYear = currentConfig.monthYear.toLocalDate()
.minus(1, DateTimeUnit.MONTH).toMonthYear()
)
}) {
Text("LEFT")
}
Button(onClick = {
val currentConfig = config.value
config.value = config.value.copy(
monthYear = currentConfig.monthYear.toLocalDate()
.plus(1, DateTimeUnit.MONTH).toMonthYear()
)
}) {
Text("RIGHT")
}
}
CalendarView(
config = config,
)
}
but it looks like I've made mistake in the code of CalendarView, and I should not use remember for yearMonth - I am sorry for that! So above example will not work without lib update / fork.
I got some bugs to fix and update compose and kotlin to 2.0, soooo I am going to release new version of the lib so you can use CalendarView without HorizontalCalendarView.
Changes merged here and will be released with 0.0.9
I agree with you that the remember made this impossible. Thanks a lot for the quick reply and fix, looking forward for the 0.0.9
@s-septimiu lib is released 🚀 Try 0.0.9 (Compose 1.6.1) or lib 1.0.0 (it supports Compose 2.0.0).
I've updated to 0.0.9 and it's working now. Thanks, you can close the issue.
Awesome, thank you for update! :) And if u migrate to Kotlin 2.0.0 you can use lib 1.0.0 🚀
@s-septimiu hey, update about "No static method HorizontalPager" issue, I think I have find the root of the problem, and fix will be delivered in next couple hours in 1.0.1 version, please try and let me know if it helps if u still got that error.
@WojciechOsak unfortunately I don't have kotlin 2+ in my project so 1.0.1 won't run... If I update and I still see that issue open I will give you an update.
I've recently added the library in a KMM project (0.0.8). I've defined the CalendarView, which works perfect and then I realised I need to be able to go next/previous month as well.
I've added the HorizontalCalendarView just like in your sample:
But I have this following error/crash:
Do you know what could go wrong here?