-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cabf01e
commit ac6f67f
Showing
21 changed files
with
162 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/config/CalendarConstants.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package io.wojciechosak.calendar.config | ||
|
||
object CalendarConstants { | ||
internal const val INITIAL_PAGE_INDEX = Int.MAX_VALUE / 2 | ||
// Compose 1.6.1 bug: https://issuetracker.google.com/issues/311414925, let's use fixed numbers for now. | ||
// internal const val MAX_PAGES = Int.MAX_VALUE | ||
internal const val MAX_PAGES = 100000 | ||
internal const val INITIAL_PAGE_INDEX = MAX_PAGES / 2 | ||
} |
38 changes: 17 additions & 21 deletions
38
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/HorizontalCalendarView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,54 @@ | ||
package io.wojciechosak.calendar.view | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.gestures.Orientation | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.pager.HorizontalPager | ||
import androidx.compose.foundation.pager.PageSize | ||
import androidx.compose.foundation.pager.PagerDefaults | ||
import androidx.compose.foundation.pager.PagerState | ||
import androidx.compose.foundation.pager.rememberPagerState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection | ||
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 kotlinx.datetime.LocalDate | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
@Composable | ||
fun HorizontalCalendarView( | ||
startDate: LocalDate, | ||
pagerState: PagerState = | ||
rememberPagerState( | ||
initialPage = INITIAL_PAGE_INDEX, | ||
pageCount = { MAX_PAGES }, | ||
initialPageOffsetFraction = 0f, | ||
), | ||
modifier: Modifier = Modifier, | ||
pageSize: PageSize = PageSize.Fill, | ||
beyondBoundsPageCount: Int = 0, | ||
contentPadding: PaddingValues = PaddingValues(0.dp), | ||
pageNestedScrollConnection: NestedScrollConnection = | ||
PagerDefaults.pageNestedScrollConnection( | ||
Orientation.Horizontal, | ||
), | ||
calendarAnimator: CalendarAnimator = CalendarAnimator(startDate), | ||
calendarView: @Composable (monthOffset: Int) -> Unit, | ||
) { | ||
val pagerState = | ||
rememberPagerState( | ||
initialPage = INITIAL_PAGE_INDEX, | ||
pageCount = { Int.MAX_VALUE }, | ||
) | ||
|
||
HorizontalPager( | ||
state = pagerState, | ||
modifier = modifier, | ||
pageSize = pageSize, | ||
beyondBoundsPageCount = beyondBoundsPageCount, | ||
pageNestedScrollConnection = pageNestedScrollConnection, | ||
contentPadding = contentPadding, | ||
) { | ||
val index = it - INITIAL_PAGE_INDEX | ||
calendarAnimator.updatePagerState(pagerState) | ||
LaunchedEffect(Unit) { | ||
calendarAnimator.setAnimationMode(CalendarAnimator.AnimationMode.MONTH) | ||
} | ||
Column { | ||
calendarView(index) | ||
if (pagerState.currentPage == it) { | ||
val index = it - INITIAL_PAGE_INDEX | ||
calendarAnimator.updatePagerState(pagerState) | ||
LaunchedEffect(Unit) { | ||
calendarAnimator.setAnimationMode(CalendarAnimator.AnimationMode.MONTH) | ||
} | ||
Column { | ||
calendarView(index) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 57 additions & 3 deletions
60
sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,68 @@ | ||
package io.wojciechosak.calendar.calendar | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.safeContentPadding | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBackIos | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.SmallTopAppBar | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.sp | ||
import cafe.adriel.voyager.navigator.CurrentScreen | ||
import cafe.adriel.voyager.navigator.LocalNavigator | ||
import cafe.adriel.voyager.navigator.Navigator | ||
import io.wojciechosak.calendar.calendar.screens.NamedScreen | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
internal fun App() { | ||
Box(modifier = Modifier.safeContentPadding()) { | ||
Navigator(MenuScreen()) | ||
Box { | ||
Navigator(MenuScreen()) { | ||
Scaffold( | ||
topBar = { | ||
val navigator = LocalNavigator.current | ||
SmallTopAppBar( | ||
colors = | ||
TopAppBarDefaults.topAppBarColors( | ||
containerColor = MaterialTheme.colorScheme.primary, | ||
titleContentColor = Color.White, | ||
), | ||
title = { | ||
if (navigator?.canPop == true) { | ||
Text((navigator.lastItem as? NamedScreen)?.name ?: "", fontSize = 14.sp) | ||
} else { | ||
Text("KMP Calendar Demo", fontSize = 14.sp) | ||
} | ||
}, | ||
navigationIcon = { | ||
if (navigator?.canPop == true) { | ||
IconButton( | ||
onClick = { navigator.pop() }, | ||
) { | ||
Icon( | ||
imageVector = Icons.AutoMirrored.Filled.ArrowBackIos, | ||
contentDescription = "Back", | ||
tint = Color.White, | ||
) | ||
} | ||
} | ||
}, | ||
) | ||
}, | ||
content = { padding -> | ||
Box(Modifier.padding(padding)) { | ||
CurrentScreen() | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
...oseApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/DateRangeScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.