Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make session module Compose Multiplatform #4

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app-ios-shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ kotlin {
api(projects.core.data)
api(projects.core.ui)
api(projects.feature.contributors)
api(projects.feature.sessions)
implementation(libs.kotlinxCoroutinesCore)
}
}
Expand Down
8 changes: 8 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ gradlePlugin {
id = "droidkaigi.primitive.kmp.compose"
implementationClass = "io.github.droidkaigi.confsched.primitive.KmpComposePlugin"
}
register("kotlinMppRoborazzi") {
id = "droidkaigi.primitive.kmp.roborazzi"
implementationClass = "io.github.droidkaigi.confsched.primitive.KmpRoborazziPlugin"
}
register("kotlinMppKtorfit") {
id = "droidkaigi.primitive.kmp.ktorfit"
implementationClass = "io.github.droidkaigi.confsched.primitive.KmpKtorfitPlugin"
Expand Down Expand Up @@ -122,5 +126,9 @@ gradlePlugin {
id = "droidkaigi.convention.androidfeature"
implementationClass = "io.github.droidkaigi.confsched.convention.AndroidFeaturePlugin"
}
register("kmpFeature") {
id = "droidkaigi.convention.kmpfeature"
implementationClass = "io.github.droidkaigi.confsched.convention.KmpFeaturePlugin"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AndroidFeaturePlugin : Plugin<Project> {
}
}

private fun Project.buildComposeMetricsParameters(): List<String> {
fun Project.buildComposeMetricsParameters(): List<String> {
val metricParameters = mutableListOf<String>()
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
val relativePath = projectDir.relativeTo(rootDir)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.github.droidkaigi.confsched.convention

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

class KmpFeaturePlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("droidkaigi.primitive.kmp")
apply("droidkaigi.primitive.kmp.android")
apply("droidkaigi.primitive.kmp.ios")
apply("droidkaigi.primitive.kmp.compose")
apply("droidkaigi.primitive.kmp.android.hilt")
apply("droidkaigi.primitive.kmp.roborazzi")
apply("droidkaigi.primitive.detekt")
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + buildComposeMetricsParameters()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ class KmpAndroidHiltPlugin : Plugin<Project> {
implementation(libs.library("androidxFragment"))
}
}
sourceSets.getByName("androidUnitTest") {
val kspConfiguration = configurations["kspAndroidTest"] // not AndroidAndroidTest
kspConfiguration.dependencies.add(
libs.library("daggerHiltAndroidCompiler").let {
DefaultExternalModuleDependency(
it.module.group,
it.module.name,
it.versionConstraint.requiredVersion
)
}
)
dependencies {
implementation(libs.library("daggerHiltAndroidTesting"))
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class KmpPlugin : Plugin<Project> {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform")

}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java) {
kotlinOptions.jvmTarget = "11"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.github.droidkaigi.confsched.primitive

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency
import org.gradle.kotlin.dsl.get

@Suppress("unused")
class KmpRoborazziPlugin : Plugin<Project> {
override fun apply(project: Project) {
with(project) {
with(pluginManager) {
apply("io.github.takahirom.roborazzi")
apply("com.google.devtools.ksp")
}
android {
testOptions {
unitTests {
all {
it.jvmArgs("-noverify")
it.maxParallelForks = Runtime.getRuntime().availableProcessors()
// -Pscreenshot to filter screenshot tests
it.useJUnit {
if (project.hasProperty("screenshot")) {
project.logger.lifecycle("Screenshot tests are included")
includeCategories("io.github.droidkaigi.confsched.testing.category.ScreenshotTests")
}
}
}
}
}
}
kotlin {
sourceSets.getByName("androidUnitTest") {
val kspConfiguration = configurations["kspAndroid"]
kspConfiguration.dependencies.add(
libs.library("showkaseProcessor").let {
DefaultExternalModuleDependency(
it.module.group,
it.module.name,
it.versionConstraint.requiredVersion
)
}
)
dependencies {
implementation(libs.library("showkaseRuntime"))
implementation(libs.library("androidxTestEspressoEspressoCore"))
implementation(libs.library("junit"))
implementation(libs.library("robolectric"))
implementation(libs.library("androidxTestExtJunit"))
implementation(libs.library("roborazzi"))
implementation(libs.library("roborazziCompose"))
}
}
}
}
}
}
8 changes: 8 additions & 0 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ plugins {

android.namespace = "io.github.droidkaigi.confsched.core.designsystem"

kotlin {
sourceSets {
commonMain {
dependencies {}
}
}
}

android {
sourceSets {
named("main") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package androidx.compose.ui.tooling.preview

@Retention(AnnotationRetention.BINARY)
@Target(
AnnotationTarget.ANNOTATION_CLASS,
AnnotationTarget.FUNCTION
)
@Repeatable
annotation class Preview(
val name: String = "",
val group: String = "",
val apiLevel: Int = -1,
val widthDp: Int = -1,
val heightDp: Int = -1,
val locale: String = "",
val fontScale: Float = 1f,
val showSystemUi: Boolean = false,
val showBackground: Boolean = false,
val backgroundColor: Long = 0,
val uiMode: Int = 0,
val device: String = "",
val wallpaper: Int = -1,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.droidkaigi.confsched.designsystem.preview

import android.content.res.Configuration
import androidx.annotation.VisibleForTesting
import androidx.compose.ui.tooling.preview.Preview
import kotlin.annotation.AnnotationRetention.SOURCE
Expand All @@ -25,12 +24,13 @@ object MultiThemePreviewDefinition {

object DarkMode {
const val Name = "DarkMode"
const val UiMode = Configuration.UI_MODE_NIGHT_YES
// FIXME: We can't use this in KMP
// const val UiMode = Configuration.UI_MODE_NIGHT_YES
}

object LightMode {
const val Name = "LightMode"
const val UiMode = Configuration.UI_MODE_NIGHT_NO
// const val UiMode = Configuration.UI_MODE_NIGHT_NO
}
}

Expand All @@ -40,12 +40,12 @@ object MultiThemePreviewDefinition {
@Preview(
name = MultiThemePreviewDefinition.LightMode.Name,
group = MultiThemePreviewDefinition.Group,
uiMode = MultiThemePreviewDefinition.LightMode.UiMode,
// uiMode = MultiThemePreviewDefinition.LightMode.UiMode,
)
@Preview(
name = MultiThemePreviewDefinition.DarkMode.Name,
group = MultiThemePreviewDefinition.Group,
uiMode = MultiThemePreviewDefinition.DarkMode.UiMode,
// uiMode = MultiThemePreviewDefinition.DarkMode.UiMode,
)
annotation class MultiThemePreviews

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.droidkaigi.confsched.ui

import android.content.res.Configuration
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalConfiguration

@Composable
actual fun getScreenSizeInfo(): ScreenInfo {
// val density = LocalDensity.current
// val config = LocalConfiguration.current
// val hDp = config.screenHeightDp.dp
// val wDp = config.screenWidthDp.dp
return ScreenInfo(
isPort = LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.droidkaigi.confsched.ui

import androidx.compose.runtime.Composable

data class ScreenInfo(val isPort: Boolean)

@Composable
expect fun getScreenSizeInfo(): ScreenInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.droidkaigi.confsched.ui

import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo

@OptIn(ExperimentalComposeUiApi::class)
@Composable
actual fun getScreenSizeInfo(): ScreenInfo {
val density = LocalDensity.current
val config = LocalWindowInfo.current.containerSize
return ScreenInfo(
isPort = config.height > config.width
)
}
34 changes: 23 additions & 11 deletions feature/sessions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
plugins {
id("droidkaigi.convention.androidfeature")
id("droidkaigi.convention.kmpfeature")
}

android.namespace = "io.github.droidkaigi.confsched.feature.sessions"
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(projects.core.designsystem)
implementation(projects.core.ui)
implementation(projects.core.model)

dependencies {
implementation(projects.core.designsystem)
implementation(projects.core.ui)
implementation(projects.core.model)
implementation(libs.animation.graphics.android)
testImplementation(projects.core.testing)

implementation(libs.composeHiltNavigtation)
implementation(libs.composeMaterialIcon)
implementation(libs.composeShimmer)
implementation(libs.composeNavigation)
implementation(compose.materialIconsExtended)
}
}
androidTarget {
dependencies {
implementation(libs.composeMaterialWindowSize)
}
}
androidUnitTest {
dependencies {
implementation(projects.core.testing)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.droidkaigi.confsched.sessions

import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
Expand All @@ -12,11 +11,11 @@ import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material.Text
import androidx.compose.material3.Button
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
Expand All @@ -26,7 +25,6 @@ import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.testTag
Expand All @@ -50,6 +48,7 @@ import io.github.droidkaigi.confsched.ui.UserMessageStateHolder
import io.github.droidkaigi.confsched.ui.UserMessageStateHolderImpl
import io.github.droidkaigi.confsched.ui.compositionlocal.FakeClock
import io.github.droidkaigi.confsched.ui.compositionlocal.LocalClock
import io.github.droidkaigi.confsched.ui.getScreenSizeInfo
import kotlinx.collections.immutable.toPersistentMap

const val timetableScreenRoute = "timetable"
Expand All @@ -72,7 +71,7 @@ fun NavGraphBuilder.nestedSessionScreens(

fun NavController.navigateTimetableScreen() {
navigate(timetableScreenRoute) {
popUpTo(id = graph.findStartDestination().id) {
popUpTo(route = checkNotNull(graph.findStartDestination().route)) {
saveState = true
}
launchSingleTop = true
Expand Down Expand Up @@ -156,7 +155,7 @@ private fun TimetableScreen(
val density = LocalDensity.current
val layoutDirection = LocalLayoutDirection.current
val gradientEndRatio =
if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_PORTRAIT) {
if (getScreenSizeInfo().isPort) {
0.2f
} else {
0.5f
Expand Down
Loading