Skip to content

Commit

Permalink
fix: force lowercase letters on user handle (WPB-4820) (#3439)
Browse files Browse the repository at this point in the history
Signed-off-by: alexandreferris <[email protected]>
  • Loading branch information
alexandreferris authored Sep 13, 2024
1 parent cb2a0a5 commit 466c428
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 466c428

Please sign in to comment.