diff --git a/.github/workflows/publish-web.yml b/.github/workflows/publish-web.yml new file mode 100644 index 0000000..e2f27a2 --- /dev/null +++ b/.github/workflows/publish-web.yml @@ -0,0 +1,43 @@ +name: Publish Web +on: + workflow_dispatch: + inputs: + versionName: + description: '' + required: true +permissions: + contents: read + pages: write + id-token: write +jobs: + publish: + name: Publish Web + runs-on: macos-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + + - name: Grant Permission to Execute Gradle + run: chmod +x gradlew + + - name: Build with Gradle + uses: gradle/gradle-build-action@v2 + with: + arguments: sample:composeApp:build + - name: Build sample JS - Main + run: ./gradlew :sample:composeApp:jsBrowserDistribution + + - name: Upload your page as github pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: sample/composeApp/build/dist/js/productionExecutable/ + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt index def1584..cffae5a 100644 --- a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt +++ b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/CalendarDay.kt @@ -2,13 +2,15 @@ package io.wojciechosak.calendar.view import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -28,35 +30,35 @@ import io.wojciechosak.calendar.utils.Pallete */ @Composable fun CalendarDay( - state: DayState, - interactionSource: MutableInteractionSource = MutableInteractionSource(), - onClick: () -> Unit = {}, - modifier: Modifier = Modifier, + state: DayState, + interactionSource: MutableInteractionSource = MutableInteractionSource(), + onClick: () -> Unit = {}, + modifier: Modifier = Modifier, ) = with(state) { - OutlinedButton( - onClick = onClick, - modifier = modifier, - shape = RoundedCornerShape(50.dp), - border = BorderStroke(1.dp, Color.Transparent), - contentPadding = PaddingValues(0.dp), - interactionSource = interactionSource, - enabled = enabled, - colors = - ButtonDefaults.outlinedButtonColors( - contentColor = - if (isForPreviousMonth || isForNextMonth) { - Color.LightGray - } else { - if (isActiveDay) Pallete.LightGreen else Pallete.LightBlue - }, - ), - ) { - Column(horizontalAlignment = Alignment.CenterHorizontally) { - Text( - "${date.dayOfMonth}", - fontSize = 20.sp, - textAlign = TextAlign.Center, - ) - } - } + Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) { + OutlinedButton( + onClick = onClick, + modifier = modifier, + shape = RoundedCornerShape(50.dp), + border = BorderStroke(1.dp, Color.Transparent), + contentPadding = PaddingValues(0.dp), + interactionSource = remember { interactionSource }, + enabled = enabled, + colors = + ButtonDefaults.outlinedButtonColors( + contentColor = + if (isForPreviousMonth || isForNextMonth) { + Color.LightGray + } else { + if (isActiveDay) Pallete.LightGreen else Pallete.LightBlue + }, + ), + ) { + Text( + "${date.dayOfMonth}", + fontSize = 20.sp, + textAlign = TextAlign.Center, + ) + } + } } diff --git a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/WeekView.kt b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/WeekView.kt index c54f457..d8a76e3 100644 --- a/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/WeekView.kt +++ b/calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/WeekView.kt @@ -1,18 +1,24 @@ package io.wojciechosak.calendar.view +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.width import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -20,6 +26,7 @@ import io.wojciechosak.calendar.animation.CalendarAnimator import io.wojciechosak.calendar.config.CalendarConstants.INITIAL_PAGE_INDEX import io.wojciechosak.calendar.config.CalendarConstants.MAX_PAGES import io.wojciechosak.calendar.config.DayState +import io.wojciechosak.calendar.utils.Pallete import io.wojciechosak.calendar.utils.copy import io.wojciechosak.calendar.utils.daySimpleName import io.wojciechosak.calendar.utils.monthLength @@ -50,80 +57,107 @@ import kotlinx.datetime.toLocalDateTime @OptIn(ExperimentalFoundationApi::class) @Composable fun WeekView( - startDate: LocalDate = - Clock.System.now() - .toLocalDateTime(TimeZone.currentSystemDefault()) - .toLocalDate(), - minDate: LocalDate = startDate.copy(day = 1).minus(3, DateTimeUnit.MONTH), - maxDate: LocalDate = - startDate.copy(day = monthLength(startDate.month, startDate.year)) - .plus(3, DateTimeUnit.MONTH), - daysOffset: Int = 0, - showDaysBesideRange: Boolean = true, - calendarAnimator: CalendarAnimator = CalendarAnimator(startDate), - isActive: (LocalDate) -> Boolean = { - val today = - Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).toLocalDate() - today == it - }, - modifier: Modifier = Modifier, - firstVisibleDate: (LocalDate) -> Unit = {}, - day: @Composable (dayState: DayState) -> Unit = { state -> - weekDay(state) { - CalendarDay( - state, - modifier = Modifier.width(58.dp), - ) - } - }, + startDate: LocalDate = + Clock.System.now() + .toLocalDateTime(TimeZone.currentSystemDefault()) + .toLocalDate(), + minDate: LocalDate = startDate.copy(day = 1).minus(3, DateTimeUnit.MONTH), + maxDate: LocalDate = + startDate.copy(day = monthLength(startDate.month, startDate.year)) + .plus(3, DateTimeUnit.MONTH), + daysOffset: Int = 0, + showDaysBesideRange: Boolean = true, + calendarAnimator: CalendarAnimator = CalendarAnimator(startDate), + isActive: (LocalDate) -> Boolean = { + val today = + Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).toLocalDate() + today == it + }, + modifier: Modifier = Modifier, + firstVisibleDate: (LocalDate) -> Unit = {}, + day: @Composable (dayState: DayState) -> Unit = { state -> + weekDay(state) { + WeekViewDay(modifier = Modifier, state = state) + } + }, ) { - val minIndex = if (showDaysBesideRange) 0 else minDate.daysUntil(startDate) - val maxIndex = if (showDaysBesideRange) MAX_PAGES else startDate.daysUntil(maxDate) - val initialPageIndex = if (showDaysBesideRange) INITIAL_PAGE_INDEX else minIndex + daysOffset - LaunchedEffect(Unit) { - calendarAnimator.setAnimationMode(CalendarAnimator.AnimationMode.WEEK) - } - val pagerState = - rememberPagerState( - initialPage = initialPageIndex, - pageCount = { minIndex + maxIndex }, - ) - HorizontalPager( - state = pagerState, - modifier = modifier, - ) { - val index = it - initialPageIndex // week number - calendarAnimator.updatePagerState(pagerState) - firstVisibleDate(startDate.plus(index * 7, DateTimeUnit.DAY)) - Row( - Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceEvenly - ) { - for (day in 0..6) { - Column( - verticalArrangement = Arrangement.SpaceEvenly, - horizontalAlignment = Alignment.CenterHorizontally, - ) { - val newDate = startDate.plus(index * 7 + day, DateTimeUnit.DAY) - day( - DayState( - date = newDate, - isActiveDay = isActive(newDate), - enabled = true, - ), - ) - } - } - } - } + val minIndex = if (showDaysBesideRange) 0 else minDate.daysUntil(startDate) + val maxIndex = if (showDaysBesideRange) MAX_PAGES else startDate.daysUntil(maxDate) + val initialPageIndex = if (showDaysBesideRange) INITIAL_PAGE_INDEX else minIndex + daysOffset + LaunchedEffect(Unit) { + calendarAnimator.setAnimationMode(CalendarAnimator.AnimationMode.WEEK) + } + val pagerState = + rememberPagerState( + initialPage = initialPageIndex, + pageCount = { minIndex + maxIndex }, + ) + HorizontalPager( + state = pagerState, + modifier = modifier, + ) { + val index = it - initialPageIndex // week number + calendarAnimator.updatePagerState(pagerState) + firstVisibleDate(startDate.plus(index * 7, DateTimeUnit.DAY)) + Row( + Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceEvenly + ) { + for (day in 0..6) { + Column( + verticalArrangement = Arrangement.SpaceEvenly, + horizontalAlignment = Alignment.CenterHorizontally, + ) { + val newDate = startDate.plus(index * 7 + day, DateTimeUnit.DAY) + day( + DayState( + date = newDate, + isActiveDay = isActive(newDate), + enabled = true, + ), + ) + } + } + } + } } @Composable private fun weekDay( - state: DayState, - function: @Composable () -> Unit, + state: DayState, + function: @Composable () -> Unit, ) { - Text(state.date.daySimpleName(), fontSize = 12.sp, textAlign = TextAlign.Center) - function() + Text(state.date.daySimpleName(), fontSize = 12.sp, textAlign = TextAlign.Center) + function() } + +@Composable +fun WeekViewDay(modifier: Modifier, state: DayState, onClick: (DayState) -> Unit = {}) { + OutlinedButton( + onClick = { onClick(state) }, + modifier = modifier, + shape = RoundedCornerShape(50.dp), + border = BorderStroke(1.dp, Color.Transparent), + contentPadding = PaddingValues(0.dp), + interactionSource = MutableInteractionSource(), + enabled = state.enabled, + colors = + ButtonDefaults.outlinedButtonColors( + contentColor = + if (state.isForPreviousMonth || state.isForNextMonth) { + Color.LightGray + } else { + if (state.isActiveDay) Pallete.LightGreen else Pallete.LightBlue + }, + ), + ) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text( + "${state.date.dayOfMonth}", + fontSize = 20.sp, + textAlign = TextAlign.Center, + ) + } + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0e2a5da..0ca3f43 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ compose-uitooling = "1.6.7" kotlinx-coroutines = "1.8.1" composeIcons = "1.1.0" kotlinx-datetime = "0.5.0" -voyager = "1.0.0" +voyager = "1.1.0-beta01" ktlint = "4.2.0" [libraries] diff --git a/sample/composeApp/src/androidMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.android.kt b/sample/composeApp/src/androidMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.android.kt new file mode 100644 index 0000000..7ba7829 --- /dev/null +++ b/sample/composeApp/src/androidMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.android.kt @@ -0,0 +1,5 @@ +package io.wojciechosak.calendar.calendar + +actual fun getPlatformType(): PlatformType { + return PlatformType.MOBILE +} \ No newline at end of file diff --git a/sample/composeApp/src/androidMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.android.kt b/sample/composeApp/src/androidMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.android.kt new file mode 100644 index 0000000..978e9a0 --- /dev/null +++ b/sample/composeApp/src/androidMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.android.kt @@ -0,0 +1,24 @@ +package io.wojciechosak.calendar.calendar + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.dp + +@Composable +actual fun getScreenSizeInfo(): ScreenSizeInfo { + val density = LocalDensity.current + val config = LocalConfiguration.current + val hDp = config.screenHeightDp.dp + val wDp = config.screenWidthDp.dp + + return remember(density, config) { + ScreenSizeInfo( + heightPx = with(density) { hDp.roundToPx() }, + widthPx = with(density) { wDp.roundToPx() }, + heightDp = hDp, + widthDp = wDp + ) + } +} \ No newline at end of file diff --git a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/App.kt b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/App.kt index fe4cd2e..7cb9006 100644 --- a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/App.kt +++ b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/App.kt @@ -1,7 +1,9 @@ package io.wojciechosak.calendar.calendar import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBackIos import androidx.compose.material3.ExperimentalMaterial3Api @@ -13,6 +15,7 @@ import androidx.compose.material3.SmallTopAppBar import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.sp @@ -24,45 +27,72 @@ import io.wojciechosak.calendar.calendar.screens.NamedScreen @OptIn(ExperimentalMaterial3Api::class) @Composable internal fun App() { - 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() - } - }, - ) - } - } + val fraction = when (getPlatformType()) { + PlatformType.MOBILE -> 1f + PlatformType.WEB -> .5f + PlatformType.DESKTOP -> .5f + } + + 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 + .fillMaxWidth() + .padding(padding), + contentAlignment = Alignment.Center, + ) { + Box( + Modifier + .width( + when (getPlatformType()) { + PlatformType.MOBILE -> getScreenSizeInfo().widthDp + PlatformType.WEB -> getScreenSizeInfo().widthDp / 2 + PlatformType.DESKTOP -> getScreenSizeInfo().widthDp / 2 + } + ) // Set the width to half of the screen width + .align(Alignment.Center) // Center it within the parent Box + ) { + CurrentScreen() + } + + } + }, + ) + } + } } diff --git a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.kt b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.kt new file mode 100644 index 0000000..e3d8052 --- /dev/null +++ b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.kt @@ -0,0 +1,9 @@ +package io.wojciechosak.calendar.calendar + +enum class PlatformType { + MOBILE, + WEB, + DESKTOP +} + +expect fun getPlatformType(): PlatformType \ No newline at end of file diff --git a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.kt b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.kt new file mode 100644 index 0000000..bac7752 --- /dev/null +++ b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.kt @@ -0,0 +1,10 @@ +package io.wojciechosak.calendar.calendar + +import androidx.compose.runtime.Composable +import androidx.compose.ui.unit.Dp + +/** Getting screen size info for UI-related calculations */ +data class ScreenSizeInfo(val heightPx: Int, val widthPx: Int, val heightDp: Dp, val widthDp: Dp) + +@Composable +expect fun getScreenSizeInfo(): ScreenSizeInfo diff --git a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/CalendarViewScreen.kt b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/CalendarViewScreen.kt index d5089df..b5bf7d8 100644 --- a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/CalendarViewScreen.kt +++ b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/CalendarViewScreen.kt @@ -62,7 +62,7 @@ private fun DayView( Box { OutlinedButton( onClick = onClick, - modifier = modifier.aspectRatio(1f).padding(3.dp), + modifier = modifier.size(55.dp).aspectRatio(1f).padding(3.dp), contentPadding = PaddingValues(0.dp), border = BorderStroke(0.dp, Color.Transparent), colors = diff --git a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/WeekViewScreen.kt b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/WeekViewScreen.kt index 21163c2..6f9c0ea 100644 --- a/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/WeekViewScreen.kt +++ b/sample/composeApp/src/commonMain/kotlin/io/wojciechosak/calendar/calendar/screens/WeekViewScreen.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import io.wojciechosak.calendar.utils.daySimpleName import io.wojciechosak.calendar.utils.today -import io.wojciechosak.calendar.view.CalendarDay +import io.wojciechosak.calendar.view.WeekViewDay import io.wojciechosak.calendar.view.WeekView import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDate @@ -35,9 +35,9 @@ class WeekViewScreen : NamedScreen { WeekView { state -> Column(horizontalAlignment = Alignment.CenterHorizontally) { Text(state.date.daySimpleName()) - CalendarDay( - state, - onClick = { }, + WeekViewDay( + modifier = Modifier, + state= state, ) } } @@ -57,7 +57,7 @@ class WeekViewScreen : NamedScreen { .today() .plus(1, DateTimeUnit.DAY)..LocalDate.today() .plus(3, DateTimeUnit.DAY) - CalendarDay( + WeekViewDay( state = state.copy(enabled = !isInNextThreeDays), modifier = Modifier.size(54.dp), onClick = { selectedDay = state.date }, diff --git a/sample/composeApp/src/iosMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.ios.kt b/sample/composeApp/src/iosMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.ios.kt new file mode 100644 index 0000000..f3dda2c --- /dev/null +++ b/sample/composeApp/src/iosMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.ios.kt @@ -0,0 +1,5 @@ +package io.wojciechosak.calendar.calendar + +actual fun getPlatformType(): PlatformType { + return PlatformType.MOBILE +} \ No newline at end of file diff --git a/sample/composeApp/src/iosMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.ios.kt b/sample/composeApp/src/iosMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.ios.kt new file mode 100644 index 0000000..2c0e333 --- /dev/null +++ b/sample/composeApp/src/iosMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.ios.kt @@ -0,0 +1,24 @@ +package io.wojciechosak.calendar.calendar + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalWindowInfo + +@OptIn(ExperimentalComposeUiApi::class) +@Composable +actual fun getScreenSizeInfo(): ScreenSizeInfo { + val density = LocalDensity.current + val config = LocalWindowInfo.current.containerSize + + + return remember(density, config) { + ScreenSizeInfo( + heightPx = config.height, + widthPx = config.width, + heightDp = with(density) { config.height.toDp() }, + widthDp = with(density) { config.width.toDp() } + ) + } +} \ No newline at end of file diff --git a/sample/composeApp/src/jsMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.js.kt b/sample/composeApp/src/jsMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.js.kt new file mode 100644 index 0000000..a3b4ff9 --- /dev/null +++ b/sample/composeApp/src/jsMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.js.kt @@ -0,0 +1,5 @@ +package io.wojciechosak.calendar.calendar + +actual fun getPlatformType(): PlatformType { + return PlatformType.WEB +} \ No newline at end of file diff --git a/sample/composeApp/src/jsMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.js.kt b/sample/composeApp/src/jsMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.js.kt new file mode 100644 index 0000000..3839b6e --- /dev/null +++ b/sample/composeApp/src/jsMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.js.kt @@ -0,0 +1,23 @@ +package io.wojciechosak.calendar.calendar + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalWindowInfo + +@OptIn(ExperimentalComposeUiApi::class) +@Composable +actual fun getScreenSizeInfo(): ScreenSizeInfo { + val density = LocalDensity.current + val config = LocalWindowInfo.current.containerSize + + return remember(density, config) { + ScreenSizeInfo( + heightPx = config.height, + widthPx = config.width, + heightDp = with(density) { config.height.toDp() }, + widthDp = with(density) { config.width.toDp() } + ) + } +} \ No newline at end of file diff --git a/sample/composeApp/src/jvmMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.jvm.kt b/sample/composeApp/src/jvmMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.jvm.kt new file mode 100644 index 0000000..a5e8d76 --- /dev/null +++ b/sample/composeApp/src/jvmMain/kotlin/io/wojciechosak/calendar/calendar/PlatformType.jvm.kt @@ -0,0 +1,5 @@ +package io.wojciechosak.calendar.calendar + +actual fun getPlatformType(): PlatformType { + return PlatformType.DESKTOP +} \ No newline at end of file diff --git a/sample/composeApp/src/jvmMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.jvm.kt b/sample/composeApp/src/jvmMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.jvm.kt new file mode 100644 index 0000000..8260812 --- /dev/null +++ b/sample/composeApp/src/jvmMain/kotlin/io/wojciechosak/calendar/calendar/ScreenSizeInfo.jvm.kt @@ -0,0 +1,17 @@ +package io.wojciechosak.calendar.calendar + +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalDensity +import java.awt.Toolkit + +@Composable +actual fun getScreenSizeInfo(): ScreenSizeInfo { + val screenSize = Toolkit.getDefaultToolkit().screenSize + val density = LocalDensity.current + return ScreenSizeInfo( + heightPx = screenSize.height, + widthPx = screenSize.width, + widthDp = with(density) { screenSize.width.toDp() }, + heightDp = with(density) { screenSize.height.toDp() }, + ) +} \ No newline at end of file