From e8fd8e88de311b99399b93237383da3ed28aca7f Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 3 Mar 2024 17:12:49 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 24 ++++++++++++------------ docs/index.md | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 3e04574..4e850bd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Calf is a library that allows you to easily create adaptive UIs for your Compose Multiplatform apps. -[![Kotlin](https://img.shields.io/badge/kotlin-1.9.21-blue.svg?logo=kotlin)](http://kotlinlang.org) +[![Kotlin](https://img.shields.io/badge/kotlin-1.9.22-blue.svg?logo=kotlin)](http://kotlinlang.org) [![MohamedRejeb](https://raw.githubusercontent.com/MohamedRejeb/MohamedRejeb/main/badges/mohamedrejeb.svg)](https://github.com/MohamedRejeb) [![Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) [![BuildPassing](https://shields.io/badge/build-passing-brightgreen)](https://github.com/MohamedRejeb/ksoup/actions) @@ -15,17 +15,17 @@ Calf stands for **C**ompose **A**daptive **L**ook & **F**eel ## Artifacts -| Artifact | Description | Platforms | Version | -|-----------------------|-------------------------------------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **calf-ui** | Adaptive UI components | Android, iOS, Desktop | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-ui)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-ui%22) | -| **calf-file-picker** | Native File Picker wrapper | Android, iOS, Desktop | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | -| **calf-permissions** | API that allows you to handle permissions | Android, iOS | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | -| **calf-geo** | API that allows you to access geolocation | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-navigation** | Native navigation wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-map** | Native Maps wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-media** | Video/Audio player | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-notification** | Notification manager | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-sf-symbols** | Apple SF Symbols icons | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| Artifact | Description | Platforms | Version | +|-----------------------|-------------------------------------------|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **calf-ui** | Adaptive UI components | Android, iOS, Desktop, Web | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-ui)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-ui%22) | +| **calf-file-picker** | Native File Picker wrapper | Android, iOS, Desktop, Web | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | +| **calf-permissions** | API that allows you to handle permissions | Android, iOS | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | +| **calf-geo** | API that allows you to access geolocation | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-navigation** | Native navigation wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-map** | Native Maps wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-media** | Video/Audio player | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-notification** | Notification manager | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-sf-symbols** | Apple SF Symbols icons | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | > The main focus for now is Android and iOS, but more Desktop components are coming that allows you to create adaptive UIs for Desktop as well (Windows, macOS, Linux) diff --git a/docs/index.md b/docs/index.md index 7716757..f09f1a2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,7 +3,7 @@ Calf is a library that allows you to easily create adaptive UIs for your Compose Multiplatform apps. -[![Kotlin](https://img.shields.io/badge/kotlin-1.9.21-blue.svg?logo=kotlin)](http://kotlinlang.org) +[![Kotlin](https://img.shields.io/badge/kotlin-1.9.22-blue.svg?logo=kotlin)](http://kotlinlang.org) [![MohamedRejeb](https://raw.githubusercontent.com/MohamedRejeb/MohamedRejeb/main/badges/mohamedrejeb.svg)](https://github.com/MohamedRejeb) [![Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) [![BuildPassing](https://shields.io/badge/build-passing-brightgreen)](https://github.com/MohamedRejeb/ksoup/actions) @@ -15,17 +15,17 @@ Calf stands for **C**ompose **A**daptive **L**ook & **F**eel ## Artifacts -| Artifact | Description | Platforms | Version | -|-----------------------|-------------------------------------------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **calf-ui** | Adaptive UI components | Android, iOS, Desktop | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-ui)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-ui%22) | -| **calf-file-picker** | Native File Picker wrapper | Android, iOS, Desktop | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | -| **calf-permissions** | API that allows you to handle permissions | Android, iOS | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | -| **calf-geo** | API that allows you to access geolocation | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-navigation** | Native navigation wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-map** | Native Maps wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-media** | Video/Audio player | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-notification** | Notification manager | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | -| **calf-sf-symbols** | Apple SF Symbols icons | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| Artifact | Description | Platforms | Version | +|-----------------------|-------------------------------------------|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **calf-ui** | Adaptive UI components | Android, iOS, Desktop, Web | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-ui)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-ui%22) | +| **calf-file-picker** | Native File Picker wrapper | Android, iOS, Desktop, Web | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | +| **calf-permissions** | API that allows you to handle permissions | Android, iOS | [![Maven Central](https://img.shields.io/maven-central/v/com.mohamedrejeb.calf/calf-file-picker)](https://search.maven.org/search?q=g:%22com.mohamedrejeb.calf%22%20AND%20a:%calf-file-picker%22) | +| **calf-geo** | API that allows you to access geolocation | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-navigation** | Native navigation wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-map** | Native Maps wrapper | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-media** | Video/Audio player | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-notification** | Notification manager | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | +| **calf-sf-symbols** | Apple SF Symbols icons | Coming soon... 🚧 🚧 | Coming soon... 🚧 🚧 | > The main focus for now is Android and iOS, but more Desktop components are coming that allows you to create adaptive UIs for Desktop as well (Windows, macOS, Linux) From 3d4e0bff7abacaef23327248c6db6c9339aec82c Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 3 Mar 2024 17:51:50 +0100 Subject: [PATCH 2/2] Add Web (JS Backed) support to file picker --- .../FilePickerLauncher.js.kt | 16 +++++ .../mohamedrejeb/calf/io/KmpFile.android.kt | 2 +- .../com.mohamedrejeb.calf/io/KmpFile.kt | 2 +- .../mohamedrejeb/calf/io/KmpFile.desktop.kt | 2 +- .../com.mohamedrejeb.calf/io/KmpFile.ios.kt | 2 +- .../com.mohamedrejeb.calf/io/KmpFile.js.kt | 30 +++++++--- .../com.mohamedrejeb.calf.sample/App.kt | 20 +++++-- .../screens/ImagePickerScreen.kt | 39 +++++++----- .../ui.theme/Color.kt | 4 +- .../ui.theme/Theme.kt | 60 ++++++++++--------- .../ui.theme/Typography.kt | 9 +-- 11 files changed, 116 insertions(+), 70 deletions(-) diff --git a/calf-file-picker/src/jsMain/kotlin/com.mohamedrejeb.calf.picker/FilePickerLauncher.js.kt b/calf-file-picker/src/jsMain/kotlin/com.mohamedrejeb.calf.picker/FilePickerLauncher.js.kt index fa1c821..24b9279 100644 --- a/calf-file-picker/src/jsMain/kotlin/com.mohamedrejeb.calf.picker/FilePickerLauncher.js.kt +++ b/calf-file-picker/src/jsMain/kotlin/com.mohamedrejeb.calf.picker/FilePickerLauncher.js.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import com.mohamedrejeb.calf.io.KmpFile import kotlinx.browser.document +import org.w3c.files.File @Composable actual fun rememberFilePickerLauncher( @@ -26,7 +27,22 @@ actual fun rememberFilePickerLauncher( fileInputElement.setAttribute("style", "display='none'") fileInputElement.setAttribute("type", "file") fileInputElement.setAttribute("name", "file") + + fileInputElement.setAttribute("accept", type.value.joinToString(", ")) + + if (selectionMode == FilePickerSelectionMode.Multiple) + fileInputElement.setAttribute("multiple", "true") + else + fileInputElement.removeAttribute("multiple") + + fileInputElement.addEventListener("change", { + val files: Array = fileInputElement.asDynamic().files + onResult(files.map { KmpFile(it) }) + fileDialogVisible = false + }) + js("fileInputElement.click();") + Unit }, ) diff --git a/calf-io/src/androidMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.android.kt b/calf-io/src/androidMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.android.kt index 3cc1721..a73d0a3 100644 --- a/calf-io/src/androidMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.android.kt +++ b/calf-io/src/androidMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.android.kt @@ -30,7 +30,7 @@ actual fun KmpFile.exists(context: PlatformContext): Boolean = * @return the content of the file as a byte array */ @Throws(FileNotFoundException::class) -actual fun KmpFile.readByteArray(context: PlatformContext): ByteArray { +actual suspend fun KmpFile.readByteArray(context: PlatformContext): ByteArray { val inputStream = context.contentResolver.openInputStream(uri) ?: throw FileNotFoundException("File not found") diff --git a/calf-io/src/commonMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.kt b/calf-io/src/commonMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.kt index d657bb6..b2c5987 100644 --- a/calf-io/src/commonMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.kt +++ b/calf-io/src/commonMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.kt @@ -21,7 +21,7 @@ expect fun KmpFile.exists(context: PlatformContext): Boolean * @param context The platform context. * @return The content of the file as a byte array. */ -expect fun KmpFile.readByteArray(context: PlatformContext): ByteArray +expect suspend fun KmpFile.readByteArray(context: PlatformContext): ByteArray /** * Reads the name of the KmpFile. diff --git a/calf-io/src/desktopMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.desktop.kt b/calf-io/src/desktopMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.desktop.kt index 3c35789..b69f715 100644 --- a/calf-io/src/desktopMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.desktop.kt +++ b/calf-io/src/desktopMain/kotlin/com/mohamedrejeb/calf/io/KmpFile.desktop.kt @@ -12,7 +12,7 @@ actual class KmpFile( actual fun KmpFile.exists(context: PlatformContext) = file.exists() -actual fun KmpFile.readByteArray(context: PlatformContext): ByteArray = file.readBytes() +actual suspend fun KmpFile.readByteArray(context: PlatformContext): ByteArray = file.readBytes() actual fun KmpFile.getName(context: PlatformContext): String? = file.name diff --git a/calf-io/src/iosMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.ios.kt b/calf-io/src/iosMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.ios.kt index c8d9575..5c28122 100644 --- a/calf-io/src/iosMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.ios.kt +++ b/calf-io/src/iosMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.ios.kt @@ -23,7 +23,7 @@ actual fun KmpFile.exists(context: PlatformContext): Boolean { } @OptIn(ExperimentalForeignApi::class) -actual fun KmpFile.readByteArray(context: PlatformContext): ByteArray { +actual suspend fun KmpFile.readByteArray(context: PlatformContext): ByteArray { val data = NSData.dataWithContentsOfURL(url) ?: return ByteArray(0) val byteArraySize: Int = if (data.length > Int.MAX_VALUE.toUInt()) Int.MAX_VALUE else data.length.toInt() return ByteArray(byteArraySize).apply { diff --git a/calf-io/src/jsMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.js.kt b/calf-io/src/jsMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.js.kt index e8687cb..b7d0563 100644 --- a/calf-io/src/jsMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.js.kt +++ b/calf-io/src/jsMain/kotlin/com.mohamedrejeb.calf/io/KmpFile.js.kt @@ -1,8 +1,13 @@ package com.mohamedrejeb.calf.io import com.mohamedrejeb.calf.core.PlatformContext +import org.khronos.webgl.ArrayBuffer +import org.khronos.webgl.Uint8Array +import org.khronos.webgl.get import org.w3c.files.File import org.w3c.files.FileReader +import kotlin.coroutines.resume +import kotlin.coroutines.suspendCoroutine /** * A typealias representing a file in the platform specific implementation @@ -13,17 +18,24 @@ actual class KmpFile( actual fun KmpFile.exists(context: PlatformContext) = true -actual fun KmpFile.readByteArray(context: PlatformContext): ByteArray { - val fileReader = FileReader() - fileReader.onload = { - val arrayBuffer = it.target.asDynamic().result as String - ByteArray(arrayBuffer.length) { index -> - arrayBuffer[index].code.toByte() +actual suspend fun KmpFile.readByteArray(context: PlatformContext): ByteArray = + suspendCoroutine { continuation -> + val fileReader = FileReader() + fileReader.readAsArrayBuffer(file) + fileReader.onloadend = { event -> + if (event.target.asDynamic().readyState == FileReader.DONE) { + val arrayBuffer: ArrayBuffer = event.target.asDynamic().result + val array = Uint8Array(arrayBuffer) + val byteArray = + ByteArray(array.length) { index -> + array[index] + } + continuation.resume(byteArray) + } else { + continuation.resume(ByteArray(0)) + } } } - fileReader.readAsText(file) - return fileReader.result as ByteArray -} actual fun KmpFile.getName(context: PlatformContext): String? = file.name diff --git a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/App.kt b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/App.kt index bd4e13e..b41a59d 100644 --- a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/App.kt +++ b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/App.kt @@ -1,13 +1,21 @@ package com.mohamedrejeb.calf.sample -import androidx.compose.runtime.* +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable import com.mohamedrejeb.calf.navigation.rememberNavController import com.mohamedrejeb.calf.sample.navigation.AppNavGraph -import com.mohamedrejeb.calf.sample.screens.theme.CalfTheme +import com.mohamedrejeb.calf.sample.ui.theme.CalfTheme @Composable -fun App() = CalfTheme { - val navController = rememberNavController() +fun App() = + CalfTheme { + val navController = rememberNavController() - AppNavGraph(navController = navController) -} \ No newline at end of file + Surface( + color = MaterialTheme.colorScheme.surface, + contentColor = MaterialTheme.colorScheme.onSurface, + ) { + AppNavGraph(navController = navController) + } + } diff --git a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/screens/ImagePickerScreen.kt b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/screens/ImagePickerScreen.kt index 34017e3..3ea1237 100644 --- a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/screens/ImagePickerScreen.kt +++ b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/screens/ImagePickerScreen.kt @@ -24,6 +24,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -37,10 +38,12 @@ import com.mohamedrejeb.calf.picker.FilePickerSelectionMode import com.mohamedrejeb.calf.picker.rememberFilePickerLauncher import com.mohamedrejeb.calf.picker.toImageBitmap import com.mohamedrejeb.calf.ui.toggle.AdaptiveSwitch +import kotlinx.coroutines.launch @Composable fun ImagePickerScreen(navigateBack: () -> Unit) { val context = LocalPlatformContext.current + val scope = rememberCoroutineScope() var imageBitmaps by remember { mutableStateOf>(emptyList()) @@ -52,15 +55,17 @@ fun ImagePickerScreen(navigateBack: () -> Unit) { type = FilePickerFileType.Image, selectionMode = FilePickerSelectionMode.Single, onResult = { files -> - imageBitmaps = - files.mapNotNull { - try { - it.readByteArray(context).toImageBitmap() - } catch (e: Exception) { - e.printStackTrace() - null + scope.launch { + imageBitmaps = + files.mapNotNull { + try { + it.readByteArray(context).toImageBitmap() + } catch (e: Exception) { + e.printStackTrace() + null + } } - } + } }, ) @@ -69,15 +74,17 @@ fun ImagePickerScreen(navigateBack: () -> Unit) { type = FilePickerFileType.Image, selectionMode = FilePickerSelectionMode.Multiple, onResult = { files -> - imageBitmaps = - files.mapNotNull { - try { - it.readByteArray(context).toImageBitmap() - } catch (e: Exception) { - e.printStackTrace() - null + scope.launch { + imageBitmaps = + files.mapNotNull { + try { + it.readByteArray(context).toImageBitmap() + } catch (e: Exception) { + e.printStackTrace() + null + } } - } + } }, ) diff --git a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Color.kt b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Color.kt index 5ace6d2..af7a1cf 100644 --- a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Color.kt +++ b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Color.kt @@ -1,5 +1,5 @@ -package com.mohamedrejeb.calf.sample.screens.theme +package com.mohamedrejeb.calf.sample.ui.theme import androidx.compose.ui.graphics.Color -val Blue400 = Color(0xFF4572E8) \ No newline at end of file +val Blue400 = Color(0xFF4572E8) diff --git a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Theme.kt b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Theme.kt index cf4ba1d..efe682b 100644 --- a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Theme.kt +++ b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Theme.kt @@ -1,4 +1,4 @@ -package com.mohamedrejeb.calf.sample.screens.theme +package com.mohamedrejeb.calf.sample.ui.theme import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme @@ -7,42 +7,44 @@ import androidx.compose.material3.lightColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color -private val DarkColorScheme = darkColorScheme( - primary = Blue400, - primaryContainer = Blue400, - onPrimaryContainer = Color.White, - background = Color.Black, - surface = Color.Black, - onPrimary = Color.White, - onBackground = Color.White, - onSurface = Color.White, -) +private val DarkColorScheme = + darkColorScheme( + primary = Blue400, + primaryContainer = Blue400, + onPrimaryContainer = Color.White, + background = Color.Black, + surface = Color.Black, + onPrimary = Color.White, + onBackground = Color.White, + onSurface = Color.White, + ) -private val LightColorScheme = lightColorScheme( - primary = Blue400, - primaryContainer = Blue400, - onPrimaryContainer = Color.White, - background = Color.White, - surface = Color.White, - onPrimary = Color.White, - onBackground = Color.Black, - onSurface = Color.Black, -) +private val LightColorScheme = + lightColorScheme( + primary = Blue400, + primaryContainer = Blue400, + onPrimaryContainer = Color.White, + background = Color.White, + surface = Color.White, + onPrimary = Color.White, + onBackground = Color.Black, + onSurface = Color.Black, + ) @Composable internal fun CalfTheme( darkTheme: Boolean = isSystemInDarkTheme(), - content: @Composable () -> Unit + content: @Composable () -> Unit, ) { - val colorScheme = if (darkTheme) { - DarkColorScheme - } else { - LightColorScheme - } + val colorScheme = + if (darkTheme) + DarkColorScheme + else + LightColorScheme MaterialTheme( colorScheme = colorScheme, typography = Typography, - content = content + content = content, ) -} \ No newline at end of file +} diff --git a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Typography.kt b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Typography.kt index a2c7feb..f338a18 100644 --- a/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Typography.kt +++ b/sample/common/src/commonMain/kotlin/com.mohamedrejeb.calf.sample/ui.theme/Typography.kt @@ -1,8 +1,9 @@ -package com.mohamedrejeb.calf.sample.screens.theme +package com.mohamedrejeb.calf.sample.ui.theme import androidx.compose.material3.Typography -val Typography = Typography( +val Typography = + Typography( /* Other default text styles to override button = TextStyle( fontFamily = FontFamily.Default, @@ -14,5 +15,5 @@ val Typography = Typography( fontWeight = FontWeight.Normal, fontSize = 12.sp ) - */ -) \ No newline at end of file + */ + )