Skip to content

Commit 67703dd

Browse files
committed
Fix various bugs in demo screen
1 parent a952a35 commit 67703dd

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

app/src/main/java/com/orange/ouds/app/ui/components/pincodeinput/PinCodeInputDemoScreen.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.orange.ouds.app.ui.components.pincodeinput
1414

1515
import androidx.compose.runtime.Composable
16+
import androidx.compose.ui.platform.LocalFocusManager
1617
import androidx.compose.ui.res.stringResource
1718
import com.orange.ouds.app.R
1819
import com.orange.ouds.app.ui.components.Component
@@ -78,14 +79,16 @@ private fun PinCodeInputDemoBottomSheetContent(state: PinCodeInputDemoState) {
7879

7980
@Composable
8081
private 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
}

app/src/main/java/com/orange/ouds/app/ui/components/pincodeinput/PinCodeInputDemoState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

core/src/main/java/com/orange/ouds/core/component/OudsPinCodeInput.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)