diff --git a/app/src/main/kotlin/com/wire/android/ui/authentication/create/common/handle/UsernameTextField.kt b/app/src/main/kotlin/com/wire/android/ui/authentication/create/common/handle/UsernameTextField.kt index ac1c7ca2b82..07c8c8e93c0 100644 --- a/app/src/main/kotlin/com/wire/android/ui/authentication/create/common/handle/UsernameTextField.kt +++ b/app/src/main/kotlin/com/wire/android/ui/authentication/create/common/handle/UsernameTextField.kt @@ -34,6 +34,7 @@ import com.wire.android.ui.common.error.CoreFailureErrorDialog import com.wire.android.ui.common.textfield.DefaultEmail import com.wire.android.ui.common.textfield.WireTextField import com.wire.android.ui.common.textfield.WireTextFieldState +import com.wire.android.ui.common.textfield.forceLowercase import com.wire.android.ui.common.textfield.maxLengthWithCallback import com.wire.android.ui.common.textfield.patternWithCallback import com.wire.android.ui.theme.wireDimensions @@ -56,6 +57,7 @@ fun UsernameTextField( placeholderText = stringResource(R.string.create_account_username_placeholder), labelText = stringResource(R.string.create_account_username_label), inputTransformation = InputTransformation + .forceLowercase() .patternWithCallback(Patterns.HANDLE, animate) .maxLengthWithCallback(255, animate), leadingIcon = { diff --git a/app/src/main/kotlin/com/wire/android/ui/common/textfield/InputTransformations.kt b/app/src/main/kotlin/com/wire/android/ui/common/textfield/InputTransformations.kt index 01a8c8e6c77..a8a4ad7b44c 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/textfield/InputTransformations.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/textfield/InputTransformations.kt @@ -76,6 +76,15 @@ class PatternFilterWithCallback(private val pattern: Pattern, private val onInco } } +fun InputTransformation.forceLowercase(): InputTransformation = + this.then(ForceLowercaseTransformation()) + +class ForceLowercaseTransformation : InputTransformation { + override fun TextFieldBuffer.transformInput() { + replace(0, length, asCharSequence().toString().lowercase()) + } +} + @Stable fun InputTransformation.patternWithCallback(pattern: Pattern, onIncorrectChangesFound: () -> Unit): InputTransformation = this.then(PatternFilterWithCallback(pattern, onIncorrectChangesFound))