@@ -62,9 +62,9 @@ import kotlinx.coroutines.flow.launchIn
6262import kotlinx.coroutines.flow.onEach
6363import kotlin.math.roundToInt
6464
65- sealed interface AutoSize {
66- data object Disabled : AutoSize
67- data class Constrained (val minimum : TextStyle ): AutoSize
65+ sealed interface ConstraintMode {
66+ data object Free : ConstraintMode
67+ data class AutoSize (val minimum : TextStyle ) : ConstraintMode
6868}
6969
7070@OptIn(ExperimentalFoundationApi ::class )
@@ -87,7 +87,7 @@ fun TextInput(
8787 enabled : Boolean = true,
8888 isError : Boolean = false,
8989 readOnly : Boolean = false,
90- autosize : AutoSize = AutoSize . Disabled ,
90+ constraintMode : ConstraintMode = ConstraintMode . Free ,
9191 leadingIcon : (@Composable () -> Unit )? = null,
9292 trailingIcon : (@Composable () -> Unit )? = null,
9393 scrollState : ScrollState = rememberScrollState(),
@@ -108,8 +108,8 @@ fun TextInput(
108108 modifier = Modifier
109109 .background(backgroundColor, shape)
110110 .defaultMinSize(minHeight = minHeight)
111- .autoSize (
112- mode = autosize ,
111+ .constrain (
112+ mode = constraintMode ,
113113 state = state,
114114 style = style,
115115 frameConstraints = constraints
@@ -163,8 +163,8 @@ fun TextInput(
163163}
164164
165165@OptIn(ExperimentalFoundationApi ::class )
166- private fun Modifier.autoSize (
167- mode : AutoSize ,
166+ private fun Modifier.constrain (
167+ mode : ConstraintMode ,
168168 state : TextFieldState ,
169169 style : TextStyle ,
170170 frameConstraints : Constraints ,
@@ -175,32 +175,32 @@ private fun Modifier.autoSize(
175175 val textLayoutResult = remember { Ref <TextLayoutResult ?>() }
176176 var flag by remember { mutableStateOf(Unit , neverEqualPolicy()) }
177177
178- Modifier .addIf(mode is AutoSize . Constrained ) {
179- Modifier .layout { measurable, constraints ->
180- val placeable = measurable.measure(constraints)
181- val result = autosizeTextMeasurer.measure(
182- text = AnnotatedString (state.text.toString()),
183- style = style,
184- constraints = Constraints (
185- maxWidth = (frameConstraints.maxWidth * 0.85f ).roundToInt(),
186- minHeight = 0
187- ),
188- minFontSize = (mode as AutoSize . Constrained ).minimum.fontSize,
189- maxFontSize = style.fontSize,
190- autosizeGranularity = 100
191- )
178+ Modifier .addIf(mode is ConstraintMode . AutoSize ) {
179+ Modifier .layout { measurable, constraints ->
180+ val placeable = measurable.measure(constraints)
181+ val result = autosizeTextMeasurer.measure(
182+ text = AnnotatedString (state.text.toString()),
183+ style = style,
184+ constraints = Constraints (
185+ maxWidth = (frameConstraints.maxWidth * 0.85f ).roundToInt(),
186+ minHeight = 0
187+ ),
188+ minFontSize = (mode as ConstraintMode . AutoSize ).minimum.fontSize,
189+ maxFontSize = style.fontSize,
190+ autosizeGranularity = 100
191+ )
192192
193- textLayoutResult.value = result
194- flag = Unit
193+ textLayoutResult.value = result
194+ flag = Unit
195195
196- onTextSizeDetermined(result.layoutInput.style.fontSize)
196+ onTextSizeDetermined(result.layoutInput.style.fontSize)
197197
198- layout(placeable.width, placeable.height) {
199- placeable.placeRelative(0 , 0 )
198+ layout(placeable.width, placeable.height) {
199+ placeable.placeRelative(0 , 0 )
200+ }
200201 }
201202 }
202203}
203- }
204204
205205@OptIn(ExperimentalFoundationApi ::class )
206206@Composable
0 commit comments