Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
avan1235 committed Mar 12, 2024
1 parent 1d98b7a commit 0f683e4
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 32 deletions.
17 changes: 10 additions & 7 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
1 change: 1 addition & 0 deletions examples/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencyResolutionManagement {
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
mavenLocal()
}
}

Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Example?>(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 }
}
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"),
;
}
Original file line number Diff line number Diff line change
@@ -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"
)
}
18 changes: 6 additions & 12 deletions examples/src/commonMain/kotlin/in/procyk/compose/examples/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,21 +31,18 @@ internal fun ExampleNoSystemBarsScreen(
}
if (isCloseAvailable) {
NoBottomBarScreen {
CloseButton(onVisibleChange)
CloseButton(onClose)
}
}
}
}

@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,
Expand All @@ -61,7 +55,7 @@ internal fun ExampleSystemBarsScreen(
) {
content()
}
if (isCloseAvailable) CloseButton(onVisibleChange)
if (isCloseAvailable) CloseButton(onClose)
}
}

Expand All @@ -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,
Expand Down

0 comments on commit 0f683e4

Please sign in to comment.