Skip to content

Commit

Permalink
Don't show animations for password fields. Fixes #800 (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines authored May 3, 2024
1 parent cffda6b commit 3bf6f70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import com.dessalines.thumbkey.utils.circularDirection
import com.dessalines.thumbkey.utils.colorVariantToColor
import com.dessalines.thumbkey.utils.doneKeyAction
import com.dessalines.thumbkey.utils.fontSizeVariantToFontSize
import com.dessalines.thumbkey.utils.isPasswordField
import com.dessalines.thumbkey.utils.performKeyAction
import com.dessalines.thumbkey.utils.pxToSp
import com.dessalines.thumbkey.utils.slideCursorDistance
Expand Down Expand Up @@ -129,6 +130,9 @@ fun KeyboardKey(
val ime = ctx as IMEService
val scope = rememberCoroutineScope()

// Don't show animations for password fields
val isPasswordField by remember { mutableStateOf(isPasswordField(ime)) }

val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()

Expand Down Expand Up @@ -695,7 +699,7 @@ fun KeyboardKey(
Modifier
.fillMaxSize()
.background(color = Color(0, 0, 0, 0)),
visible = releasedKey.value != null,
visible = releasedKey.value != null && !isPasswordField,
enter = EnterTransition.None,
exit = fadeOut(tween(animationSpeed)),
) {
Expand All @@ -714,7 +718,7 @@ fun KeyboardKey(
Modifier
.fillMaxSize()
.background(color = Color(0, 0, 0, 0)),
visible = releasedKey.value != null,
visible = releasedKey.value != null && !isPasswordField,
enter = slideInVertically(tween(animationSpeed)),
exit = fadeOut(tween(animationSpeed)),
) {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,15 @@ fun isUriOrEmailOrPasswordField(ime: IMEService): Boolean {
).contains(inputType) || ime.currentInputEditorInfo.inputType == EditorInfo.TYPE_NULL
}

fun isPasswordField(ime: IMEService): Boolean {
val inputType = ime.currentInputEditorInfo.inputType and (InputType.TYPE_MASK_VARIATION)
return listOf(
InputType.TYPE_TEXT_VARIATION_PASSWORD,
InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD,
InputType.TYPE_NUMBER_VARIATION_PASSWORD,
).contains(inputType) || ime.currentInputEditorInfo.inputType == EditorInfo.TYPE_NULL
}

fun deleteWordBeforeCursor(ime: IMEService) {
val wordsBeforeCursor = ime.currentInputConnection.getTextBeforeCursor(9999, 0)

Expand Down

0 comments on commit 3bf6f70

Please sign in to comment.