Skip to content

Commit

Permalink
Set up Compose rules check
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored and egorikftp committed Jul 22, 2024
1 parent cc07a02 commit fba80d2
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 38 deletions.
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ allprojects {
// Sources copied from AndroidX Compose
targetExclude("src/main/kotlin/androidx/**")
ktlint(rootProject.libs.ktlint.get().version)
.customRuleSets(
listOf(
rootProject.libs.composeRules.get().toString(),
),
)
}
kotlinGradle {
ktlint(rootProject.libs.ktlint.get().version)
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tiamat-koin = "io.github.composegears:tiamat-koin:1.1.0-rc02"
xpp3 = "org.ogce:xpp3:1.1.6"

ktlint = "com.pinterest.ktlint:ktlint-cli:1.3.1"
composeRules = "io.nlopez.compose.rules:ktlint:0.4.5"

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import io.github.composegears.valkyrie.ui.screen.settings.SettingsScreen
import org.koin.compose.koinInject

@Composable
fun ValkyriePlugin() {
fun ValkyriePlugin(
modifier: Modifier = Modifier,
) {
val inMemorySettings = koinInject<InMemorySettings>()

val navController = rememberNavController(
Expand Down Expand Up @@ -52,7 +54,7 @@ fun ValkyriePlugin() {
)

Navigation(
modifier = Modifier.fillMaxSize(),
modifier = modifier.fillMaxSize(),
navController = navController,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import io.github.composegears.valkyrie.ui.foundation.theme.PreviewTheme

@Composable
fun InputField(
modifier: Modifier = Modifier,
caption: String,
value: String,
isError: Boolean = false,
tooltipValue: AnnotatedString,
modifier: Modifier = Modifier,
isError: Boolean = false,
supportingText: @Composable (() -> Unit)? = null,
onValueChange: (String) -> Unit,
) {
Expand Down Expand Up @@ -59,8 +59,8 @@ fun InputField(

@Composable
fun InputTextField(
modifier: Modifier = Modifier,
value: String,
modifier: Modifier = Modifier,
isError: Boolean = false,
supportingText: @Composable (() -> Unit)? = null,
onValueChange: (String) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import io.github.composegears.valkyrie.ui.foundation.theme.PreviewTheme

@Composable
fun PixelGrid(
gridSize: Dp = 8.dp,
modifier: Modifier = Modifier,
gridSize: Dp = 8.dp,
) {
Canvas(modifier = modifier) {
val canvasWidth = size.width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp

@Composable
fun VerticalSpacer(dp: Dp) = Spacer(modifier = Modifier.height(dp))
fun VerticalSpacer(
dp: Dp,
modifier: Modifier = Modifier,
) {
Spacer(modifier = modifier.height(dp))
}

@Composable
fun HorizontalSpacer(dp: Dp) = Spacer(modifier = Modifier.width(dp))
fun HorizontalSpacer(
dp: Dp,
modifier: Modifier = Modifier,
) {
Spacer(modifier = modifier.width(dp))
}

@Composable
fun RowScope.WeightSpacer(weight: Float = 1f) = Spacer(modifier = Modifier.weight(weight))
fun RowScope.WeightSpacer(
modifier: Modifier = Modifier,
weight: Float = 1f,
) {
Spacer(modifier = modifier.weight(weight))
}

@Composable
fun ColumnScope.WeightSpacer(weight: Float = 1f) = Spacer(modifier = Modifier.weight(weight))
fun ColumnScope.WeightSpacer(
modifier: Modifier = Modifier,
weight: Float = 1f,
) {
Spacer(modifier = modifier.weight(weight))
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import io.github.composegears.valkyrie.ui.foundation.icons.ValkyrieIcons

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Tooltip(text: AnnotatedString) {
fun Tooltip(
text: AnnotatedString,
modifier: Modifier = Modifier,
) {
TooltipBox(
modifier = modifier,
positionProvider = TooltipDefaults.rememberRichTooltipPositionProvider(),
tooltip = {
RichTooltip(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import io.github.composegears.valkyrie.ui.foundation.icons.ValkyrieIcons
import io.github.composegears.valkyrie.ui.foundation.theme.PreviewTheme

@Composable
fun TopAppBar(content: @Composable RowScope.() -> Unit) {
fun TopAppBar(
modifier: Modifier = Modifier,
content: @Composable RowScope.() -> Unit,
) {
Row(
modifier = Modifier
modifier = modifier
.fillMaxWidth()
.height(56.dp)
.padding(horizontal = 8.dp),
Expand All @@ -36,43 +39,62 @@ fun TopAppBar(content: @Composable RowScope.() -> Unit) {
}

@Composable
fun BackAction(onBack: () -> Unit) {
fun BackAction(
modifier: Modifier = Modifier,
onBack: () -> Unit,
) {
IconButton(
modifier = modifier,
onClick = onBack,
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowLeft,
)
}

@Composable
fun AppBarTitle(title: String) {
fun AppBarTitle(
title: String,
modifier: Modifier = Modifier,
) {
Text(
modifier = Modifier.padding(horizontal = 8.dp),
modifier = modifier.padding(horizontal = 8.dp),
text = title,
maxLines = 1,
style = MaterialTheme.typography.titleSmall,
)
}

@Composable
fun ClearAction(onClear: () -> Unit) {
fun ClearAction(
modifier: Modifier = Modifier,
onClear: () -> Unit,
) {
IconButton(
modifier = modifier,
imageVector = Icons.Default.Clear,
onClick = onClear,
)
}

@Composable
fun CopyAction(onCopy: () -> Unit) {
fun CopyAction(
modifier: Modifier = Modifier,
onCopy: () -> Unit,
) {
IconButton(
modifier = modifier,
imageVector = ValkyrieIcons.ContentCopy,
onClick = onCopy,
iconSize = 18.dp,
)
}

@Composable
fun SettingsAction(openSettings: () -> Unit) {
fun SettingsAction(
modifier: Modifier = Modifier,
openSettings: () -> Unit,
) {
IconButton(
modifier = modifier,
imageVector = Icons.Default.Settings,
onClick = openSettings,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.composegears.valkyrie.ui.foundation.dnd
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalInspectionMode
import io.github.composegears.valkyrie.ui.foundation.dnd.DragAndDropHandlerState.Companion.dragging
Expand Down Expand Up @@ -46,10 +47,11 @@ fun rememberMultiSelectDragAndDropHandler(onDrop: (List<Path>) -> Unit): DragAnd
} else {
val localComponent = LocalComponent.current
var state by rememberMutableState { DragAndDropHandlerState() }
val latestOnDrop by rememberUpdatedState(onDrop)

DisposableEffect(Unit) {
val listener = SimpleDropTargetListener(
onDrop = onDrop,
onDrop = latestOnDrop,
onDragEnter = { state = state.dragging() },
onDragExit = { state = state.notDragging() },
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("ktlint:compose:compositionlocal-allowlist")

package io.github.composegears.valkyrie.ui.foundation.theme

import androidx.compose.runtime.compositionLocalOf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private fun IconPackConversionUi(
Column(modifier = Modifier.fillMaxSize()) {
TopAppBar {
if (state is BatchFilesProcessing) {
ClearAction(onReset)
ClearAction(onClear = onReset)
}
AppBarTitle(title = "IconPack generation")
WeightSpacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ import kotlin.io.path.Path
@Composable
fun BatchProcessingState(
icons: List<BatchIcon>,
modifier: Modifier = Modifier,
onDeleteIcon: (IconName) -> Unit,
onUpdatePack: (BatchIcon, String) -> Unit,
onPreviewClick: (IconName) -> Unit,
onRenameIcon: (BatchIcon, IconName) -> Unit,
modifier: Modifier = Modifier,
) {
LazyVerticalGrid(
modifier = modifier.fillMaxSize(),
Expand Down Expand Up @@ -89,12 +89,12 @@ fun BatchProcessingState(

@Composable
private fun ValidIconItem(
modifier: Modifier = Modifier,
icon: BatchIcon.Valid,
onUpdatePack: (BatchIcon, String) -> Unit,
onPreview: (IconName) -> Unit,
onDeleteIcon: (IconName) -> Unit,
onRenameIcon: (BatchIcon, IconName) -> Unit,
modifier: Modifier = Modifier,
) {
Card(modifier = modifier.fillMaxWidth()) {
Box {
Expand Down Expand Up @@ -174,8 +174,8 @@ private fun ValidIconItem(

@Composable
private fun BrokenIconItem(
modifier: Modifier = Modifier,
broken: BatchIcon.Broken,
modifier: Modifier = Modifier,
onDelete: (IconName) -> Unit,
) {
Card(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ import kotlin.io.path.isRegularFile
import kotlinx.coroutines.launch

@Composable
fun IconPackPickerState(onPickerEvent: (PickerEvent) -> Unit) {
fun IconPackPickerState(
modifier: Modifier = Modifier,
onPickerEvent: (PickerEvent) -> Unit,
) {
val scope = rememberCoroutineScope()

val multipleFilePicker = rememberMultipleFilesPicker()
val directoryPicker = rememberDirectoryPicker()

Box(
modifier = Modifier.fillMaxSize(),
modifier = modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
SelectableState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import io.github.composegears.valkyrie.ui.foundation.rememberMutableState
import io.github.composegears.valkyrie.ui.foundation.theme.PreviewTheme

@Composable
fun IconPreviewBox(painter: Painter) {
fun IconPreviewBox(
painter: Painter,
modifier: Modifier = Modifier,
) {
var bgType by rememberMutableState { BgType.PixelGrid }

Box(
modifier = Modifier
modifier = modifier
.size(56.dp)
.clip(RoundedCornerShape(8.dp))
.pointerInput(Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private fun IconPackModeSetupUI(
) {
Column {
TopAppBar {
BackAction(onBack)
BackAction(onBack = onBack)
AppBarTitle("IconPack setup")
}
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ private fun PluginUI(
AppBarTitle(title = "Simple conversion")
WeightSpacer()
if (content != null) {
ClearAction(onClear)
CopyAction(onCopy)
ClearAction(onClear = onClear)
CopyAction(onCopy = onCopy)
}
SettingsAction(openSettings = openSettings)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private fun SimpleModeSetupScreenUI(
) {
Column {
TopAppBar {
BackAction(onBack)
BackAction(onBack = onBack)
AppBarTitle(title = "Simple mode setup")
}
VerticalSpacer(36.dp)
Expand Down
Loading

0 comments on commit fba80d2

Please sign in to comment.