From 0f683e48f6fb79de28fe365083f6515775735a51 Mon Sep 17 00:00:00 2001 From: Maciej Procyk Date: Tue, 12 Mar 2024 10:29:43 +0100 Subject: [PATCH] update examples --- examples/build.gradle.kts | 17 ++++--- examples/settings.gradle.kts | 1 + .../in/procyk/compose/examples/Calendars.kt | 51 +++++++++++++++++++ .../compose/examples/CameraPermission.kt | 5 +- .../in/procyk/compose/examples/CameraQR.kt | 5 +- .../in/procyk/compose/examples/ExamplesApp.kt | 27 +++++++--- .../in/procyk/compose/examples/QRCode.kt | 28 ++++++++++ .../kotlin/in/procyk/compose/examples/Util.kt | 18 +++---- 8 files changed, 120 insertions(+), 32 deletions(-) create mode 100644 examples/src/commonMain/kotlin/in/procyk/compose/examples/Calendars.kt create mode 100644 examples/src/commonMain/kotlin/in/procyk/compose/examples/QRCode.kt diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index e9d07a8..85c805d 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -1,9 +1,9 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { - kotlin("multiplatform") version "1.9.21" - id("com.android.application") version "8.1.0" - id("org.jetbrains.compose") version "1.5.11" + kotlin("multiplatform") version "1.9.22" + id("com.android.application") version "8.2.2" + id("org.jetbrains.compose") version "1.6.0-rc02" } group = "in.procyk.compose" @@ -41,12 +41,15 @@ kotlin { implementation(compose.materialIconsExtended) implementation(compose.animationGraphics) - implementation("in.procyk.compose:camera-permission:1.5.11.0") - implementation("in.procyk.compose:camera-qr:1.5.11.0") - implementation("in.procyk.compose:util:1.5.11.0") + val composeExtensionsVersion = "1.6.0-rc02.1" + implementation("in.procyk.compose:calendar:$composeExtensionsVersion") + implementation("in.procyk.compose:camera-permission:$composeExtensionsVersion") + implementation("in.procyk.compose:camera-qr:$composeExtensionsVersion") + implementation("in.procyk.compose:util:$composeExtensionsVersion") + implementation("in.procyk.compose:qr-code:$composeExtensionsVersion") } androidMain.dependencies { - api("androidx.activity:activity-compose:1.8.1") + api("androidx.activity:activity-compose:1.8.2") api("androidx.appcompat:appcompat:1.6.1") api("androidx.core:core-ktx:1.12.0") } diff --git a/examples/settings.gradle.kts b/examples/settings.gradle.kts index c948c78..86b0b14 100644 --- a/examples/settings.gradle.kts +++ b/examples/settings.gradle.kts @@ -14,6 +14,7 @@ dependencyResolutionManagement { mavenCentral() google() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + mavenLocal() } } diff --git a/examples/src/commonMain/kotlin/in/procyk/compose/examples/Calendars.kt b/examples/src/commonMain/kotlin/in/procyk/compose/examples/Calendars.kt new file mode 100644 index 0000000..1569553 --- /dev/null +++ b/examples/src/commonMain/kotlin/in/procyk/compose/examples/Calendars.kt @@ -0,0 +1,51 @@ +package `in`.procyk.compose.examples + +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import `in`.procyk.compose.calendar.SelectableCalendar +import `in`.procyk.compose.calendar.SelectableWeekCalendar +import `in`.procyk.compose.calendar.StaticCalendar +import `in`.procyk.compose.calendar.StaticWeekCalendar + +@Composable +internal fun Calendars( + onClose: () -> Unit, +) = ExampleSystemBarsScreen(onClose) { + val scrollState = rememberScrollState() + Column( + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 12.dp) + .verticalScroll(scrollState), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(24.dp) + ) { + Spacer(Modifier.height(24.dp)) + Titled("Static Calendar") { StaticCalendar() } + Titled("Selectable Calendar") { SelectableCalendar() } + Titled("Static Week Calendar") { StaticWeekCalendar() } + Titled("Selectable Week Calendar") { SelectableWeekCalendar() } + } +} + +@Composable +private inline fun Titled( + title: String, + content: @Composable ColumnScope.() -> Unit, +) { + Column( + modifier = Modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(4.dp) + ) { + Text(title, maxLines = 1, style = MaterialTheme.typography.headlineLarge) + content() + } +} diff --git a/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraPermission.kt b/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraPermission.kt index 5e956de..3f5a0d4 100644 --- a/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraPermission.kt +++ b/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraPermission.kt @@ -8,9 +8,8 @@ import `in`.procyk.compose.camera.permission.CameraPermissionState @Composable internal fun CameraPermission( cameraPermissionState: CameraPermissionState, - visible: Boolean, - onVisibleChange: (Boolean) -> Unit, -) = ExampleSystemBarsScreen(visible, onVisibleChange) { + onClose: () -> Unit, +) = ExampleSystemBarsScreen(onClose) { when { !cameraPermissionState.isAvailable -> Text("Camera not available") cameraPermissionState.permission.isGranted -> Text("Permission granted") diff --git a/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraQR.kt b/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraQR.kt index 000539e..11c453b 100644 --- a/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraQR.kt +++ b/examples/src/commonMain/kotlin/in/procyk/compose/examples/CameraQR.kt @@ -18,9 +18,8 @@ import `in`.procyk.compose.camera.qr.QRResult @Composable internal fun CameraQR( cameraPermissionState: CameraPermissionState, - visible: Boolean, - onVisibleChange: (Boolean) -> Unit, -) = ExampleNoSystemBarsScreen(visible, onVisibleChange) { + onClose: () -> Unit, +) = ExampleNoSystemBarsScreen(onClose) { when { !cameraPermissionState.isAvailable -> Text("Camera not available") !cameraPermissionState.permission.isGranted -> Text("Missing camera permission") diff --git a/examples/src/commonMain/kotlin/in/procyk/compose/examples/ExamplesApp.kt b/examples/src/commonMain/kotlin/in/procyk/compose/examples/ExamplesApp.kt index cf49ab7..ceeecb5 100644 --- a/examples/src/commonMain/kotlin/in/procyk/compose/examples/ExamplesApp.kt +++ b/examples/src/commonMain/kotlin/in/procyk/compose/examples/ExamplesApp.kt @@ -12,18 +12,31 @@ import `in`.procyk.compose.camera.permission.rememberCameraPermissionState internal fun ExamplesApp() = MaterialTheme { val cameraPermissionState = rememberCameraPermissionState() - var visibleCameraPermission by remember { mutableStateOf(false) } - var visibleCameraQR by remember { mutableStateOf(false) } + var selectedExample by remember { mutableStateOf(null) } ExampleSystemBarsScreen(isCloseAvailable = false) { Column( modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, ) { - ExampleButton("camera-permission") { visibleCameraPermission = true } - ExampleButton("camera-qr") { visibleCameraQR = true } + for (example in Example.entries) { + ExampleButton(example.presentableName) { selectedExample = example } + } } } - CameraPermission(cameraPermissionState, visibleCameraPermission) { visibleCameraPermission = it } - CameraQR(cameraPermissionState, visibleCameraQR) { visibleCameraQR = it } -} \ No newline at end of file + when (selectedExample) { + Example.Calendar -> Calendars { selectedExample = null } + Example.CameraPermission -> CameraPermission(cameraPermissionState) { selectedExample = null } + Example.CameraQR -> CameraQR(cameraPermissionState) { selectedExample = null } + Example.QRCode -> QRCode { selectedExample = null } + null -> {} + } +} + +private enum class Example(val presentableName: String) { + Calendar("calendar"), + CameraPermission("camera-permission"), + CameraQR("camera-qr"), + QRCode("qr-code"), + ; +} diff --git a/examples/src/commonMain/kotlin/in/procyk/compose/examples/QRCode.kt b/examples/src/commonMain/kotlin/in/procyk/compose/examples/QRCode.kt new file mode 100644 index 0000000..4a037e5 --- /dev/null +++ b/examples/src/commonMain/kotlin/in/procyk/compose/examples/QRCode.kt @@ -0,0 +1,28 @@ +package `in`.procyk.compose.examples + +import androidx.compose.foundation.Image +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color +import `in`.procyk.compose.qrcode.QrData +import `in`.procyk.compose.qrcode.options.* +import `in`.procyk.compose.qrcode.rememberQrCodePainter + +@Composable +internal fun QRCode( + data: String = QrData.text("https://github.com/avan1235/shin"), + onClose: () -> Unit, +) = ExampleSystemBarsScreen(onClose) { + Image( + painter = rememberQrCodePainter(data) { + shapes { + ball = QrBallShape.circle() + darkPixel = QrPixelShape.roundCorners() + frame = QrFrameShape.roundCorners(.25f) + } + colors { + dark = QrBrush.solid(Color.Black) + } + }, + contentDescription = "QR Code" + ) +} diff --git a/examples/src/commonMain/kotlin/in/procyk/compose/examples/Util.kt b/examples/src/commonMain/kotlin/in/procyk/compose/examples/Util.kt index fd7c6c1..b069281 100644 --- a/examples/src/commonMain/kotlin/in/procyk/compose/examples/Util.kt +++ b/examples/src/commonMain/kotlin/in/procyk/compose/examples/Util.kt @@ -16,13 +16,10 @@ import `in`.procyk.compose.util.SystemBarsScreen @Composable internal fun ExampleNoSystemBarsScreen( - visible: Boolean = true, - onVisibleChange: (Boolean) -> Unit = {}, + onClose: () -> Unit = {}, isCloseAvailable: Boolean = true, content: @Composable BoxScope.() -> Unit, ) { - if (!visible) return - NoSystemBarsScreen { Box( modifier = Modifier @@ -34,7 +31,7 @@ internal fun ExampleNoSystemBarsScreen( } if (isCloseAvailable) { NoBottomBarScreen { - CloseButton(onVisibleChange) + CloseButton(onClose) } } } @@ -42,13 +39,10 @@ internal fun ExampleNoSystemBarsScreen( @Composable internal fun ExampleSystemBarsScreen( - visible: Boolean = true, - onVisibleChange: (Boolean) -> Unit = {}, + onClose: () -> Unit = {}, isCloseAvailable: Boolean = true, content: @Composable BoxScope.() -> Unit, ) { - if (!visible) return - SystemBarsScreen( top = MaterialTheme.colorScheme.background, bottom = MaterialTheme.colorScheme.background, @@ -61,7 +55,7 @@ internal fun ExampleSystemBarsScreen( ) { content() } - if (isCloseAvailable) CloseButton(onVisibleChange) + if (isCloseAvailable) CloseButton(onClose) } } @@ -73,8 +67,8 @@ internal fun ExampleButton(name: String, onClick: () -> Unit) { } @Composable -private fun CloseButton(onVisibleChange: (Boolean) -> Unit) { - IconButton(onClick = { onVisibleChange(false) }) { +private fun CloseButton(onClose: () -> Unit) { + IconButton(onClick = { onClose() }) { Icon( imageVector = Icons.Default.Close, contentDescription = null,