From d3473ebe7567dbce323721dacd162733d482c786 Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Fri, 31 Mar 2023 10:39:17 +0200 Subject: [PATCH] Add minLines parameter to BasicTextField.desktop Same as here: https://android-review.googlesource.com/c/platform/frameworks/support/+/2237754 We don't need to support binary compatibility for this function, as it is experimental --- .../foundation/text/BasicTextField.desktop.kt | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/BasicTextField.desktop.kt b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/BasicTextField.desktop.kt index 1ab60f959f464..11577fa60c6e8 100644 --- a/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/BasicTextField.desktop.kt +++ b/compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/BasicTextField.desktop.kt @@ -95,11 +95,12 @@ import androidx.compose.ui.text.input.VisualTransformation * [KeyboardOptions.imeAction]. * @param singleLine when set to true, this text field becomes a single horizontally scrolling * text field instead of wrapping onto multiple lines. The keyboard will be informed to not show - * the return key as the [ImeAction]. Note that [maxLines] parameter will be ignored as the - * maxLines attribute will be automatically set to 1. - * @param maxLines the maximum height in terms of maximum number of visible lines. Should be - * equal or greater than 1. Note that this parameter will be ignored and instead maxLines will be - * set to 1 if [singleLine] is set to true. + * the return key as the [ImeAction]. [maxLines] and [minLines] are ignored as both are + * automatically set to 1. + * @param maxLines the maximum height in terms of maximum number of visible lines. It is required + * that 1 <= [minLines] <= [maxLines]. This parameter is ignored when [singleLine] is true. + * @param minLines the minimum height in terms of minimum number of visible lines. It is required + * that 1 <= [minLines] <= [maxLines]. This parameter is ignored when [singleLine] is true. * @param visualTransformation The visual transformation filter for changing the visual * representation of the input. By default no visual transformation is applied. * @param onTextLayout Callback that is executed when a new text layout is calculated. A @@ -133,7 +134,8 @@ fun BasicTextField( keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, singleLine: Boolean = false, - maxLines: Int = Int.MAX_VALUE, + maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE, + minLines: Int = 1, visualTransformation: VisualTransformation = VisualTransformation.None, onTextLayout: (TextLayoutResult) -> Unit = {}, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, @@ -182,6 +184,7 @@ fun BasicTextField( imeOptions = keyboardOptions.toImeOptions(singleLine = singleLine), keyboardActions = keyboardActions, softWrap = !singleLine, + minLines = if (singleLine) 1 else minLines, maxLines = if (singleLine) 1 else maxLines, decorationBox = decorationBox, enabled = enabled, @@ -243,11 +246,12 @@ fun BasicTextField( * [KeyboardOptions.imeAction]. * @param singleLine when set to true, this text field becomes a single horizontally scrolling * text field instead of wrapping onto multiple lines. The keyboard will be informed to not show - * the return key as the [ImeAction]. Note that [maxLines] parameter will be ignored as the - * maxLines attribute will be automatically set to 1. - * @param maxLines the maximum height in terms of maximum number of visible lines. Should be - * equal or greater than 1. Note that this parameter will be ignored and instead maxLines will be - * set to 1 if [singleLine] is set to true. + * the return key as the [ImeAction]. [maxLines] and [minLines] are ignored as both are + * automatically set to 1. + * @param maxLines the maximum height in terms of maximum number of visible lines. It is required + * that 1 <= [minLines] <= [maxLines]. This parameter is ignored when [singleLine] is true. + * @param minLines the minimum height in terms of minimum number of visible lines. It is required + * that 1 <= [minLines] <= [maxLines]. This parameter is ignored when [singleLine] is true. * @param visualTransformation The visual transformation filter for changing the visual * representation of the input. By default no visual transformation is applied. * @param onTextLayout Callback that is executed when a new text layout is calculated. A @@ -281,7 +285,8 @@ fun BasicTextField( keyboardOptions: KeyboardOptions = KeyboardOptions.Default, keyboardActions: KeyboardActions = KeyboardActions.Default, singleLine: Boolean = false, - maxLines: Int = Int.MAX_VALUE, + maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE, + minLines: Int = 1, visualTransformation: VisualTransformation = VisualTransformation.None, onTextLayout: (TextLayoutResult) -> Unit = {}, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, @@ -306,6 +311,7 @@ fun BasicTextField( imeOptions = keyboardOptions.toImeOptions(singleLine = singleLine), keyboardActions = keyboardActions, softWrap = !singleLine, + minLines = if (singleLine) 1 else minLines, maxLines = if (singleLine) 1 else maxLines, decorationBox = decorationBox, enabled = enabled, @@ -314,4 +320,3 @@ fun BasicTextField( ) } -