Skip to content

Commit

Permalink
Fixed the formatting on the Expression TextField to correctly scale i…
Browse files Browse the repository at this point in the history
…n height with the text
  • Loading branch information
Carson-McCombs committed Jun 26, 2024
1 parent bb72fbf commit f62c358
Showing 1 changed file with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -44,17 +45,12 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalFontFamilyResolver
import androidx.compose.ui.text.Paragraph
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import model.RegexPatterns
Expand Down Expand Up @@ -127,7 +123,6 @@ fun ChildExpressionView(
ChildExpressionView_Body(
expression = expression,
expressionTextFieldState = expressionTextFieldState,
visibleState = visibleState,
updateExpressionText = updateExpressionText
)
}
Expand Down Expand Up @@ -247,23 +242,12 @@ private fun ChildExpressionView_TitleBar(
private fun ChildExpressionView_Body(
expression: Expression,
expressionTextFieldState: TextFieldState,
visibleState: MutableTransitionState<Boolean>,
updateExpressionText: () -> Unit
) {
val focusManager = LocalFocusManager.current
val scrollState = rememberScrollState()
val interactionSource = remember(expression.id, "expressionTextInteractionSource") { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState()
val localConfiguration = LocalConfiguration.current
val lineCount = Paragraph(
text = expression.text,
style = MaterialTheme.typography.bodyLarge,
constraints = Constraints(maxWidth = (localConfiguration.screenWidthDp * 0.8f).toInt()),
density = LocalDensity.current,
fontFamilyResolver = LocalFontFamilyResolver.current
).lineCount
val textFieldFontSize = with(LocalDensity.current) { MaterialTheme.typography.bodyLarge.fontSize.toDp() }
val textFieldHeight= remember (visibleState.currentState,textFieldFontSize, lineCount) { if (visibleState.currentState) (textFieldFontSize * (lineCount+1)) + 8.dp else textFieldFontSize + 8.dp }
Column(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -293,7 +277,7 @@ private fun ChildExpressionView_Body(
Row(
modifier = Modifier
.fillMaxWidth()
.height(textFieldHeight)
.height(IntrinsicSize.Min)
.border(
width = 1.dp,
color = MaterialTheme.colorScheme.onPrimaryContainer,
Expand Down

0 comments on commit f62c358

Please sign in to comment.