From 55d9ec43279ba8ddce2ec7ac8f6f2bb1ad658222 Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Thu, 9 Feb 2023 19:39:17 +0400 Subject: [PATCH] Fix DateUnixTextFields Moved to a separate file Fixed text color --- .../epoch/component/DateUnixTextFields.kt | 78 +++++++++++++++++++ .../unitto/feature/epoch/component/TopPart.kt | 51 ------------ 2 files changed, 78 insertions(+), 51 deletions(-) create mode 100644 feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/DateUnixTextFields.kt diff --git a/feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/DateUnixTextFields.kt b/feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/DateUnixTextFields.kt new file mode 100644 index 00000000..b89dc02b --- /dev/null +++ b/feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/DateUnixTextFields.kt @@ -0,0 +1,78 @@ +/* + * Unitto is a unit converter for Android + * Copyright (c) 2023 Elshan Agaev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.sadellie.unitto.feature.epoch.component + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.text.BasicTextField +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.platform.LocalTextInputService +import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.text.input.VisualTransformation +import androidx.compose.ui.text.style.TextAlign +import com.sadellie.unitto.core.ui.theme.NumbersTextStyleDisplayMedium + +@Composable +internal fun DateUnixTextFields( + fromTextFieldValue: TextFieldValue, + onCursorChange: (TextFieldValue) -> Unit, + fromSupportText: String, + toTextValue: String, + toSupportText: String, + visualTransformation: VisualTransformation, + fromPlaceholderText: String, + toPlaceholderText: String +) { + Column { + CompositionLocalProvider( + LocalTextInputService provides null + ) { + BasicTextField( + value = fromTextFieldValue, + onValueChange = onCursorChange, + textStyle = NumbersTextStyleDisplayMedium.copy( + textAlign = TextAlign.Start, + color = MaterialTheme.colorScheme.onBackground + ), + minLines = 1, + maxLines = 2, + visualTransformation = visualTransformation, + decorationBox = { innerTextField -> + Text( + text = fromPlaceholderText, + minLines = 1, + maxLines = 2, + style = NumbersTextStyleDisplayMedium, + color = MaterialTheme.colorScheme.outline, + textAlign = TextAlign.Start + ) + innerTextField() + } + ) + } + Text(text = fromSupportText) + Text( + text = toTextValue.ifEmpty { toPlaceholderText }, + style = NumbersTextStyleDisplayMedium, + ) + Text(text = toSupportText) + } +} diff --git a/feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/TopPart.kt b/feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/TopPart.kt index 867c37d5..b1190789 100644 --- a/feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/TopPart.kt +++ b/feature/epoch/src/main/java/com/sadellie/unitto/feature/epoch/component/TopPart.kt @@ -22,19 +22,12 @@ import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.text.BasicTextField -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalTextInputService import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.VisualTransformation -import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import com.sadellie.unitto.core.ui.theme.NumbersTextStyleDisplayMedium @Composable fun TopPart( @@ -79,47 +72,3 @@ fun TopPart( SwapButton(modifier = Modifier.fillMaxWidth(), swap = swap) } } - -@Composable -fun DateUnixTextFields( - fromTextFieldValue: TextFieldValue, - onCursorChange: (TextFieldValue) -> Unit, - fromSupportText: String, - toTextValue: String, - toSupportText: String, - visualTransformation: VisualTransformation, - fromPlaceholderText: String, - toPlaceholderText: String -) { - Column { - CompositionLocalProvider( - LocalTextInputService provides null - ) { - BasicTextField( - value = fromTextFieldValue, - onValueChange = onCursorChange, - textStyle = NumbersTextStyleDisplayMedium.copy(textAlign = TextAlign.Start), - minLines = 1, - maxLines = 2, - visualTransformation = visualTransformation, - decorationBox = { innerTextField -> - Text( - text = fromPlaceholderText, - minLines = 1, - maxLines = 2, - style = NumbersTextStyleDisplayMedium, - color = MaterialTheme.colorScheme.outline, - textAlign = TextAlign.Start - ) - innerTextField() - } - ) - } - Text(text = fromSupportText) - Text( - text = toTextValue.ifEmpty { toPlaceholderText }, - style = NumbersTextStyleDisplayMedium, - ) - Text(text = toSupportText) - } -}