# PasswordVisualTransformation

Artifact: [androidx.compose.ui:ui-text](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/input/VisualTransformation.kt+class:androidx.compose.ui.text.input.PasswordVisualTransformation) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Deprecated in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.13.0-rc01) Common/AllAndroid/JVM
- Cmn

  ```
  class PasswordVisualTransformation : VisualTransformation
  ```

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
> The TextField flavors that use VisualTransformation are deprecated. Please refer to BasicSecureTextField and other SecureTextField composables for password inputs.

The Visual Filter can be used for password Input Field.

Note that this visual filter only works for ASCII characters.

## Summary

| ### Public constructors |
|---|---|
| `[PasswordVisualTransformation](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#PasswordVisualTransformation(kotlin.Char))(mask: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char/index.html)` **This function is deprecated.** The TextField flavors that use VisualTransformation are deprecated. | Cmn |

| ### Public functions |
|---|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `[equals](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#equals(kotlin.Any))(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` **This function is deprecated.** The TextField flavors that use VisualTransformation are deprecated. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/TransformedText` | `[filter](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#filter(androidx.compose.ui.text.AnnotatedString))(text: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/AnnotatedString)` **This function is deprecated.** The TextField flavors that use VisualTransformation are deprecated. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `[hashCode](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#hashCode())()` **This function is deprecated.** The TextField flavors that use VisualTransformation are deprecated. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#mask()` **This property is deprecated.** The TextField flavors that use VisualTransformation are deprecated. | Cmn |

## Public constructors

### PasswordVisualTransformation

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Deprecated in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.13.0-rc01)

```
[PasswordVisualTransformation](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#PasswordVisualTransformation(kotlin.Char))(mask: Char = '\u2022')
```

> [!CAUTION]
> **This function is deprecated.**   
> The TextField flavors that use VisualTransformation are deprecated. Please refer to BasicSecureTextField and other SecureTextField composables for password inputs.

| Parameters |
|---|---|
| `mask: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char/index.html = '\u2022'` | The mask character used instead of original text. |

## Public functions

### equals

Cmn

```
open operator fun [equals](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#equals(kotlin.Any))(other: Any?): Boolean
```

> [!CAUTION]
> **This function is deprecated.**   
> The TextField flavors that use VisualTransformation are deprecated. Please refer to BasicSecureTextField and other SecureTextField composables for password inputs.

### filter

Cmn

```
open fun [filter](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#filter(androidx.compose.ui.text.AnnotatedString))(text: AnnotatedString): TransformedText
```

> [!CAUTION]
> **This function is deprecated.**   
> The TextField flavors that use VisualTransformation are deprecated. Please refer to BasicSecureTextField and other SecureTextField composables for password inputs.

Change the visual output of given text.

Note that the returned text length can be different length from the given text. The composable will call the offset translator for converting offsets for various reasons, cursor drawing position, text selection by gesture, etc.

Example: The ASCII only password (replacing with '\*' chars) original text : thisispassword transformed text: \*\*\*\*\*\*\*\*\*\*\*\*\*\*

```kotlin
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText

return TransformedText(
    AnnotatedString("*".repeat(text.text.length)),

    /**
     * [OffsetMapping.Identity] is a predefined [OffsetMapping] that can be used for the
     * transformation that does not change the character count.
     */
    OffsetMapping.Identity,
)
```

Example: Credit Card Visual Output (inserting hyphens each 4 digits) original text : 1234567890123456 transformed text: 1234-5678-9012-3456

```kotlin
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText

// Making XXXX-XXXX-XXXX-XXXX string.
val trimmed = if (text.text.length >= 16) text.text.substring(0..15) else text.text
var out = ""
for (i in trimmed.indices) {
    out += trimmed[i]
    if (i % 4 == 3 && i != 15) out += "-"
}

/**
 * The offset translator should ignore the hyphen characters, so conversion from original offset
 * to transformed text works like
 * - The 4th char of the original text is 5th char in the transformed text.
 * - The 13th char of the original text is 15th char in the transformed text. Similarly, the
 *   reverse conversion works like
 * - The 5th char of the transformed text is 4th char in the original text.
 * - The 12th char of the transformed text is 10th char in the original text.
 */
val creditCardOffsetTranslator =
    object : OffsetMapping {
        override fun originalToTransformed(offset: Int): Int {
            if (offset <= 3) return offset
            if (offset <= 7) return offset + 1
            if (offset <= 11) return offset + 2
            if (offset <= 16) return offset + 3
            return 19
        }

        override fun transformedToOriginal(offset: Int): Int {
            if (offset <= 4) return offset
            if (offset <= 9) return offset - 1
            if (offset <= 14) return offset - 2
            if (offset <= 19) return offset - 3
            return 16
        }
    }

return TransformedText(AnnotatedString(out), creditCardOffsetTranslator)
```

| Parameters |
|---|---|
| `text: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/AnnotatedString` | The original text |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/TransformedText` | the pair of filtered text and offset translator. |

### hashCode

Cmn

```
open fun [hashCode](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/PasswordVisualTransformation#hashCode())(): Int
```

> [!CAUTION]
> **This function is deprecated.**   
> The TextField flavors that use VisualTransformation are deprecated. Please refer to BasicSecureTextField and other SecureTextField composables for password inputs.

## Public properties

### mask

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Deprecated in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.13.0-rc01)

```
val mask: Char
```

> [!CAUTION]
> **This property is deprecated.**   
> The TextField flavors that use VisualTransformation are deprecated. Please refer to BasicSecureTextField and other SecureTextField composables for password inputs.

The mask character used instead of original text.