Fix DateUnixTextFields

Moved to a separate file
Fixed text color
This commit is contained in:
Sad Ellie 2023-02-09 19:39:17 +04:00
parent 3bf2b73549
commit 55d9ec4327
2 changed files with 78 additions and 51 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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)
}
}

View File

@ -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)
}
}