@@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
15
15
import androidx.compose.ui.draw.clip
16
16
import androidx.compose.ui.focus.FocusRequester
17
17
import androidx.compose.ui.focus.focusRequester
18
+ import androidx.compose.ui.focus.onFocusChanged
18
19
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
19
20
import androidx.compose.ui.text.input.KeyboardType
20
21
import androidx.compose.ui.unit.dp
@@ -66,10 +67,13 @@ fun PinInput(
66
67
value : String = "",
67
68
disableKeypad : Boolean = false,
68
69
obscureText : String? = "*",
70
+ cursorVisibleOnlyOnFocus : Boolean = true,
69
71
onValueChanged : (String ) -> Unit
70
72
) {
71
73
val focusRequester = remember { FocusRequester () }
72
74
val keyboard = LocalSoftwareKeyboardController .current
75
+ val isFocused = remember { mutableStateOf(false ) }
76
+
73
77
TextField (
74
78
readOnly = disableKeypad,
75
79
value = value,
@@ -86,7 +90,10 @@ fun PinInput(
86
90
// Hide the text field
87
91
modifier = Modifier
88
92
.size(0 .dp)
89
- .focusRequester(focusRequester),
93
+ .focusRequester(focusRequester)
94
+ .onFocusChanged {
95
+ isFocused.value = it.isFocused
96
+ },
90
97
keyboardOptions = KeyboardOptions (
91
98
keyboardType = KeyboardType .Number
92
99
)
@@ -110,7 +117,7 @@ fun PinInput(
110
117
keyboard?.show()
111
118
},
112
119
value = value.getOrNull(it),
113
- isCursorVisible = value.length == it,
120
+ isCursorVisible = (isFocused.value || ! cursorVisibleOnlyOnFocus) && value.length == it,
114
121
obscureText
115
122
)
116
123
if (it != length - 1 )
0 commit comments