From 4d97c810af6194959c77c17828578580f93ad7c6 Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Mon, 2 Oct 2023 23:01:02 +0200 Subject: [PATCH 1/2] Rearrange some composable and add missing Modifier default param --- .github/workflows/build.yml | 2 +- gradle/libs.versions.toml | 4 ++-- .../appyx/component/gridpuzzle/GridPuzzle.kt | 4 +--- .../bumble/puzzyx/composable/CallToActionScreen.kt | 4 +++- .../com/bumble/puzzyx/composable/EntryCard.kt | 14 +++++++------- .../com/bumble/puzzyx/composable/MessageBoard.kt | 13 +++++++++---- .../com/bumble/puzzyx/imageloader/ResourceImage.kt | 2 +- .../com/bumble/puzzyx/node/app/PuzzyxAppNode.kt | 4 ++-- .../com/bumble/puzzyx/node/puzzle1/Puzzle1Node.kt | 10 +++++----- 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed8ebcba..6afaa34e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: Build -on: [push] +on: [ push, pull_request, workflow_dispatch ] env: CI: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9d40b1cf..74fcdc03 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,7 +15,7 @@ composeBom = "2023.05.01" composeCompiler = "1.4.4" coroutines = "1.7.1" dependencyAnalysis = "1.13.1" -detekt = "1.21.0" +detekt = "1.22.0" junit5 = "5.8.2" jvmTarget = "17" kotlin = "1.8.10" @@ -96,7 +96,7 @@ plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version. plugin-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" } plugin-android = { module = "com.android.tools.build:gradle", version.ref = "agp" } -detekt-compose = "com.twitter.compose.rules:detekt:0.0.26" +detekt-compose = "io.nlopez.compose.rules:detekt:0.3.0" toolargetool = "com.gu.android:toolargetool:0.3.0" symbol-processing-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/appyx/component/gridpuzzle/GridPuzzle.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/appyx/component/gridpuzzle/GridPuzzle.kt index 8c6eb312..59d51258 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/appyx/component/gridpuzzle/GridPuzzle.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/appyx/component/gridpuzzle/GridPuzzle.kt @@ -16,6 +16,4 @@ class GridPuzzle( model = GridPuzzleModel(savedStateMap, gridRows, gridCols, pieces), motionController = { GridPuzzleVisualisation(it, defaultAnimationSpec) }, defaultAnimationSpec = defaultAnimationSpec -) { - -} +) diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/CallToActionScreen.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/CallToActionScreen.kt index 34008133..ec208358 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/CallToActionScreen.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/CallToActionScreen.kt @@ -11,7 +11,9 @@ import com.bumble.puzzyx.ui.appyx_dark import com.bumble.puzzyx.ui.appyx_yellow1 @Composable -fun CallToActionScreen(modifier: Modifier) { +fun CallToActionScreen( + modifier: Modifier = Modifier, +) { Box( modifier = modifier .fillMaxSize() diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/EntryCard.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/EntryCard.kt index 71621c6a..88c7e8f5 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/EntryCard.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/EntryCard.kt @@ -19,14 +19,14 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import com.bumble.puzzyx.model.Entry import com.bumble.puzzyx.imageloader.ResourceImage +import com.bumble.puzzyx.model.Entry import com.bumble.puzzyx.ui.colors @Composable fun EntryCard( - modifier: Modifier, - entry: Entry + entry: Entry, + modifier: Modifier = Modifier, ) { Box( modifier = modifier.clip(RoundedCornerShape(16.dp)) @@ -39,6 +39,7 @@ fun EntryCard( contentScale = entry.contentScale, modifier = Modifier.fillMaxSize().align(Alignment.Center) ) + is Entry.ComposableContent -> entry.content() } GitHubHeader( @@ -89,15 +90,14 @@ fun TextEntry( .fillMaxSize() .background(colors[colorIdx]) .padding(12.dp) - .padding(top = 36.dp) - , + .padding(top = 36.dp), ) } @Composable fun EntryCardSmall( - modifier: Modifier, - entry: Entry.Text + entry: Entry.Text, + modifier: Modifier = Modifier, ) { ScaledLayout( modifier = modifier.padding(8.dp), diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/MessageBoard.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/MessageBoard.kt index 3e6aa43c..7abee24b 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/MessageBoard.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/composable/MessageBoard.kt @@ -28,7 +28,9 @@ import math.noise3D import kotlin.math.cos @Composable -fun MessageBoard(modifier: Modifier) { +fun MessageBoard( + modifier: Modifier = Modifier, +) { ProgressBasedContent( millisPerFrame = 50000, ) { time -> @@ -37,7 +39,10 @@ fun MessageBoard(modifier: Modifier) { } @Composable -private fun MessageBoardContent(time: Float, modifier: Modifier) { +private fun MessageBoardContent( + time: Float, + modifier: Modifier = Modifier, +) { Box( modifier = modifier .fillMaxSize() @@ -72,8 +77,8 @@ private fun MessageBoardContent(time: Float, modifier: Modifier) { val entry = entriesShuffled[(y * maxY + x) % entriesShuffled.size] EntryCard( - modifier = Modifier.fillMaxSize(), - entry + entry = entry, + modifier = Modifier.fillMaxSize() ) } } diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/imageloader/ResourceImage.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/imageloader/ResourceImage.kt index 87a0aac7..871eeb95 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/imageloader/ResourceImage.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/imageloader/ResourceImage.kt @@ -31,7 +31,7 @@ fun ResourceImage( image?.let { Image( bitmap = it, - contentDescription = null, + contentDescription = contentDescription, modifier = modifier, contentScale = contentScale ) diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/app/PuzzyxAppNode.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/app/PuzzyxAppNode.kt index 852ecf91..356af7fa 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/app/PuzzyxAppNode.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/app/PuzzyxAppNode.kt @@ -67,7 +67,7 @@ class PuzzyxAppNode( initialTargets = listOf(screens.first()), savedStateMap = buildContext.savedStateMap, ), - motionController = { BackStackClipper(it, shape = { progress -> ClipShape(progress) }) } + motionController = { BackStackClipper(it, shape = { progress -> clipShape(progress) }) } ) ) : ParentNode( buildContext = buildContext, @@ -186,7 +186,7 @@ class PuzzyxAppNode( } @Composable -private fun ClipShape(progress: Float): Shape { +private fun clipShape(progress: Float): Shape { val screenSize = LocalScreenSize.current val density = LocalDensity.current val (meshMin, meshMax) = 15 to 25 diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/puzzle1/Puzzle1Node.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/puzzle1/Puzzle1Node.kt index fbd0684d..591c5b9d 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/puzzle1/Puzzle1Node.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/node/puzzle1/Puzzle1Node.kt @@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Alignment @@ -47,7 +46,6 @@ import com.bumble.puzzyx.model.puzzle1Entries import com.bumble.puzzyx.ui.LocalAutoPlayFlow import com.bumble.puzzyx.ui.appyx_dark import com.bumble.puzzyx.ui.colors -import org.jetbrains.compose.resources.ExperimentalResourceApi import kotlin.random.Random private val animationSpec = spring( @@ -79,7 +77,6 @@ class Puzzle1Node( appyxComponent = gridPuzzle ) { - @OptIn(ExperimentalResourceApi::class) override fun resolve(puzzlePiece: PuzzlePiece, buildContext: BuildContext): Node = node(buildContext) { modifier -> val colorIdx = rememberSaveable(puzzlePiece) { Random.nextInt(colors.size) } @@ -106,7 +103,8 @@ class Puzzle1Node( .fillMaxSize() .background(color), // TODO decide on the fate of this - entry = puzzle1Entries[puzzlePiece.entryId] as? Entry.Text ?: Entry.Text(Puzzle.PUZZLE1, "n/a") + entry = puzzle1Entries[puzzlePiece.entryId] as? Entry.Text + ?: Entry.Text(Puzzle.PUZZLE1, "n/a") ) } ) @@ -148,7 +146,9 @@ class Puzzle1Node( @OptIn(ExperimentalLayoutApi::class) @Composable - private fun Controls(modifier: Modifier) { + private fun Controls( + modifier: Modifier = Modifier, + ) { if (!LocalAutoPlayFlow.current.collectAsState().value) { FlowRow( modifier = modifier, From bc7252b8ef4050e00d3d21e6348cbc75cb3ddbb5 Mon Sep 17 00:00:00 2001 From: Manel Martos Date: Tue, 3 Oct 2023 06:59:56 +0200 Subject: [PATCH 2/2] Clean up --- .../com/bumble/puzzyx/ui/DottedMeshShape.kt | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/shared/src/commonMain/kotlin/com/bumble/puzzyx/ui/DottedMeshShape.kt b/shared/src/commonMain/kotlin/com/bumble/puzzyx/ui/DottedMeshShape.kt index 0318a464..62bd1152 100644 --- a/shared/src/commonMain/kotlin/com/bumble/puzzyx/ui/DottedMeshShape.kt +++ b/shared/src/commonMain/kotlin/com/bumble/puzzyx/ui/DottedMeshShape.kt @@ -10,7 +10,6 @@ import androidx.compose.ui.graphics.Shape import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.LayoutDirection import com.bumble.appyx.interactions.core.annotations.FloatRange -import com.bumble.appyx.interactions.core.ui.math.clamp import com.bumble.appyx.interactions.core.ui.math.lerpFloat import com.bumble.puzzyx.math.mapValueRange import kotlin.math.abs @@ -52,7 +51,7 @@ class DottedMeshShape( val appliedMeshSizeY = meshSizeY - 1f val halfMeshWidth = 0.5f * (width / appliedMeshSizeX) val halfMeshHeight = 0.5f * (height / appliedMeshSizeY) - val clampRadius = sqrt(halfMeshWidth * halfMeshWidth + halfMeshHeight * halfMeshHeight) + val maxOvalRadius = sqrt(halfMeshWidth * halfMeshWidth + halfMeshHeight * halfMeshHeight) val dots = Path().apply { for (y in 0 until meshSizeY) { for (x in 0 until meshSizeX) { @@ -64,23 +63,19 @@ class DottedMeshShape( y = lerpFloat(0f, height, v) ) - val radius = clamp( - x = mapValueRange( - value = progressDelayed - + (0.5f - abs(u - 0.5f)) - + (0.5f - abs(v - 0.5f)), - fromRangeMin = 0f, - fromRangeMax = 2f, - destRangeMin = 0f, - destRangeMax = maxRadius - ), - min = 0f, - max = clampRadius, + val radius = mapValueRange( + value = progressDelayed + + (0.5f - abs(u - 0.5f)) + + (0.5f - abs(v - 0.5f)), + fromRangeMin = 0f, + fromRangeMax = 2f, + destRangeMin = 0f, + destRangeMax = maxRadius ) // Clip with ovals when you see them, but stick with rectangles otherwise. This // helps make clipping faster and prevents dropping frames. - if (radius < clampRadius) { + if (radius < maxOvalRadius) { addOval( Rect( left = center.x - radius,