File tree Expand file tree Collapse file tree
app/src/main/java/com/orange/ouds/app/ui/components/pincodeinput
core/src/main/java/com/orange/ouds/core/component Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313package com.orange.ouds.app.ui.components.pincodeinput
1414
1515import androidx.compose.runtime.Composable
16+ import androidx.compose.ui.platform.LocalFocusManager
1617import androidx.compose.ui.res.stringResource
1718import com.orange.ouds.app.R
1819import com.orange.ouds.app.ui.components.Component
@@ -78,14 +79,16 @@ private fun PinCodeInputDemoBottomSheetContent(state: PinCodeInputDemoState) {
7879
7980@Composable
8081private fun PinCodeInputDemoContent (state : PinCodeInputDemoState ) {
82+ val focusManager = LocalFocusManager .current
8183 with (state) {
8284 OudsPinCodeInput (
8385 value = value,
8486 onValueChange = { value = it },
8587 length = length,
8688 outlined = outlined,
8789 error = if (error) OudsError (errorMessage) else null ,
88- helperText = helperText
90+ helperText = helperText,
91+ onKeyboardAction = { focusManager.clearFocus() }
8992 )
9093 }
9194}
@@ -99,9 +102,7 @@ private fun Code.Builder.pinCodeInputDemoCodeSnippet(state: PinCodeInputDemoStat
99102 }
100103 typedArgument(" length" , length)
101104 if (outlined) typedArgument(" outlined" , outlined)
102- if (error) {
103- errorArgument(errorMessage)
104- }
105+ if (error) errorArgument(errorMessage)
105106 if (helperText.isNotEmpty()) typedArgument(" helperText" , helperText)
106107 }
107108 }
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ class PinCodeInputDemoState(
7171 )
7272 }
7373
74- var value by mutableStateOf(value)
74+ var value: String by mutableStateOf(value)
7575
7676 var length: OudsPinCodeInputLength by mutableStateOf(length)
7777
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ fun OudsPinCodeInput(
7373 @Suppress(" NAME_SHADOWING" ) val interactionSource = interactionSource ? : remember { MutableInteractionSource () }
7474 val interactionState by interactionSource.collectInteractionStateAsState()
7575 val pinCodeInputTokens = OudsTheme .componentsTokens.pinCodeInput
76- val paddedValue = value.padEnd(length.value, OudsDigitInputPlaceholder )
76+ val paddedValue = value.take(length.value). padEnd(length.value, OudsDigitInputPlaceholder )
7777 val textFieldState = rememberTextFieldState(
7878 initialText = paddedValue,
7979 initialSelection = TextRange ((value.length + 1 ).coerceIn(0 , length.value))
@@ -82,8 +82,9 @@ fun OudsPinCodeInput(
8282 if (paddedValue != textFieldState.text) {
8383 textFieldState.edit {
8484 val cursorPosition = selection.end.coerceIn(0 , length.value)
85- replace(0 , length.value, paddedValue)
86- // Set the cursor to its position before the replacement, because the replace method moves the cursor
85+ delete(0 , this .length)
86+ append(paddedValue)
87+ // Set the cursor to its position before the text replacement
8788 placeCursorBeforeCharAt(cursorPosition)
8889 }
8990 }
You can’t perform that action at this time.
0 commit comments