mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Add TextFieldState overload to design system TextField, use it in UserStatusView
This commit is contained in:
+6
-5
@@ -34,7 +34,7 @@ import io.element.android.libraries.designsystem.components.list.ListItemContent
|
|||||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.theme.components.Button
|
import io.element.android.libraries.designsystem.theme.components.Button
|
||||||
import io.element.android.libraries.designsystem.theme.components.FilledTextField
|
import io.element.android.libraries.designsystem.theme.components.TextField
|
||||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||||
import io.element.android.libraries.designsystem.theme.components.IconButton
|
import io.element.android.libraries.designsystem.theme.components.IconButton
|
||||||
import io.element.android.libraries.designsystem.theme.components.IconSource
|
import io.element.android.libraries.designsystem.theme.components.IconSource
|
||||||
@@ -171,12 +171,12 @@ private fun CustomStatusInputRow(
|
|||||||
) {
|
) {
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = {
|
headlineContent = {
|
||||||
FilledTextField(
|
TextField(
|
||||||
state = textFieldState,
|
state = textFieldState,
|
||||||
placeholder = { Text(stringResource(R.string.screen_preferences_user_status_custom_hint)) },
|
placeholder = stringResource(R.string.screen_preferences_user_status_custom_hint),
|
||||||
inputTransformation = InputTransformation { if (length > 30) revertAllChanges() },
|
inputTransformation = InputTransformation { if (length > 30) revertAllChanges() },
|
||||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||||
keyboardActions = { if (textFieldState.text.isNotBlank()) onConfirm() },
|
onKeyboardAction = { if (textFieldState.text.isNotBlank()) onConfirm() },
|
||||||
lineLimits = TextFieldLineLimits.SingleLine,
|
lineLimits = TextFieldLineLimits.SingleLine,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -195,7 +195,8 @@ private fun CustomStatusInputRow(
|
|||||||
Text(text = emoji, style = ElementTheme.typography.fontBodyLgRegular)
|
Text(text = emoji, style = ElementTheme.typography.fontBodyLgRegular)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
|
modifier = modifier,
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+54
@@ -24,6 +24,11 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
|||||||
import androidx.compose.foundation.text.BasicTextField
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.foundation.text.input.InputTransformation
|
||||||
|
import androidx.compose.foundation.text.input.KeyboardActionHandler
|
||||||
|
import androidx.compose.foundation.text.input.TextFieldDecorator
|
||||||
|
import androidx.compose.foundation.text.input.TextFieldLineLimits
|
||||||
|
import androidx.compose.foundation.text.input.TextFieldState
|
||||||
import androidx.compose.material3.LocalContentColor
|
import androidx.compose.material3.LocalContentColor
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
@@ -161,6 +166,55 @@ fun TextField(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TextField(
|
||||||
|
state: TextFieldState,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
label: String? = null,
|
||||||
|
supportingText: String? = null,
|
||||||
|
placeholder: String? = null,
|
||||||
|
leadingIcon: @Composable (() -> Unit)? = null,
|
||||||
|
trailingIcon: @Composable (() -> Unit)? = null,
|
||||||
|
validity: TextFieldValidity = TextFieldValidity.None,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
readOnly: Boolean = false,
|
||||||
|
inputTransformation: InputTransformation? = null,
|
||||||
|
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
||||||
|
onKeyboardAction: KeyboardActionHandler? = null,
|
||||||
|
lineLimits: TextFieldLineLimits = TextFieldLineLimits.Default,
|
||||||
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
|
) {
|
||||||
|
val isFocused by interactionSource.collectIsFocusedAsState()
|
||||||
|
BasicTextField(
|
||||||
|
state = state,
|
||||||
|
modifier = modifier,
|
||||||
|
textStyle = textFieldStyle(enabled),
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
enabled = enabled,
|
||||||
|
readOnly = readOnly,
|
||||||
|
inputTransformation = inputTransformation,
|
||||||
|
cursorBrush = SolidColor(ElementTheme.colors.textPrimary),
|
||||||
|
keyboardOptions = keyboardOptions,
|
||||||
|
onKeyboardAction = onKeyboardAction,
|
||||||
|
lineLimits = lineLimits,
|
||||||
|
decorator = TextFieldDecorator { innerTextField ->
|
||||||
|
DecorationBox(
|
||||||
|
label = label,
|
||||||
|
readOnly = readOnly,
|
||||||
|
enabled = enabled,
|
||||||
|
isFocused = isFocused,
|
||||||
|
validity = validity,
|
||||||
|
leadingIcon = leadingIcon,
|
||||||
|
placeholder = placeholder,
|
||||||
|
isTextEmpty = state.text.isEmpty(),
|
||||||
|
innerTextField = innerTextField,
|
||||||
|
trailingIcon = trailingIcon,
|
||||||
|
supportingText = supportingText,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DecorationBox(
|
private fun DecorationBox(
|
||||||
label: String?,
|
label: String?,
|
||||||
|
|||||||
Reference in New Issue
Block a user