Skip to content

Commit

Permalink
Support for landscape mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz800 committed Oct 3, 2022
1 parent 0005ddc commit adb50ee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
6 changes: 5 additions & 1 deletion app/src/main/java/com/mabn/calendar/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
Expand Down Expand Up @@ -42,7 +44,8 @@ class MainActivity : ComponentActivity() {
@Composable
fun Calendar() {
val currentDate = remember { mutableStateOf(LocalDate.now()) }
Column() {
val scrollState = rememberScrollState()
Column(Modifier.verticalScroll(scrollState)) {
ExpandableCalendar(
theme = calendarDefaultTheme.copy(
dayShape = CircleShape,
Expand All @@ -61,6 +64,7 @@ fun Calendar() {
}
}


@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies {
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "com.google.accompanist:accompanist-pager:0.23.1"
implementation "com.google.accompanist:accompanist-flowlayout:0.26.4-beta"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.mabn.calendarlibrary
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ fun DayView(
else modifier.background(theme.dayBackgroundColor, shape = theme.dayShape)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier
.heightIn(max = if (weekDayLabel) 50.dp + 20.dp else 50.dp)
.widthIn(max = 50.dp)
.testTag("day_view_column")
) {
if (weekDayLabel) {
Expand All @@ -61,7 +64,7 @@ fun DayView(
}
Box(
dayValueModifier
.padding(10.dp)
.padding(5.dp)
.aspectRatio(1f)
.clickable { onDayClick(date) },
contentAlignment = Alignment.Center
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.mabn.calendarlibrary.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.dp
import com.google.accompanist.flowlayout.FlowColumn
import com.google.accompanist.flowlayout.FlowRow
import com.mabn.calendarlibrary.core.CalendarTheme
import com.mabn.calendarlibrary.utils.dayViewModifier
import java.time.LocalDate
Expand All @@ -24,17 +25,20 @@ internal fun MonthViewCalendar(
loadDatesForMonth: (YearMonth) -> Unit,
onDayClick: (LocalDate) -> Unit
) {
val itemWidth = LocalConfiguration.current.screenWidthDp / 7
CalendarPager(
loadedDates = loadedDates,
loadNextDates = { loadDatesForMonth(currentMonth) },
loadPrevDates = { loadDatesForMonth(currentMonth.minusMonths(2)) } // why 2
) { currentPage ->
LazyVerticalGrid(
columns = GridCells.Fixed(7),
verticalArrangement = Arrangement.Top,
) {
itemsIndexed(loadedDates[currentPage]) { index, date ->
Box(Modifier.padding(5.dp)) {
FlowRow(Modifier.height(355.dp)) {
loadedDates[currentPage].forEachIndexed { index, date ->
Box(
Modifier
.width(itemWidth.dp)
.padding(5.dp),
contentAlignment = Alignment.Center
) {
DayView(
date,
theme = theme,
Expand Down

0 comments on commit adb50ee

Please sign in to comment.