Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/navigation drawer #243

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package com.ban.autosizetextfield
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.ParagraphIntrinsics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.font.createFontFamilyResolver
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import de.berlindroid.zeapp.zeui.zetheme.ZeBlack
import de.berlindroid.zeapp.zeui.zetheme.ZeWhite

private const val TEXT_SCALE_REDUCTION_INTERVAL = 0.7f

Expand All @@ -25,23 +28,22 @@ private const val TEXT_SCALE_REDUCTION_INTERVAL = 0.7f
fun AutoSizeTextField(
modifier: Modifier = Modifier,
value: String,
fontSize: TextUnit = 24.sp,
lineHeight: TextUnit = 36.sp,
onValueChange: (String) -> Unit,
supportingText: @Composable () -> Unit,
label: @Composable () -> Unit = { },
trailingIcon: @Composable () -> Unit,
placeholder: @Composable () -> Unit,
isError: Boolean = false,
) {
BoxWithConstraints(modifier = modifier.fillMaxWidth()) {
var shrunkFontSize = fontSize
var shrunkFontSize = 20.sp
val calculateIntrinsics = @Composable {
ParagraphIntrinsics(
text = value,
style = TextStyle(
fontSize = shrunkFontSize,
fontWeight = FontWeight.SemiBold,
lineHeight = lineHeight,
fontWeight = FontWeight.Normal,
lineHeight = 36.sp,
),
density = LocalDensity.current,
fontFamilyResolver = createFontFamilyResolver(LocalContext.current),
Expand All @@ -66,15 +68,27 @@ fun AutoSizeTextField(
onValueChange = { onValueChange(it) },
textStyle = TextStyle(
fontSize = shrunkFontSize,
fontWeight = FontWeight.SemiBold,
lineHeight = lineHeight,
textAlign = TextAlign.Center,
fontWeight = FontWeight.Normal,
lineHeight = 36.sp,
textAlign = TextAlign.Start,
),
label = label,
singleLine = true,
supportingText = supportingText,
trailingIcon = trailingIcon,
placeholder = placeholder,
isError = isError,
colors = OutlinedTextFieldDefaults.colors().copy(
focusedContainerColor = ZeBlack,
focusedTextColor = ZeWhite,
focusedLabelColor = ZeBlack,
unfocusedContainerColor = ZeWhite,
unfocusedTextColor = ZeBlack,
unfocusedLabelColor = ZeBlack,
cursorColor = ZeWhite,
errorContainerColor = Color.Red,
errorLabelColor = Color.Red,
),
)
}
}
Loading
Loading