Skip to content

Commit

Permalink
Improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Aug 3, 2024
1 parent e70db61 commit 5c62c3e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<activity
android:exported="true"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
android:name=".MainActivity">
android:name="com.kizitonwose.calendar.compose.multiplatform.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
7 changes: 5 additions & 2 deletions compose-multiplatform/sample/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -47,9 +48,11 @@ fun App() {
val widthPx = maxWidth.value.roundToInt()
val count = if (widthPx in 650..800) 2 else widthPx / 400
Row {
repeat(count) {
VerticalDivider()
repeat(count) { index ->
Demo(modifier = Modifier.weight(1f))
if (index < count - 1) {
VerticalDivider()
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyListState
Expand Down Expand Up @@ -105,7 +107,16 @@ fun Example10Page(adjacentYears: Int = 50) {
}
HorizontalYearCalendar(
modifier = Modifier
.fillMaxSize()
.fillMaxWidth()
.then(
if (isMobile()) {
Modifier.fillMaxHeight()
} else {
// Don't stretch vertically on very
// large displays (web+desktop)
Modifier.heightIn(max = 920.dp)
},
)
.testTag("Calendar"),
state = state,
monthColumns = if (isPortrait) {
Expand Down
82 changes: 39 additions & 43 deletions compose-multiplatform/sample/src/commonMain/kotlin/Example11Page.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,50 @@ fun Example11Page(adjacentYears: Int = 50) {
val selections = remember { mutableStateListOf<CalendarDay>() }
val daysOfWeek = remember { daysOfWeek() }
BoxWithConstraints(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize()
.background(Color.White),
) {
val isTablet = maxWidth >= 600.dp
Column(
val state = rememberYearCalendarState(
startYear = currentYear,
endYear = endYear,
firstVisibleYear = currentYear,
firstDayOfWeek = daysOfWeek.first(),
)
VerticalYearCalendar(
modifier = Modifier
.fillMaxSize()
.background(Color.White),
) {
val state = rememberYearCalendarState(
startYear = currentYear,
endYear = endYear,
firstVisibleYear = currentYear,
firstDayOfWeek = daysOfWeek.first(),
)
VerticalYearCalendar(
modifier = Modifier
.fillMaxSize()
.testTag("Calendar"),
state = state,
dayContent = { day ->
Day(
day = day,
isSelected = selections.contains(day),
isTablet = isTablet,
) { clicked ->
if (selections.contains(clicked)) {
selections.remove(clicked)
} else {
selections.add(clicked)
}
.testTag("Calendar"),
state = state,
dayContent = { day ->
Day(
day = day,
isSelected = selections.contains(day),
isTablet = isTablet,
) { clicked ->
if (selections.contains(clicked)) {
selections.remove(clicked)
} else {
selections.add(clicked)
}
},
calendarScrollPaged = false,
contentHeightMode = YearContentHeightMode.Wrap,
monthVerticalSpacing = 20.dp,
monthHorizontalSpacing = if (isTablet) 52.dp else 10.dp,
contentPadding = PaddingValues(horizontal = if (isTablet) 52.dp else 10.dp),
isMonthVisible = {
it.yearMonth >= currentMonth
},
yearHeader = {
YearHeader(it.year)
},
monthHeader = {
MonthHeader(it)
},
)
}
}
},
calendarScrollPaged = false,
contentHeightMode = YearContentHeightMode.Wrap,
monthVerticalSpacing = 20.dp,
monthHorizontalSpacing = if (isTablet) 52.dp else 10.dp,
contentPadding = PaddingValues(horizontal = if (isTablet) 52.dp else 10.dp),
isMonthVisible = {
it.yearMonth >= currentMonth
},
yearHeader = {
YearHeader(it.year)
},
monthHeader = {
MonthHeader(it)
},
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun Example11Page(adjacentYears: Long = 50) {
val daysOfWeek = remember { daysOfWeek() }
val config = LocalConfiguration.current
val isTablet = config.smallestScreenWidthDp >= 600
Column(
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.White),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Example3Fragment : BaseFragment(R.layout.example_3_fragment), HasBackButto
override fun bind(container: MonthViewContainer, data: CalendarMonth) {
// Setup each header day text if we have not done that already.
if (container.legendLayout.tag == null) {
container.legendLayout.tag = data.yearMonth
container.legendLayout.tag = true
container.legendLayout.children.map { it as TextView }
.forEachIndexed { index, tv ->
tv.text = daysOfWeek[index].name.first().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Example5Fragment : BaseFragment(R.layout.example_5_fragment), HasToolbar {
override fun bind(container: MonthViewContainer, data: CalendarMonth) {
// Setup each header day text if we have not done that already.
if (container.legendLayout.tag == null) {
container.legendLayout.tag = data.yearMonth
container.legendLayout.tag = true
container.legendLayout.children.map { it as TextView }
.forEachIndexed { index, tv ->
tv.text = daysOfWeek[index].displayText(uppercase = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Example6Fragment : BaseFragment(R.layout.example_6_fragment), HasBackButto
container.textView.text = data.yearMonth.displayText(short = true)
// Setup each header day text if we have not done that already.
if (container.legendLayout.tag == null) {
container.legendLayout.tag = data.yearMonth
container.legendLayout.tag = true
container.legendLayout.children.map { it as TextView }
.forEachIndexed { index, tv ->
tv.text = daysOfWeek[index].name.first().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class Example8Fragment : BaseFragment(R.layout.example_8_fragment), HasToolbar {
override fun create(view: View) = MonthHeaderViewContainer(view)
override fun bind(container: MonthHeaderViewContainer, data: CalendarMonth) {
// Setup each header day text if we have not done that already.
if (container.binding.root.tag == null) {
container.binding.root.tag = data.yearMonth
if (container.binding.legendLayout.root.tag == null) {
container.binding.legendLayout.root.tag = true
container.binding.legendLayout.root.children
.map { it as TextView }
.forEachIndexed { index, tv ->
Expand Down

0 comments on commit 5c62c3e

Please sign in to comment.