From 2841b5288920af5bcd278367cb7a548c93bd36e6 Mon Sep 17 00:00:00 2001 From: Md Sadique Inam Date: Tue, 9 Apr 2024 10:17:07 +0530 Subject: [PATCH] Refactor IconButton and clean up imports in TextField Removed unnecessary imports from the TextField component and refactored IconButton usage. This includes removing the IconButton import in TextField and defining a new PMCIconButton function in the Button component. This improvement aids in reducing clutter and enhancing code readability. --- .../commonMain/kotlin/ui/components/Button.kt | 20 +++++++++++++++++++ .../kotlin/ui/components/TextField.kt | 9 ++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/commonCompose/src/commonMain/kotlin/ui/components/Button.kt b/commonCompose/src/commonMain/kotlin/ui/components/Button.kt index e89b703..7f53339 100644 --- a/commonCompose/src/commonMain/kotlin/ui/components/Button.kt +++ b/commonCompose/src/commonMain/kotlin/ui/components/Button.kt @@ -1,10 +1,15 @@ package ui.components +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.RowScope import androidx.compose.material3.Button import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.IconButton +import androidx.compose.material3.IconButtonColors +import androidx.compose.material3.IconButtonDefaults import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.PointerIcon import androidx.compose.ui.input.pointer.pointerHoverIcon @@ -53,4 +58,19 @@ fun PMCTextButton( content() } } +} + +@Composable +fun PMCIconButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + content: @Composable () -> Unit +) { + IconButton( + onClick = onClick, + modifier = modifier.pointerHoverIcon(icon = PointerIcon.Hand), + enabled = enabled, + content = content + ) } \ No newline at end of file diff --git a/commonCompose/src/commonMain/kotlin/ui/components/TextField.kt b/commonCompose/src/commonMain/kotlin/ui/components/TextField.kt index 2a6e363..f3cfb62 100644 --- a/commonCompose/src/commonMain/kotlin/ui/components/TextField.kt +++ b/commonCompose/src/commonMain/kotlin/ui/components/TextField.kt @@ -10,7 +10,6 @@ import androidx.compose.material.icons.filled.Error import androidx.compose.material.icons.outlined.Visibility import androidx.compose.material.icons.outlined.VisibilityOff import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text @@ -25,15 +24,12 @@ import androidx.compose.ui.input.key.KeyEventType import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.input.key.type -import androidx.compose.ui.input.pointer.PointerIcon -import androidx.compose.ui.input.pointer.pointerHoverIcon import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.VisualTransformation import org.jetbrains.compose.resources.stringResource import pdnsmanager.commoncompose.generated.resources.Res -import pdnsmanager.commoncompose.generated.resources.error import pdnsmanager.commoncompose.generated.resources.hide_password import pdnsmanager.commoncompose.generated.resources.show_password @@ -58,7 +54,7 @@ fun PMCOutlinedTextField( val focusManager = LocalFocusManager.current OutlinedTextField( modifier = modifier.onPreviewKeyEvent { - if (it.key == Key.Tab && it.type == KeyEventType.KeyDown){ + if (it.key == Key.Tab && it.type == KeyEventType.KeyDown) { focusManager.moveFocus(FocusDirection.Down) true } else { @@ -145,7 +141,7 @@ fun PMCPasswordTextField( isError = isError, error = error, trailingIcon = { - IconButton( + PMCIconButton( onClick = { if (visibility.value == FieldVisibility.Hidden) { visibility.value = FieldVisibility.Visible @@ -153,7 +149,6 @@ fun PMCPasswordTextField( visibility.value = FieldVisibility.Hidden } }, - modifier = Modifier.pointerHoverIcon(PointerIcon.Hand) ) { visibility.value.icon() }