From 12b51e381eeabcc9115a8587782c624b3ba45976 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:55:39 +0000 Subject: [PATCH 1/4] Update dependency io.nlopez.compose.rules:detekt to v0.3.13 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index a0eedc8db78..0e5ec1c6743 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -60,7 +60,7 @@ allprojects { config.from(files("$rootDir/tools/detekt/detekt.yml")) } dependencies { - detektPlugins("io.nlopez.compose.rules:detekt:0.3.12") + detektPlugins("io.nlopez.compose.rules:detekt:0.3.13") } // KtLint From 000bcb448cff00c6afee6b6cc1d61ab30136d8bc Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 3 Apr 2024 11:34:49 +0200 Subject: [PATCH 2/4] Rework Modifier.applyIf. It was using `Modifier.composed` which is not good for performance and detekt is warning about this. --- .../impl/search/RoomListSearchView.kt | 11 ++++--- .../designsystem/modifiers/ApplyIf.kt | 32 ++++++++----------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/search/RoomListSearchView.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/search/RoomListSearchView.kt index a18dd6607fe..8190c8078e6 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/search/RoomListSearchView.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/search/RoomListSearchView.kt @@ -87,10 +87,13 @@ internal fun RoomListSearchView( ) { Column( modifier = modifier - .applyIf(state.isSearchActive, ifTrue = { - // Disable input interaction to underlying views - pointerInput(Unit) {} - }) + .applyIf( + condition = state.isSearchActive, + ifTrue = { + // Disable input interaction to underlying views + pointerInput(Unit) {} + } + ) ) { if (state.isSearchActive) { RoomListSearchContent( diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/modifiers/ApplyIf.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/modifiers/ApplyIf.kt index a18d0ef3ed1..3a4a433821e 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/modifiers/ApplyIf.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/modifiers/ApplyIf.kt @@ -16,30 +16,26 @@ package io.element.android.libraries.designsystem.modifiers -import android.annotation.SuppressLint -import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.composed import androidx.compose.ui.platform.debugInspectorInfo +import androidx.compose.ui.platform.inspectable /** * Applies the [ifTrue] modifier when the [condition] is true, [ifFalse] otherwise. */ -@SuppressLint("UnnecessaryComposedModifier") // It's actually necessary due to the `@Composable` lambdas fun Modifier.applyIf( condition: Boolean, - ifTrue: @Composable Modifier.() -> Modifier, - ifFalse: @Composable (Modifier.() -> Modifier)? = null -): Modifier = - composed( - inspectorInfo = debugInspectorInfo { - name = "applyIf" - value = condition - } - ) { - when { - condition -> then(ifTrue(Modifier)) - ifFalse != null -> then(ifFalse(Modifier)) - else -> this - } + ifTrue: Modifier.() -> Modifier, + ifFalse: (Modifier.() -> Modifier)? = null +): Modifier = this then inspectable( + inspectorInfo = debugInspectorInfo { + name = "applyIf" + value = condition } +) { + this then when { + condition -> ifTrue(Modifier) + ifFalse != null -> ifFalse(Modifier) + else -> Modifier + } +} From 07ca064ac48976a1a473ec1b1f50caefaaf96e21 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 3 Apr 2024 12:00:21 +0200 Subject: [PATCH 3/4] Supress warning `ModifierComposed` for autofill, there is a low risk of performance issue here. --- .../loginpassword/LoginPasswordView.kt | 28 +++++++++++-------- .../theme/components/TextField.kt | 1 + 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordView.kt b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordView.kt index 51ed3fcf6f3..926601bceea 100644 --- a/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordView.kt +++ b/features/login/impl/src/main/kotlin/io/element/android/features/login/impl/screens/loginpassword/LoginPasswordView.kt @@ -141,7 +141,7 @@ fun LoginPasswordView( // Submit Box( modifier = Modifier - .padding(horizontal = 16.dp) + .padding(horizontal = 16.dp) ) { ButtonColumnMolecule { Button( @@ -201,11 +201,14 @@ private fun LoginForm( .fillMaxWidth() .onTabOrEnterKeyFocusNext(focusManager) .testTag(TestTags.loginEmailUsername) - .autofill(autofillTypes = listOf(AutofillType.Username), onFill = { - val sanitized = it.sanitize() - loginFieldState = sanitized - eventSink(LoginPasswordEvents.SetLogin(sanitized)) - }), + .autofill( + autofillTypes = listOf(AutofillType.Username), + onFill = { + val sanitized = it.sanitize() + loginFieldState = sanitized + eventSink(LoginPasswordEvents.SetLogin(sanitized)) + } + ), placeholder = { Text(text = stringResource(CommonStrings.common_username)) }, @@ -247,11 +250,14 @@ private fun LoginForm( .fillMaxWidth() .onTabOrEnterKeyFocusNext(focusManager) .testTag(TestTags.loginPassword) - .autofill(autofillTypes = listOf(AutofillType.Password), onFill = { - val sanitized = it.sanitize() - passwordFieldState = sanitized - eventSink(LoginPasswordEvents.SetPassword(sanitized)) - }), + .autofill( + autofillTypes = listOf(AutofillType.Password), + onFill = { + val sanitized = it.sanitize() + passwordFieldState = sanitized + eventSink(LoginPasswordEvents.SetPassword(sanitized)) + } + ), onValueChange = { val sanitized = it.sanitize() passwordFieldState = sanitized diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/TextField.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/TextField.kt index f2c004d2caf..10fb4a29061 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/TextField.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/TextField.kt @@ -213,6 +213,7 @@ private fun TextFieldValueContentToPreview() { } } +@Suppress("ModifierComposed") @OptIn(ExperimentalComposeUiApi::class) fun Modifier.autofill(autofillTypes: List, onFill: (String) -> Unit) = composed { val autofillNode = AutofillNode(autofillTypes, onFill = onFill) From 25b46ee23028b0c08779ffaa3a812089343e939a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 17 May 2024 16:57:08 +0200 Subject: [PATCH 4/4] Suppress warning for ModifierComposed (detekt) --- .../element/android/libraries/designsystem/components/Bloom.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/Bloom.kt b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/Bloom.kt index 8558780a224..f8121ec500b 100644 --- a/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/Bloom.kt +++ b/libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/Bloom.kt @@ -168,6 +168,7 @@ data class BloomLayer( * @param bottomSoftEdgeAlpha The alpha value to apply to the bottom soft edge. * @param alpha The alpha value to apply to the bloom effect. */ +@SuppressWarnings("ModifierComposed") fun Modifier.bloom( hash: String?, background: Color, @@ -312,6 +313,7 @@ fun Modifier.bloom( * @param bottomSoftEdgeAlpha The alpha value to apply to the bottom soft edge. * @param alpha The alpha value to apply to the bloom effect. */ +@SuppressWarnings("ModifierComposed") fun Modifier.avatarBloom( avatarData: AvatarData, background: Color,