From 6b4b9baf2f0aaa8cb64ff461114e9587c8241393 Mon Sep 17 00:00:00 2001 From: Xavier Molloy <44061143+xavimolloy@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:12:49 +0100 Subject: [PATCH] fix: [ANDROAPP-5900] set initial composition to 0, manage textfieldValue correctly on value change (#186) * bug: [ANDROAPP-5900] set initial composition to 0, manage textfieldValue correctly on value change * fix: [ANDROAPP-5900] extract rememberable variable to avoid unnecessary recompositions and use TextFieldValue for Inputs to maintain cursor, selection and composition control. * fix: [ANDROAPP-5900] amend build gradle changes * bug: [ANDROAPP-5900] set initial composition to 0, manage textfieldValue correctly on value change * fix: [ANDROAPP-5900] extract rememberable variable to avoid unnecessary recompositions and use TextFieldValue for Inputs to maintain cursor, selection and composition control. * fix: [ANDROAPP-5900] amend build gradle changes * fix: [ANDROAPP-5900] allow null values and correct Input Negative Integer --- .../dhis/common/screens/FormShellsScreen.kt | 65 ++++++++++--------- .../common/screens/FormsComponentsScreen.kt | 5 +- .../dhis/common/screens/InputBarCodeScreen.kt | 35 ++++------ .../common/screens/InputDateTimeScreen.kt | 17 ++--- .../dhis/common/screens/InputEmailScreen.kt | 57 +++++++++------- .../dhis/common/screens/InputIntegerScreen.kt | 33 ++++------ .../dhis/common/screens/InputLetterScreen.kt | 33 ++++------ .../dhis/common/screens/InputLinkScreen.kt | 21 +++--- .../common/screens/InputLongTextScreen.kt | 27 ++++---- .../screens/InputNegativeIntegerScreen.kt | 17 ++--- .../dhis/common/screens/InputNumberScreen.kt | 17 ++--- .../common/screens/InputPercentageScreen.kt | 17 ++--- .../common/screens/InputPhoneNumberScreen.kt | 17 ++--- .../InputPositiveIntegerOrZeroScreen.kt | 13 ++-- .../screens/InputPositiveIntegerScreen.kt | 17 ++--- .../dhis/common/screens/InputQRCodeScreen.kt | 15 +++-- .../hisp/dhis/common/screens/InputScreen.kt | 11 ++-- .../dhis/common/screens/InputTextScreen.kt | 21 +++--- .../common/screens/InputUnitIntervalScreen.kt | 25 ++++--- .../hisp/dhis/common/screens/SectionScreen.kt | 19 +++--- .../designsystem/component/BasicTextInput.kt | 45 ++++++++----- .../ui/designsystem/component/InputAge.kt | 11 ++-- .../ui/designsystem/component/InputBarCode.kt | 11 ++-- .../designsystem/component/InputDateTime.kt | 19 +++--- .../ui/designsystem/component/InputEmail.kt | 9 +-- .../ui/designsystem/component/InputField.kt | 22 ++----- .../ui/designsystem/component/InputInteger.kt | 7 +- .../ui/designsystem/component/InputLetter.kt | 7 +- .../ui/designsystem/component/InputLink.kt | 9 +-- .../designsystem/component/InputLongText.kt | 7 +- .../component/InputNegativeInteger.kt | 16 +++-- .../ui/designsystem/component/InputNumber.kt | 7 +- .../designsystem/component/InputPercentage.kt | 7 +- .../component/InputPhoneNumber.kt | 11 ++-- .../component/InputPositiveInteger.kt | 7 +- .../component/InputPositiveIntegerOrZero.kt | 7 +- .../ui/designsystem/component/InputQRCode.kt | 9 +-- .../ui/designsystem/component/InputText.kt | 7 +- .../component/InputUnitInterval.kt | 7 +- .../component/InputBarCodeTest.kt | 25 +++---- .../component/InputDateTimeTest.kt | 17 ++--- .../designsystem/component/InputEmailTest.kt | 53 ++++++--------- .../component/InputIntegerTest.kt | 53 ++++++--------- .../designsystem/component/InputLetterTest.kt | 37 +++++------ .../designsystem/component/InputLinkTest.kt | 29 +++++---- .../component/InputLongTextTest.kt | 17 ++--- .../component/InputNegativeIntegerTest.kt | 25 +++---- .../designsystem/component/InputNumberTest.kt | 21 +++--- .../component/InputPercentageTest.kt | 25 +++---- .../component/InputPhoneNumberTest.kt | 17 ++--- .../InputPositiveIntegerOrZeroTest.kt | 33 +++++----- .../component/InputPositiveIntegerTest.kt | 29 +++++---- .../designsystem/component/InputQRCodeTest.kt | 13 ++-- .../designsystem/component/InputTextTest.kt | 17 ++--- .../component/InputUnitIntervalTest.kt | 25 +++---- 55 files changed, 578 insertions(+), 565 deletions(-) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormShellsScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormShellsScreen.kt index bd3cdb9f8..3d244f3cb 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormShellsScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormShellsScreen.kt @@ -9,6 +9,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.common.screens.previews.lorem import org.hisp.dhis.common.screens.previews.regularLegendList import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer @@ -28,11 +29,11 @@ fun FormShellsScreen() { ColumnComponentContainer(title = "Form Shells") { SubTitle("Outer frames for form elements", TextColor.OnSurface) Description("Focused/Unfocused", TextColor.OnSurface) - var inputValue1 by rememberSaveable { mutableStateOf("Input") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -44,10 +45,10 @@ fun FormShellsScreen() { Description("Focused/Unfocused with content", TextColor.OnSurface) - var inputValue2 by rememberSaveable { mutableStateOf("Input") } + var inputValue2 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue2, + inputTextFieldValue = inputValue2, onValueChanged = { if (it != null) { inputValue2 = it @@ -58,11 +59,11 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Error", TextColor.OnSurface) - var inputValue3 by rememberSaveable { mutableStateOf("") } + var inputValue3 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } InputText( "Label", state = InputShellState.ERROR, - inputText = inputValue3, + inputTextFieldValue = inputValue3, onValueChanged = { if (it != null) { inputValue3 = it @@ -72,11 +73,11 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Error with content", TextColor.OnSurface) - var inputValue4 by rememberSaveable { mutableStateOf("Input") } + var inputValue4 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue4, + inputTextFieldValue = inputValue4, state = InputShellState.ERROR, onValueChanged = { if (it != null) { @@ -87,11 +88,11 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Disabled", TextColor.OnSurface) - var inputValue5 by rememberSaveable { mutableStateOf("") } + var inputValue5 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } InputText( "Label", state = InputShellState.DISABLED, - inputText = inputValue5, + inputTextFieldValue = inputValue5, onValueChanged = { if (it != null) { inputValue5 = it @@ -101,10 +102,10 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Disabled with content", TextColor.OnSurface) - var inputValue6 by rememberSaveable { mutableStateOf("Input") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -115,11 +116,11 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Required field", TextColor.OnSurface) - var inputValue7 by rememberSaveable { mutableStateOf("") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } InputText( "Label", isRequiredField = true, - inputText = inputValue7, + inputTextFieldValue = inputValue7, onValueChanged = { if (it != null) { inputValue7 = it @@ -130,10 +131,10 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Required field with error", TextColor.OnSurface) - var inputValue8 by rememberSaveable { mutableStateOf("Input") } + var inputValue8 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } InputText( "Label", - inputText = inputValue8, + inputTextFieldValue = inputValue8, isRequiredField = true, state = InputShellState.ERROR, onValueChanged = { @@ -146,7 +147,7 @@ fun FormShellsScreen() { SubTitle("Supporting text", TextColor.OnSurface) Description("Short text", TextColor.OnSurface) - var inputValue9 by rememberSaveable { mutableStateOf("") } + var inputValue9 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } InputText( "Label", supportingText = listOf( @@ -155,7 +156,7 @@ fun FormShellsScreen() { SupportingTextState.DEFAULT, ), ), - inputText = inputValue9, + inputTextFieldValue = inputValue9, onValueChanged = { if (it != null) { inputValue9 = it @@ -166,7 +167,7 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Long text", TextColor.OnSurface) - var inputValue10 by rememberSaveable { mutableStateOf("") } + var inputValue10 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputText( "Label", supportingText = listOf( @@ -175,7 +176,7 @@ fun FormShellsScreen() { SupportingTextState.DEFAULT, ), ), - inputText = inputValue10, + inputTextFieldValue = inputValue10, onValueChanged = { if (it != null) { inputValue10 = it @@ -187,10 +188,10 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Error", TextColor.OnSurface) - var inputValue11 by rememberSaveable { mutableStateOf("Input") } + var inputValue11 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue11, + inputTextFieldValue = inputValue11, supportingText = listOf( SupportingTextData( "Supporting Text", @@ -207,10 +208,10 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Warning", TextColor.OnSurface) - var inputValue12 by rememberSaveable { mutableStateOf("Input") } + var inputValue12 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue12, + inputTextFieldValue = inputValue12, supportingText = listOf( SupportingTextData( "Supporting Text", @@ -227,10 +228,10 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Error and Warning", TextColor.OnSurface) - var inputValue13 by rememberSaveable { mutableStateOf("Input") } + var inputValue13 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue13, + inputTextFieldValue = inputValue13, supportingText = listOf( SupportingTextData( lorem, @@ -257,11 +258,11 @@ fun FormShellsScreen() { SubTitle("Form with legend", TextColor.OnSurface) Description("Just legend", TextColor.OnSurface) - var inputValue14 by rememberSaveable { mutableStateOf("Input") } + var inputValue14 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue14, + inputTextFieldValue = inputValue14, legendData = LegendData(SurfaceColor.CustomGreen, "Legend", popUpLegendDescriptionData = regularLegendList), onValueChanged = { if (it != null) { @@ -271,10 +272,10 @@ fun FormShellsScreen() { state = InputShellState.UNFOCUSED, ) - var inputValue15 by rememberSaveable { mutableStateOf("Input") } + var inputValue15 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue15, + inputTextFieldValue = inputValue15, legendData = LegendData(SurfaceColor.CustomYellow, "Legend", popUpLegendDescriptionData = regularLegendList), onValueChanged = { if (it != null) { @@ -286,10 +287,10 @@ fun FormShellsScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("Legend and supporting text", TextColor.OnSurface) - var inputValue16 by rememberSaveable { mutableStateOf("Input") } + var inputValue16 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( "Label", - inputText = inputValue16, + inputTextFieldValue = inputValue16, legendData = LegendData(SurfaceColor.CustomYellow, "Legend", popUpLegendDescriptionData = regularLegendList), supportingText = listOf( SupportingTextData( diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormsComponentsScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormsComponentsScreen.kt index e5469e236..75d01bd9f 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormsComponentsScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/FormsComponentsScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.common.screens.previews.InputShellPreview import org.hisp.dhis.mobile.ui.designsystem.component.BasicTextField import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer @@ -46,11 +47,11 @@ fun FormsComponentsScreen() { inputField = { BasicTextField( helper = "Helper", - inputText = inputField, + inputTextValue = TextFieldValue(inputField), enabled = true, helperStyle = InputStyle.WITH_HELPER_BEFORE, onInputChanged = { - inputField = it + inputField = it.text }, ) }, diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputBarCodeScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputBarCodeScreen.kt index f1632586a..ee7278846 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputBarCodeScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputBarCodeScreen.kt @@ -14,6 +14,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.common.screens.previews.threeButtonCarousel import org.hisp.dhis.mobile.ui.designsystem.component.BarcodeBlock import org.hisp.dhis.mobile.ui.designsystem.component.BottomSheetShell @@ -32,7 +33,7 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor @Composable fun InputBarCodeScreen() { ColumnComponentContainer { - var inputValue1 by rememberSaveable { mutableStateOf("889026a1-d01e-4d34-8209-81e8ed5c614b") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("889026a1-d01e-4d34-8209-81e8ed5c614b")) } var showEnabledBarCodeBottomSheet by rememberSaveable { mutableStateOf(false) } Description("Default Input Barcode", textColor = TextColor.OnSurfaceVariant) @@ -42,11 +43,9 @@ fun InputBarCodeScreen() { onActionButtonClicked = { showEnabledBarCodeBottomSheet = !showEnabledBarCodeBottomSheet }, - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { - if (it != null) { - inputValue1 = it - } + inputValue1 = it ?: TextFieldValue() }, ) @@ -63,7 +62,7 @@ fun InputBarCodeScreen() { }, content = { Row(horizontalArrangement = Arrangement.Center) { - BarcodeBlock(data = inputValue1) + BarcodeBlock(data = inputValue1.text) } }, buttonBlock = { @@ -77,52 +76,46 @@ fun InputBarCodeScreen() { } Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue2 by rememberSaveable { mutableStateOf("") } + var inputValue2 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } Description("Required field Input Barcode", textColor = TextColor.OnSurfaceVariant) InputBarCode( "label", state = InputShellState.ERROR, onActionButtonClicked = { }, - inputText = inputValue2, + inputTextFieldValue = inputValue2, onValueChanged = { - if (it != null) { - inputValue2 = it - } + inputValue2 = it ?: TextFieldValue() }, isRequiredField = true, supportingText = listOf(SupportingTextData("Required", SupportingTextState.ERROR)), ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } Description("Disabled Input Barcode", textColor = TextColor.OnSurfaceVariant) InputBarCode( "label", state = InputShellState.DISABLED, onActionButtonClicked = { }, - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue3 by rememberSaveable { mutableStateOf("889026a1-d01e-4d34-8209-81e8ed5c614b") } + var inputValue3 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("889026a1-d01e-4d34-8209-81e8ed5c614b")) } Description("Disabled Input Barcode with content", textColor = TextColor.OnSurfaceVariant) InputBarCode( "label", state = InputShellState.DISABLED, onActionButtonClicked = { }, - inputText = inputValue3, + inputTextFieldValue = inputValue3, onValueChanged = { - if (it != null) { - inputValue3 = it - } + inputValue3 = it ?: TextFieldValue() }, ) } diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputDateTimeScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputDateTimeScreen.kt index 1f212f412..d01d4d8e2 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputDateTimeScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputDateTimeScreen.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.DateTimeActionIconType import org.hisp.dhis.mobile.ui.designsystem.component.InputDateTime @@ -16,13 +17,13 @@ import org.hisp.dhis.mobile.ui.designsystem.component.internal.TimeTransformatio @Composable fun InputDateTimeScreen() { ColumnComponentContainer { - var date by remember { mutableStateOf("") } - var time by remember { mutableStateOf("") } - var dateTime by remember { mutableStateOf("") } + var date by remember { mutableStateOf(TextFieldValue()) } + var time by remember { mutableStateOf(TextFieldValue()) } + var dateTime by remember { mutableStateOf(TextFieldValue()) } InputDateTime( title = "Label", - value = date, + inputTextFieldValue = date, visualTransformation = DateTransformation(), actionIconType = DateTimeActionIconType.DATE, onActionClicked = { @@ -33,7 +34,7 @@ fun InputDateTimeScreen() { InputDateTime( title = "Label", - value = time, + inputTextFieldValue = time, visualTransformation = TimeTransformation(), actionIconType = DateTimeActionIconType.TIME, onActionClicked = { @@ -44,7 +45,7 @@ fun InputDateTimeScreen() { InputDateTime( title = "Label", - value = dateTime, + inputTextFieldValue = dateTime, visualTransformation = DateTimeTransformation(), actionIconType = DateTimeActionIconType.DATE_TIME, onActionClicked = { @@ -55,7 +56,7 @@ fun InputDateTimeScreen() { InputDateTime( title = "Label", - value = "", + inputTextFieldValue = TextFieldValue(), state = InputShellState.DISABLED, onActionClicked = { // no-op @@ -67,7 +68,7 @@ fun InputDateTimeScreen() { InputDateTime( title = "Label", - value = "", + inputTextFieldValue = TextFieldValue(), isRequired = true, state = InputShellState.ERROR, onActionClicked = { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputEmailScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputEmailScreen.kt index 901da6625..3ea502921 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputEmailScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputEmailScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputEmail import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -23,16 +24,14 @@ fun InputEmailScreen() { ColumnComponentContainer { Title("Input Email component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Email ", textColor = TextColor.OnSurfaceVariant) - var inputText1 by rememberSaveable { mutableStateOf("") } + var inputText1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } InputEmail( title = "Label", supportingText = listOf(SupportingTextData("Example: name@example.com")), - inputText = inputText1, + inputTextFieldValue = inputText1, onValueChanged = { - if (it != null) { - inputText1 = it - } + inputText1 = it ?: TextFieldValue() }, onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -40,16 +39,18 @@ fun InputEmailScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Email with content ", textColor = TextColor.OnSurfaceVariant) - var inputText2 by rememberSaveable { mutableStateOf("fatiman92@gmail.com") } + var inputText2 by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue("fatiman92@gmail.com"), + ) + } InputEmail( title = "Label", supportingText = listOf(SupportingTextData("Example: name@example.com")), - inputText = inputText2, + inputTextFieldValue = inputText2, onValueChanged = { - if (it != null) { - inputText2 = it - } + inputText2 = it ?: TextFieldValue() }, onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -57,49 +58,55 @@ fun InputEmailScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Error Email with content ", textColor = TextColor.OnSurfaceVariant) - var inputText3 by rememberSaveable { mutableStateOf("fatiman92@gmail.com") } + var inputText3 by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue("fatiman92@gmail.com"), + ) + } InputEmail( title = "Label", state = InputShellState.ERROR, supportingText = listOf(SupportingTextData("Enter a valid email address", SupportingTextState.ERROR)), - inputText = inputText3, + inputTextFieldValue = inputText3, onValueChanged = { - if (it != null) { - inputText3 = it - } + inputText3 = it ?: TextFieldValue() }, onEmailActionCLicked = {}, ) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Error Email required field ", textColor = TextColor.OnSurfaceVariant) - var inputText4 by rememberSaveable { mutableStateOf("") } + var inputText4 by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue(), + ) + } InputEmail( title = "Label", state = InputShellState.ERROR, supportingText = listOf(SupportingTextData("Enter email address", SupportingTextState.ERROR)), - inputText = inputText4, + inputTextFieldValue = inputText4, isRequiredField = true, onValueChanged = { - if (it != null) { - inputText4 = it - } + inputText4 = it ?: TextFieldValue() }, onEmailActionCLicked = {}, ) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Disabled Email with content ", textColor = TextColor.OnSurfaceVariant) - var inputText5 by rememberSaveable { mutableStateOf("fatiman92@gmail.com") } + var inputText5 by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue("fatiman92@gmail.com"), + ) + } InputEmail( title = "Label", state = InputShellState.DISABLED, - inputText = inputText5, + inputTextFieldValue = inputText5, onValueChanged = { - if (it != null) { - inputText5 = it - } + inputText5 = it ?: TextFieldValue() }, onEmailActionCLicked = {}, ) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputIntegerScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputIntegerScreen.kt index 17fab4e97..37d74256d 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputIntegerScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputIntegerScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputInteger import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -23,62 +24,54 @@ fun InputIntegerScreen() { ColumnComponentContainer { Title("Input Integer component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Input Integer", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("12") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("12")) } InputInteger( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { - if (it != null) { - inputValue1 = it - } + inputValue1 = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Input Integer with error", textColor = TextColor.OnSurfaceVariant) - var inputValueError by rememberSaveable { mutableStateOf("") } + var inputValueError by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("")) } InputInteger( title = "Label", - inputText = inputValueError, + inputTextFieldValue = inputValueError, onValueChanged = { - if (it != null) { - inputValueError = it - } + inputValueError = it ?: TextFieldValue() }, state = InputShellState.ERROR, supportingText = listOf(SupportingTextData("Numbers only", SupportingTextState.ERROR)), ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } SubTitle("Disabled Input Integer ", textColor = TextColor.OnSurfaceVariant) InputInteger( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { - if (it != null) { - inputValue6 = it - } + inputValue6 = it ?: TextFieldValue() }, ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("1234") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } SubTitle("Disabled Input Integer with content ", textColor = TextColor.OnSurfaceVariant) InputInteger( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { - if (it != null) { - inputValue7 = it - } + inputValue7 = it ?: TextFieldValue() }, ) } diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLetterScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLetterScreen.kt index 2fd6a7431..34e49b4b2 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLetterScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLetterScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputLetter import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -23,62 +24,54 @@ fun InputLetterScreen() { ColumnComponentContainer { Title("Input Letter component", textColor = TextColor.OnSurfaceVariant) SubTitle(" Basic Input Letter", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLetter( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { - if (it != null) { - inputValue1 = it - } + inputValue1 = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle(" Basic Input Letter with error", textColor = TextColor.OnSurfaceVariant) - var inputValueError by rememberSaveable { mutableStateOf("") } + var inputValueError by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLetter( title = "Label", - inputText = inputValueError, + inputTextFieldValue = inputValueError, onValueChanged = { - if (it != null) { - inputValueError = it - } + inputValueError = it ?: TextFieldValue() }, supportingText = listOf(SupportingTextData("Letters only. eg. A, B, C", SupportingTextState.ERROR)), state = InputShellState.ERROR, ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } SubTitle("Disabled Input Letter ", textColor = TextColor.OnSurfaceVariant) InputLetter( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { - if (it != null) { - inputValue6 = it - } + inputValue6 = it ?: TextFieldValue() }, ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("A") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("A")) } SubTitle("Disabled Input Letter with content ", textColor = TextColor.OnSurfaceVariant) InputLetter( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { - if (it != null) { - inputValue7 = it - } + inputValue7 = it ?: TextFieldValue() }, ) } diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLinkScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLinkScreen.kt index cf6976962..94c7b3e60 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLinkScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLinkScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputLink import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -23,12 +24,12 @@ fun InputLinkScreen() { ColumnComponentContainer { Title("Input Link component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Link ", textColor = TextColor.OnSurfaceVariant) - var inputText1 by rememberSaveable { mutableStateOf("") } + var inputText1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLink( title = "Label", supportingText = listOf(SupportingTextData("Example: example.com")), - inputText = inputText1, + inputTextFieldValue = inputText1, onValueChanged = { if (it != null) { inputText1 = it @@ -40,12 +41,12 @@ fun InputLinkScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Link with invalid link ", textColor = TextColor.OnSurfaceVariant) - var inputText2 by rememberSaveable { mutableStateOf("example.") } + var inputText2 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("example.")) } InputLink( title = "Label", supportingText = listOf(SupportingTextData("Example: example.com")), - inputText = inputText2, + inputTextFieldValue = inputText2, onValueChanged = { if (it != null) { inputText2 = it @@ -57,12 +58,12 @@ fun InputLinkScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Link with valid link ", textColor = TextColor.OnSurfaceVariant) - var inputText3 by rememberSaveable { mutableStateOf("example.com") } + var inputText3 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue(("example.com"))) } InputLink( title = "Label", supportingText = listOf(SupportingTextData("Example: example.com")), - inputText = inputText3, + inputTextFieldValue = inputText3, onValueChanged = { if (it != null) { inputText3 = it @@ -74,12 +75,12 @@ fun InputLinkScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Error Link required field ", textColor = TextColor.OnSurfaceVariant) - var inputText4 by rememberSaveable { mutableStateOf("") } + var inputText4 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLink( title = "Label", state = InputShellState.ERROR, supportingText = listOf(SupportingTextData("Required", SupportingTextState.ERROR)), - inputText = inputText4, + inputTextFieldValue = inputText4, isRequiredField = true, onValueChanged = { if (it != null) { @@ -91,11 +92,11 @@ fun InputLinkScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Disabled Link with content ", textColor = TextColor.OnSurfaceVariant) - var inputText5 by rememberSaveable { mutableStateOf("example.com") } + var inputText5 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("example.com")) } InputLink( title = "Label", state = InputShellState.DISABLED, - inputText = inputText5, + inputTextFieldValue = inputText5, onValueChanged = { if (it != null) { inputText5 = it diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLongTextScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLongTextScreen.kt index a31f08a1f..4eca3b0ed 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLongTextScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputLongTextScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.common.screens.previews.lorem_medium import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputLongText @@ -24,15 +25,16 @@ fun InputLongTextScreen() { ColumnComponentContainer { Title("Input Long Text component", textColor = TextColor.OnSurfaceVariant) SubTitle(" Basic Input Long Text", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf( - lorem_medium, + TextFieldValue(lorem_medium), + ) } InputLongText( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -43,15 +45,15 @@ fun InputLongTextScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle(" Basic Input Long Text with error message", textColor = TextColor.OnSurfaceVariant) - var inputValueError by rememberSaveable { + var inputValueError by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf( - lorem_medium, + TextFieldValue(lorem_medium), ) } InputLongText( title = "Label", - inputText = inputValueError, + inputTextFieldValue = inputValueError, onValueChanged = { if (it != null) { inputValueError = it @@ -66,13 +68,16 @@ fun InputLongTextScreen() { state = InputShellState.ERROR, ) Spacer(Modifier.size(Spacing.Spacing18)) - - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue(""), + ) + } SubTitle("Disabled Input Long Text ", textColor = TextColor.OnSurfaceVariant) InputLongText( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -82,12 +87,12 @@ fun InputLongTextScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("Content") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Content")) } SubTitle("Disabled Input text with content ", textColor = TextColor.OnSurfaceVariant) InputLongText( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNegativeIntegerScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNegativeIntegerScreen.kt index 2883bbb15..4bc409f08 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNegativeIntegerScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNegativeIntegerScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputNegativeInteger import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -23,11 +24,11 @@ fun InputNegativeIntegerScreen() { ColumnComponentContainer { Title("Input Negative Integer component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Input Negative Integer", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("-12") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("-12")) } InputNegativeInteger( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -38,11 +39,11 @@ fun InputNegativeIntegerScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Input Integer with error", textColor = TextColor.OnSurfaceVariant) - var inputValueError by rememberSaveable { mutableStateOf("") } + var inputValueError by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNegativeInteger( title = "Label", - inputText = inputValueError, + inputTextFieldValue = inputValueError, onValueChanged = { if (it != null) { inputValueError = it @@ -53,12 +54,12 @@ fun InputNegativeIntegerScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } SubTitle("Disabled Input Negative Integer ", textColor = TextColor.OnSurfaceVariant) InputNegativeInteger( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -68,12 +69,12 @@ fun InputNegativeIntegerScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("1234") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } SubTitle("Disabled Input Negative Integer with content ", textColor = TextColor.OnSurfaceVariant) InputNegativeInteger( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNumberScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNumberScreen.kt index 530429cdf..cc47e041f 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNumberScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputNumberScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.Description import org.hisp.dhis.mobile.ui.designsystem.component.InputNumber @@ -23,11 +24,11 @@ fun InputNumberScreen() { ColumnComponentContainer { Title("Input Number component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Input Number", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } Description("British decimal notation", textColor = TextColor.OnSurfaceVariant) InputNumber( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -39,11 +40,11 @@ fun InputNumberScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Description("European decimal notation", textColor = TextColor.OnSurfaceVariant) - var inputValueEuropean by rememberSaveable { mutableStateOf("") } + var inputValueEuropean by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNumber( title = "Label", - inputText = inputValueEuropean, + inputTextFieldValue = inputValueEuropean, onValueChanged = { if (it != null) { inputValueEuropean = it @@ -54,12 +55,12 @@ fun InputNumberScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } SubTitle("Disabled Input Number ", textColor = TextColor.OnSurfaceVariant) InputNumber( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -69,12 +70,12 @@ fun InputNumberScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("86") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("86")) } SubTitle("Disabled Input Number with content ", textColor = TextColor.OnSurfaceVariant) InputNumber( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPercentageScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPercentageScreen.kt index 79c340854..7a39f4e19 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPercentageScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPercentageScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputPercentage import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -21,11 +22,11 @@ fun InputPercentageScreen() { ColumnComponentContainer { Title("Input Percentage component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Percentage ", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("12") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("12")) } InputPercentage( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -36,11 +37,11 @@ fun InputPercentageScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Percentage required field", textColor = TextColor.OnSurfaceVariant) - var inputValueRequired by rememberSaveable { mutableStateOf("") } + var inputValueRequired by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPercentage( title = "Label", - inputText = inputValueRequired, + inputTextFieldValue = inputValueRequired, onValueChanged = { if (it != null) { inputValueRequired = it @@ -51,12 +52,12 @@ fun InputPercentageScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } SubTitle("Disabled Percentage ", textColor = TextColor.OnSurfaceVariant) InputPercentage( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -66,12 +67,12 @@ fun InputPercentageScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("1234") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } SubTitle("Disabled Percentage with content ", textColor = TextColor.OnSurfaceVariant) InputPercentage( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPhoneNumberScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPhoneNumberScreen.kt index 68872471f..a1ef6194e 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPhoneNumberScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPhoneNumberScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.Description import org.hisp.dhis.mobile.ui.designsystem.component.InputPhoneNumber @@ -20,11 +21,11 @@ fun InputPhoneNumberScreen() { ColumnComponentContainer( title = "Input Phone Number", ) { - var inputValue1 by rememberSaveable { mutableStateOf("") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } Description("Default Input Phone Number", textColor = TextColor.OnSurfaceVariant) InputPhoneNumber( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -38,11 +39,11 @@ fun InputPhoneNumberScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue2 by rememberSaveable { mutableStateOf("") } + var inputValue2 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } Description("Disabled Input Phone Number Without Phone Number", textColor = TextColor.OnSurfaceVariant) InputPhoneNumber( title = "Label", - inputText = inputValue2, + inputTextFieldValue = inputValue2, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -56,11 +57,11 @@ fun InputPhoneNumberScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue3 by rememberSaveable { mutableStateOf("1111111111") } + var inputValue3 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1111111")) } Description("Disabled Input Phone Number With Phone Number", textColor = TextColor.OnSurfaceVariant) InputPhoneNumber( title = "Label", - inputText = inputValue3, + inputTextFieldValue = inputValue3, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -74,11 +75,11 @@ fun InputPhoneNumberScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue4 by rememberSaveable { mutableStateOf("") } + var inputValue4 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } Description("Error Input Phone Number", textColor = TextColor.OnSurfaceVariant) InputPhoneNumber( title = "Label", - inputText = inputValue4, + inputTextFieldValue = inputValue4, state = InputShellState.ERROR, isRequiredField = true, onValueChanged = { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerOrZeroScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerOrZeroScreen.kt index 3e12e4e6b..775b933cb 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerOrZeroScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerOrZeroScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputPositiveIntegerOrZero import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -23,11 +24,11 @@ fun InputPositiveIntegerOrZeroScreen() { ColumnComponentContainer { Title("Input Positive or Zero Integer component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Input Integer", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("123") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("123")) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -38,11 +39,11 @@ fun InputPositiveIntegerOrZeroScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Input Integer with error", textColor = TextColor.OnSurfaceVariant) - var inputValueError by rememberSaveable { mutableStateOf("") } + var inputValueError by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValueError, + inputTextFieldValue = inputValueError, onValueChanged = { if (it != null) { inputValueError = it @@ -53,12 +54,12 @@ fun InputPositiveIntegerOrZeroScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("1234") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } SubTitle("Disabled Input Integer with content ", textColor = TextColor.OnSurfaceVariant) InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerScreen.kt index 793f63ced..4f148bb66 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputPositiveIntegerScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputPositiveInteger import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState @@ -23,11 +24,11 @@ fun InputPositiveIntegerScreen() { ColumnComponentContainer { Title("Input Positive Integer component", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic Input Integer", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("12") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("12")) } InputPositiveInteger( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -37,11 +38,11 @@ fun InputPositiveIntegerScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic Input Integer with error", textColor = TextColor.OnSurfaceVariant) - var inputValueError by rememberSaveable { mutableStateOf("") } + var inputValueError by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveInteger( title = "Label", - inputText = inputValueError, + inputTextFieldValue = inputValueError, onValueChanged = { if (it != null) { inputValueError = it @@ -52,12 +53,12 @@ fun InputPositiveIntegerScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } SubTitle("Disabled Input Integer ", textColor = TextColor.OnSurfaceVariant) InputPositiveInteger( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -67,12 +68,12 @@ fun InputPositiveIntegerScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("1234") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } SubTitle("Disabled Input Integer with content ", textColor = TextColor.OnSurfaceVariant) InputPositiveInteger( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputQRCodeScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputQRCodeScreen.kt index e1f1c13a6..02d81a136 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputQRCodeScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputQRCodeScreen.kt @@ -14,6 +14,7 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.common.screens.previews.threeButtonCarousel import org.hisp.dhis.mobile.ui.designsystem.component.BottomSheetShell import org.hisp.dhis.mobile.ui.designsystem.component.ButtonCarousel @@ -32,7 +33,7 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor @Composable fun InputQRCodeScreen() { ColumnComponentContainer { - var inputValue1 by rememberSaveable { mutableStateOf("889026a1-d01e-4d34-8209-81e8ed5c614b") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("889026a1-d01e-4d34-8209-81e8ed5c614b")) } var showEnabledQRBottomSheet by rememberSaveable { mutableStateOf(false) } Description("Default Input QR code", textColor = TextColor.OnSurfaceVariant) @@ -42,7 +43,7 @@ fun InputQRCodeScreen() { onQRButtonClicked = { showEnabledQRBottomSheet = !showEnabledQRBottomSheet }, - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -64,7 +65,7 @@ fun InputQRCodeScreen() { }, content = { Row(horizontalArrangement = Arrangement.Center) { - QrCodeBlock(data = inputValue1) + QrCodeBlock(data = inputValue1.text) } }, buttonBlock = { @@ -77,14 +78,14 @@ fun InputQRCodeScreen() { } } - var inputValue2 by rememberSaveable { mutableStateOf("") } + var inputValue2 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } Description("Required field Input QR code", textColor = TextColor.OnSurfaceVariant) InputQRCode( "label", state = InputShellState.ERROR, onQRButtonClicked = { }, - inputText = inputValue2, + inputTextFieldValue = inputValue2, onValueChanged = { if (it != null) { inputValue2 = it @@ -96,14 +97,14 @@ fun InputQRCodeScreen() { Spacer(Modifier.size(Spacing.Spacing18)) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } Description("Disabled Input QR code", textColor = TextColor.OnSurfaceVariant) InputQRCode( "label", state = InputShellState.DISABLED, onQRButtonClicked = { }, - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputScreen.kt index dbf00b29d..9f1e4ecbb 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.BasicTextField import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputStyle @@ -25,19 +26,19 @@ fun InputScreen() { title = "Input", content = { SubTitle("With helper before") - BasicTextField("Helper", helperStyle = InputStyle.WITH_HELPER_BEFORE, inputText = inputValue1, onInputChanged = { inputValue1 = it }) + BasicTextField("Helper", helperStyle = InputStyle.WITH_HELPER_BEFORE, inputTextValue = TextFieldValue(inputValue1), onInputChanged = { inputValue1 = it.text }) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("With helper after") - BasicTextField("Helper", helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = inputValue2, onInputChanged = { inputValue2 = it }) + BasicTextField("Helper", helperStyle = InputStyle.WITH_HELPER_AFTER, inputTextValue = TextFieldValue(inputValue2), onInputChanged = { inputValue2 = it.text }) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("No helper") - BasicTextField(inputText = inputValue3, onInputChanged = { - inputValue3 = it + BasicTextField(inputTextValue = TextFieldValue(inputValue3), onInputChanged = { + inputValue3 = it.text }) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Disabled") - BasicTextField(enabled = false, inputText = inputValue4, onInputChanged = { inputValue4 = it }) + BasicTextField(enabled = false, inputTextValue = TextFieldValue(inputValue4), onInputChanged = { inputValue4 = it.text }) }, ) } diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputTextScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputTextScreen.kt index 8413b29ac..68e55a606 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputTextScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputTextScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState import org.hisp.dhis.mobile.ui.designsystem.component.InputText @@ -21,13 +22,17 @@ fun InputTextScreen() { ColumnComponentContainer { Title("Input text component", textColor = TextColor.OnSurfaceVariant) SubTitle(" Basic Input text", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("Input") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue("Input"), + ) + } val autoCompleteList = listOf("red", "yellow", "blue", "orange", "purple", "green") InputText( autoCompleteList = autoCompleteList, title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -37,11 +42,11 @@ fun InputTextScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Input text with error ") - var inputValueError by rememberSaveable { mutableStateOf("Input") } + var inputValueError by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( title = "Label", - inputText = inputValueError, + inputTextFieldValue = inputValueError, onValueChanged = { if (it != null) { inputValueError = it @@ -51,12 +56,12 @@ fun InputTextScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } SubTitle("Disabled Input text ", textColor = TextColor.OnSurfaceVariant) InputText( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -66,12 +71,12 @@ fun InputTextScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("Content") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Content")) } SubTitle("Disabled Input text with content ", textColor = TextColor.OnSurfaceVariant) InputText( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputUnitIntervalScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputUnitIntervalScreen.kt index 4f4488cef..1e424f2e3 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputUnitIntervalScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputUnitIntervalScreen.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState import org.hisp.dhis.mobile.ui.designsystem.component.InputUnitInterval @@ -22,11 +23,11 @@ fun InputUnitIntervalScreen() { Title("Unit Interval", textColor = TextColor.OnSurfaceVariant) SubTitle("Keyboard: Numbers. Range between 0 and 1", textColor = TextColor.OnSurfaceVariant) SubTitle("Basic unit interval ", textColor = TextColor.OnSurfaceVariant) - var inputValue1 by rememberSaveable { mutableStateOf("0.25") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("0.25")) } InputUnitInterval( title = "Label", - inputText = inputValue1, + inputTextFieldValue = inputValue1, onValueChanged = { if (it != null) { inputValue1 = it @@ -37,11 +38,15 @@ fun InputUnitIntervalScreen() { Spacer(Modifier.size(Spacing.Spacing18)) SubTitle("Basic unit interval required field", textColor = TextColor.OnSurfaceVariant) - var inputValueRequired by rememberSaveable { mutableStateOf("") } + var inputValueRequired by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue(), + ) + } InputUnitInterval( title = "Label", - inputText = inputValueRequired, + inputTextFieldValue = inputValueRequired, onValueChanged = { if (it != null) { inputValueRequired = it @@ -52,12 +57,16 @@ fun InputUnitIntervalScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue6 by rememberSaveable { mutableStateOf("") } + var inputValue6 by rememberSaveable(stateSaver = TextFieldValue.Saver) { + mutableStateOf( + TextFieldValue(), + ) + } SubTitle("Disabled unit interval ", textColor = TextColor.OnSurfaceVariant) InputUnitInterval( title = "Label", - inputText = inputValue6, + inputTextFieldValue = inputValue6, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { @@ -67,12 +76,12 @@ fun InputUnitIntervalScreen() { ) Spacer(Modifier.size(Spacing.Spacing18)) - var inputValue7 by rememberSaveable { mutableStateOf("0.19") } + var inputValue7 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("0.19")) } SubTitle("Disabled unit interval with content ", textColor = TextColor.OnSurfaceVariant) InputUnitInterval( title = "Label", - inputText = inputValue7, + inputTextFieldValue = inputValue7, state = InputShellState.DISABLED, onValueChanged = { if (it != null) { diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/SectionScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/SectionScreen.kt index 2313dd06e..f39deeef5 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/SectionScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/SectionScreen.kt @@ -9,6 +9,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.common.screens.previews.lorem import org.hisp.dhis.common.screens.previews.lorem_medium import org.hisp.dhis.common.screens.previews.lorem_short @@ -156,25 +157,25 @@ fun SectionScreen() { @Composable private fun TestingFields() { - var inputValue1: String by rememberSaveable { mutableStateOf("Input") } - var inputValue2: String by rememberSaveable { mutableStateOf("") } - var inputValue3: String by rememberSaveable { mutableStateOf("") } + var inputValue1 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } + var inputValue2 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } + var inputValue3 by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputText( title = "Label", - inputText = inputValue1, - onValueChanged = { inputValue1 = it ?: "" }, + inputTextFieldValue = inputValue1, + onValueChanged = { inputValue1 = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) InputText( title = "Label", - inputText = inputValue2, - onValueChanged = { inputValue2 = it ?: "" }, + inputTextFieldValue = inputValue2, + onValueChanged = { inputValue2 = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) InputText( title = "Label", - inputText = inputValue3, - onValueChanged = { inputValue3 = it ?: "" }, + inputTextFieldValue = inputValue3, + onValueChanged = { inputValue3 = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) } diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/BasicTextInput.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/BasicTextInput.kt index a0f0c83a4..6a1739ff3 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/BasicTextInput.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/BasicTextInput.kt @@ -24,6 +24,8 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.testTag +import androidx.compose.ui.text.TextRange +import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.window.PopupProperties @@ -57,10 +59,10 @@ internal fun BasicTextInput( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, @@ -73,12 +75,12 @@ internal fun BasicTextInput( actionButton: @Composable (() -> Unit)? = null, modifier: Modifier = Modifier, ) { - val inputValue by remember(inputText) { mutableStateOf(inputText) } + var inputValue by remember(inputTextFieldValue) { mutableStateOf(inputTextFieldValue) } - var deleteButtonIsVisible by remember(inputText) { mutableStateOf(!inputText.isNullOrEmpty() && state != InputShellState.DISABLED) } + var deleteButtonIsVisible by remember(inputTextFieldValue) { mutableStateOf(!inputTextFieldValue?.text.isNullOrEmpty() && state != InputShellState.DISABLED) } val focusManager = LocalFocusManager.current val focusRequester = remember { FocusRequester() } - val filteredList = autoCompleteList?.filter { it.contains(inputValue ?: "") } + val filteredList = autoCompleteList?.filter { it.contains(inputValue?.text ?: "") } var expanded by remember { mutableStateOf(false) } var deleteButton: @@ -98,7 +100,8 @@ internal fun BasicTextInput( }, onClick = { focusRequester.requestFocus() - onValueChanged?.invoke("") + onValueChanged?.invoke(TextFieldValue("")) + inputValue = TextFieldValue("") deleteButtonIsVisible = false }, enabled = state != InputShellState.DISABLED, @@ -140,30 +143,34 @@ internal fun BasicTextInput( .testTag("INPUT_" + testTag + "_FIELD") .fillMaxWidth() .heightIn(Spacing.Spacing0, InternalSizeValues.Size300), - inputText = inputValue ?: "", + inputTextValue = inputValue ?: TextFieldValue(), helper = helper, isSingleLine = isSingleLine, helperStyle = helperStyle, onInputChanged = { newValue -> if (allowedCharacters != null) { if (allowedCharacters == RegExValidations.SINGLE_LETTER.regex) { - if (newValue.uppercase(Locale.getDefault()) - .matches(allowedCharacters) || newValue.isEmpty() + if (newValue.text.uppercase(Locale.getDefault()) + .matches(allowedCharacters) || newValue.text.isEmpty() ) { - onValueChanged?.invoke(newValue.uppercase(Locale.getDefault())) - deleteButtonIsVisible = newValue.isNotEmpty() + onValueChanged?.invoke(TextFieldValue(newValue.text.uppercase(Locale.getDefault()), newValue.selection, newValue.composition)) + inputValue = TextFieldValue(newValue.text.uppercase(Locale.getDefault()), newValue.selection, newValue.composition) + + deleteButtonIsVisible = newValue.text.isNotEmpty() } } else { - if (newValue.matches(allowedCharacters) || newValue.isEmpty()) { + if (newValue.text.matches(allowedCharacters) || newValue.text.isEmpty()) { onValueChanged?.invoke(newValue) - deleteButtonIsVisible = newValue.isNotEmpty() + inputValue = newValue + deleteButtonIsVisible = newValue.text.isNotEmpty() } } } else { onValueChanged?.invoke(newValue) - deleteButtonIsVisible = newValue.isNotEmpty() + inputValue = newValue + deleteButtonIsVisible = newValue.text.isNotEmpty() } - expanded = (!filteredList.isNullOrEmpty() && filteredList.any { it == newValue || it.contains(newValue) }) + expanded = (!filteredList.isNullOrEmpty() && filteredList.any { it == newValue.text || it.contains(newValue.text) }) }, enabled = state != InputShellState.DISABLED, state = state, @@ -190,7 +197,13 @@ internal fun BasicTextInput( text = { Text(it) }, modifier = Modifier, onClick = { - onValueChanged?.invoke(it) + onValueChanged?.invoke( + TextFieldValue( + it, + TextRange(it.length), + TextRange(0), + ), + ) autoCompleteItemSelected?.invoke(it) expanded = false }, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt index 7cbb0f221..cbb1e1b1f 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputAge.kt @@ -21,6 +21,7 @@ import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.AgeInputType.Age import org.hisp.dhis.mobile.ui.designsystem.component.AgeInputType.DateOfBirth import org.hisp.dhis.mobile.ui.designsystem.component.AgeInputType.None @@ -146,23 +147,23 @@ fun InputAge( modifier = Modifier .testTag("INPUT_AGE_TEXT_FIELD") .fillMaxWidth(), - inputText = transformInputText(inputType), + inputTextValue = TextFieldValue(transformInputText(inputType)), helper = helperText, isSingleLine = true, helperStyle = helperStyle, onInputChanged = { newText -> - if (newText.length > maxAgeCharLimit && inputType is Age) { + if (newText.text.length > maxAgeCharLimit && inputType is Age) { return@BasicTextField } @Suppress("KotlinConstantConditions") val newInputType: AgeInputType = when (inputType) { - is Age -> inputType.copy(value = newText) - is DateOfBirth -> updateDateOfBirth(inputType, newText) + is Age -> inputType.copy(value = newText.text) + is DateOfBirth -> updateDateOfBirth(inputType, newText.text) None -> None } - if (allowedCharacters.containsMatchIn(newText) || newText.isBlank()) { + if (allowedCharacters.containsMatchIn(newText.text) || newText.text.isBlank()) { onValueChanged.invoke(newInputType) } }, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCode.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCode.kt index 98d7f7d15..4f34fb537 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCode.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCode.kt @@ -7,6 +7,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.resource.provideDHIS2Icon /** @@ -33,23 +34,23 @@ fun InputBarCode( onActionButtonClicked: () -> Unit, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, ) { - val actionButtonIconVector = mutableStateOf(if (inputText.isNullOrEmpty()) "material_barcode_scanner" else "material_barcode") + val actionButtonIconVector = mutableStateOf(if (inputTextFieldValue?.text.isNullOrEmpty()) "material_barcode_scanner" else "material_barcode") BasicTextInput( title = title, state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, @@ -60,7 +61,7 @@ fun InputBarCode( actionButton = { SquareIconButton( modifier = Modifier.testTag("INPUT_BAR_CODE_BUTTON"), - enabled = (state == InputShellState.DISABLED && !inputText.isNullOrEmpty()) || state != InputShellState.DISABLED, + enabled = (state == InputShellState.DISABLED && !inputTextFieldValue?.text.isNullOrEmpty()) || state != InputShellState.DISABLED, icon = { Icon( painter = provideDHIS2Icon(actionButtonIconVector.value), diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTime.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTime.kt index e69442766..58785112a 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTime.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTime.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.DateTimeVisualTransformation import org.hisp.dhis.mobile.ui.designsystem.component.internal.DateTransformation import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations @@ -48,7 +49,7 @@ import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor @Composable fun InputDateTime( title: String, - value: String?, + inputTextFieldValue: TextFieldValue? = null, actionIconType: DateTimeActionIconType = DateTimeActionIconType.DATE_TIME, allowsManualInput: Boolean = true, onActionClicked: () -> Unit, @@ -61,7 +62,7 @@ fun InputDateTime( imeAction: ImeAction = ImeAction.Next, visualTransformation: DateTimeVisualTransformation = DateTransformation(), onFocusChanged: ((Boolean) -> Unit) = {}, - onValueChanged: (String) -> Unit, + onValueChanged: (TextFieldValue) -> Unit, ) { val allowedCharacters = RegExValidations.DATE_TIME.regex val focusManager = LocalFocusManager.current @@ -80,14 +81,14 @@ fun InputDateTime( modifier = Modifier .testTag("INPUT_DATE_TIME_TEXT_FIELD") .fillMaxWidth(), - inputText = value.orEmpty(), + inputTextValue = inputTextFieldValue ?: TextFieldValue(), isSingleLine = true, onInputChanged = { newText -> - if (newText.length > visualTransformation.maskLength) { + if (newText.text.length > visualTransformation.maskLength) { return@BasicTextField } - if (allowedCharacters.containsMatchIn(newText) || newText.isBlank()) { + if (allowedCharacters.containsMatchIn(newText.text) || newText.text.isBlank()) { onValueChanged.invoke(newText) } }, @@ -109,9 +110,9 @@ fun InputDateTime( modifier = Modifier .testTag("INPUT_DATE_TIME_TEXT") .fillMaxWidth(), - text = value.orEmpty(), + text = inputTextFieldValue?.text.orEmpty(), style = MaterialTheme.typography.bodyLarge.copy( - color = if (state != InputShellState.DISABLED && !value.isNullOrEmpty()) { + color = if (state != InputShellState.DISABLED && !inputTextFieldValue?.text.isNullOrEmpty()) { TextColor.OnSurface } else { TextColor.OnDisabledSurface @@ -134,7 +135,7 @@ fun InputDateTime( } }, primaryButton = { - if (!value.isNullOrBlank() && state != InputShellState.DISABLED) { + if (!inputTextFieldValue?.text.isNullOrBlank() && state != InputShellState.DISABLED) { IconButton( modifier = Modifier.testTag("INPUT_DATE_TIME_RESET_BUTTON").padding(Spacing.Spacing0), icon = { @@ -144,7 +145,7 @@ fun InputDateTime( ) }, onClick = { - onValueChanged.invoke("") + onValueChanged.invoke(TextFieldValue()) focusRequester.requestFocus() }, ) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmail.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmail.kt index a465e1d7e..e27ab730b 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmail.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmail.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -35,24 +36,24 @@ fun InputEmail( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, onEmailActionCLicked: () -> Unit, ) { - val isValidEmailAddress = RegExValidations.EMAIL.regex.matches(inputText.orEmpty()) + val isValidEmailAddress = RegExValidations.EMAIL.regex.matches(inputTextFieldValue?.text.orEmpty()) BasicTextInput( title = title, state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputField.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputField.kt index f64b83e06..6fe4d9e59 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputField.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputField.kt @@ -27,7 +27,6 @@ import androidx.compose.ui.graphics.PathEffect import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.platform.LocalSoftwareKeyboardController -import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.VisualTransformation @@ -87,8 +86,8 @@ fun BasicTextField( enabled: Boolean = true, isSingleLine: Boolean = true, helperStyle: InputStyle = InputStyle.NONE, - inputText: String = "", - onInputChanged: (String) -> Unit, + inputTextValue: TextFieldValue? = null, + onInputChanged: (TextFieldValue) -> Unit, modifier: Modifier = Modifier, state: InputShellState = InputShellState.FOCUSED, keyboardOptions: KeyboardOptions = KeyboardOptions(imeAction = ImeAction.Done), @@ -129,13 +128,6 @@ fun BasicTextField( backgroundColor = Blue300, ) - var textFieldSelection by remember { - mutableStateOf(TextRange(if (inputText.isEmpty()) 0 else inputText.length)) - } - var textFieldComposition by remember { - mutableStateOf(if (inputText.isEmpty()) null else TextRange(0, if (inputText.isEmpty()) 0 else inputText.length)) - } - CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) { BasicTextField( @@ -145,15 +137,9 @@ fun BasicTextField( ) .fillMaxWidth() .textFieldHoverPointerIcon(enabled), - value = TextFieldValue( - text = inputText, - selection = textFieldSelection, - composition = textFieldComposition, - ), + value = inputTextValue ?: TextFieldValue(), onValueChange = { - textFieldSelection = it.selection - textFieldComposition = it.composition - onInputChanged.invoke(it.text) + onInputChanged.invoke(it) }, enabled = enabled, textStyle = MaterialTheme.typography.bodyLarge.copy(color = if (enabled) TextColor.OnSurface else TextColor.OnDisabledSurface), diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputInteger.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputInteger.kt index 14e604a77..5b7ab2af5 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputInteger.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputInteger.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -31,12 +32,12 @@ fun InputInteger( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, @@ -46,7 +47,7 @@ fun InputInteger( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetter.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetter.kt index 40d78c733..0427204cc 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetter.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetter.kt @@ -6,6 +6,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -33,12 +34,12 @@ fun InputLetter( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, @@ -48,7 +49,7 @@ fun InputLetter( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLink.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLink.kt index c1d867f53..182160888 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLink.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLink.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -35,24 +36,24 @@ fun InputLink( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, onLinkActionCLicked: () -> Unit, ) { - val isValidUrl = RegExValidations.LINK.regex.matches(inputText.orEmpty()) + val isValidUrl = RegExValidations.LINK.regex.matches(inputTextFieldValue?.text.orEmpty()) BasicTextInput( title = title, state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongText.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongText.kt index 571e1f87f..922192f1b 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongText.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongText.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.TextFieldValue /** * DHIS2 Input Long Text. Wraps DHIS · [BasicTextInput]. @@ -28,12 +29,12 @@ fun InputLongText( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, @@ -43,7 +44,7 @@ fun InputLongText( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeInteger.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeInteger.kt index b14027e7c..5d88ea0a8 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeInteger.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeInteger.kt @@ -7,8 +7,10 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -35,29 +37,29 @@ fun InputNegativeInteger( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, ) { - var inputValue by rememberSaveable { mutableStateOf(inputText ?: "") } - inputValue = inputValue.replaceFirst("-", "") + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(inputTextFieldValue ?: TextFieldValue()) } + inputValue = TextFieldValue(inputValue.text.replaceFirst("-", ""), TextRange(inputValue.text.length), inputValue.composition) BasicTextInput( title = title, state = state, supportingText = supportingText, legendData = legendData, - inputText = inputValue, + inputTextFieldValue = inputValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = { - onValueChanged?.invoke(if (it?.startsWith("-") == true || it?.isEmpty() == true) it else "-$it") - inputValue = if (it?.startsWith("-") == true) inputValue.replaceFirst("-", "") else it.toString() + onValueChanged?.invoke(TextFieldValue(if (it.text.startsWith("-") || it.text.isEmpty()) it.text else "-${it.text}")) + inputValue = TextFieldValue(if (it.text.startsWith("-")) inputValue.text.replaceFirst("-", "") else it.text) }, helperStyle = InputStyle.WITH_HELPER_BEFORE, helper = "-", diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumber.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumber.kt index df2f0eccb..f974f0bd4 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumber.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumber.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -33,12 +34,12 @@ fun InputNumber( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, notation: RegExValidations = RegExValidations.EUROPEAN_DECIMAL_NOTATION, @@ -49,7 +50,7 @@ fun InputNumber( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentage.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentage.kt index 6f1b54f67..e8d340968 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentage.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentage.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -31,12 +32,12 @@ fun InputPercentage( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, @@ -46,7 +47,7 @@ fun InputPercentage( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumber.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumber.kt index d6ffcd0f5..8c2c2e0f7 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumber.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumber.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -37,28 +38,28 @@ fun InputPhoneNumber( maxLength: Int = 12, state: InputShellState, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit) = {}, imeAction: ImeAction = ImeAction.Next, supportingText: List? = emptyList(), allowedCharacters: RegExValidations = RegExValidations.PHONE_NUMBER, ) { - val hasMinimumPhoneNumberInput = inputText.orEmpty().length > 2 + val hasMinimumPhoneNumberInput = inputTextFieldValue?.text.orEmpty().length > 2 BasicTextInput( title = title, state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = { - if ((it?.length ?: 0) <= maxLength) { + if ((it.text.length) <= maxLength) { onValueChanged?.invoke(it) } else { // no-op diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveInteger.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveInteger.kt index 5e1462449..53f4aef08 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveInteger.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveInteger.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -31,12 +32,12 @@ fun InputPositiveInteger( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, @@ -46,7 +47,7 @@ fun InputPositiveInteger( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZero.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZero.kt index c18ae2320..e2edff7b3 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZero.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZero.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations /** @@ -31,12 +32,12 @@ fun InputPositiveIntegerOrZero( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, @@ -46,7 +47,7 @@ fun InputPositiveIntegerOrZero( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCode.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCode.kt index 335595f1b..0b2c462d3 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCode.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCode.kt @@ -10,6 +10,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.TextFieldValue /** * DHIS2 Input QR Code. Wraps DHIS · [BasicTextInput]. @@ -36,23 +37,23 @@ fun InputQRCode( onQRButtonClicked: () -> Unit, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, autoCompleteList: List? = null, autoCompleteItemSelected: ((String?) -> Unit)? = null, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, ) { - val actionButtonIconVector = mutableStateOf(if (!inputText.isNullOrEmpty()) Icons.Outlined.QrCode2 else Icons.Outlined.QrCodeScanner) + val actionButtonIconVector = mutableStateOf(if (!inputTextFieldValue?.text.isNullOrEmpty()) Icons.Outlined.QrCode2 else Icons.Outlined.QrCodeScanner) BasicTextInput( title = title, state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputText.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputText.kt index 42afc4f3f..90d792804 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputText.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputText.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.TextFieldValue /** * DHIS2 Input Text. Wraps DHIS · [BasicTextInput]. @@ -27,10 +28,10 @@ fun InputText( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, onFocusChanged: ((Boolean) -> Unit)? = null, autoCompleteList: List? = null, onAutoCompleteItemSelected: ((String?) -> Unit)? = null, @@ -43,7 +44,7 @@ fun InputText( autoCompleteList = autoCompleteList, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitInterval.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitInterval.kt index 6e376a88a..fcf92b0be 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitInterval.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitInterval.kt @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.internal.RegExValidations @Composable @@ -13,10 +14,10 @@ fun InputUnitInterval( state: InputShellState, supportingText: List? = null, legendData: LegendData? = null, - inputText: String? = null, + inputTextFieldValue: TextFieldValue? = null, isRequiredField: Boolean = false, onNextClicked: (() -> Unit)? = null, - onValueChanged: ((String?) -> Unit)? = null, + onValueChanged: ((TextFieldValue?) -> Unit)? = null, imeAction: ImeAction = ImeAction.Next, modifier: Modifier = Modifier, ) { @@ -25,7 +26,7 @@ fun InputUnitInterval( state = state, supportingText = supportingText, legendData = legendData, - inputText = inputText, + inputTextFieldValue = inputTextFieldValue, isRequiredField = isRequiredField, onNextClicked = onNextClicked, onValueChanged = onValueChanged, diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCodeTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCodeTest.kt index e90798cfd..e5651c32b 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCodeTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputBarCodeTest.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.test.assertTextEquals import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick +import androidx.compose.ui.text.input.TextFieldValue import org.junit.Rule import org.junit.Test @@ -20,15 +21,13 @@ class InputBarCodeTest { @Test fun shouldDisplayComponentCorrectly() { rule.setContent { - var inputValue by remember { mutableStateOf("") } + var inputValue by remember { mutableStateOf(TextFieldValue("")) } InputBarCode( title = "Bar code", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onActionButtonClicked = { // no-op @@ -41,15 +40,13 @@ class InputBarCodeTest { @Test fun shouldDeleteContentWhenResetIsClicked() { rule.setContent { - var inputValue by remember { mutableStateOf("12345") } + var inputValue by remember { mutableStateOf(TextFieldValue("12345")) } InputBarCode( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onActionButtonClicked = { // no-op @@ -66,15 +63,13 @@ class InputBarCodeTest { @Test fun shouldShowActionButtonCorrectlyAndBeClickable() { rule.setContent { - var inputValue by remember { mutableStateOf("12345") } + var inputValue by remember { mutableStateOf(TextFieldValue("12345")) } InputBarCode( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onActionButtonClicked = { // no-op diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTimeTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTimeTest.kt index 00e1fd20f..1c8bc9436 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTimeTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputDateTimeTest.kt @@ -5,6 +5,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.component.InputDateTime import org.junit.Rule import org.junit.Test @@ -16,11 +17,11 @@ class InputDateTimeTest { @Test fun dateTimeFieldChangesShouldWorkCorrectly() { - var input by mutableStateOf("") + var input by mutableStateOf(TextFieldValue()) rule.setContent { InputDateTime( title = "Label", - value = null, + inputTextFieldValue = input, onActionClicked = { // no-op }, @@ -31,17 +32,17 @@ class InputDateTimeTest { rule.onNodeWithTag("INPUT_DATE_TIME_TEXT_FIELD").performTextInput("1002") - assert(input == "1002") + assert(input.text == "1002") } @Test fun resetButtonShouldNotBeShownWhenTextIsEmpty() { - var input by mutableStateOf("") + var input by mutableStateOf(TextFieldValue()) rule.setContent { InputDateTime( title = "Label", - value = null, + inputTextFieldValue = input, onActionClicked = { // no-op }, @@ -55,12 +56,12 @@ class InputDateTimeTest { @Test fun clickingOnResetButtonShouldClearInput() { - var input by mutableStateOf("1002") + var input by mutableStateOf(TextFieldValue("1002")) rule.setContent { InputDateTime( title = "Label", - value = input, + inputTextFieldValue = input, onActionClicked = { // no-op }, @@ -71,6 +72,6 @@ class InputDateTimeTest { rule.onNodeWithTag("INPUT_DATE_TIME_RESET_BUTTON").performClick() - assert(input.isBlank()) + assert(input.text.isBlank()) } } diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmailTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmailTest.kt index aa9feaa13..e807f5e2a 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmailTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputEmailTest.kt @@ -16,6 +16,7 @@ import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextClearance import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -41,14 +42,12 @@ class InputEmailTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputEmail( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -75,14 +74,12 @@ class InputEmailTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputEmail( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -97,15 +94,13 @@ class InputEmailTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("fatiman@gmail.com") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("fatiman@gmail.com")) } InputEmail( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -121,15 +116,13 @@ class InputEmailTest { @Test fun shouldHideResetButtonWhenDisabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("fatiman@gmail.com") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("fatiman@gmail.com")) } InputEmail( title = "Label", state = InputShellState.DISABLED, - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onEmailActionCLicked = {}, ) @@ -143,7 +136,7 @@ class InputEmailTest { rule.setContent { InputEmail( title = "Label", - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -159,7 +152,7 @@ class InputEmailTest { rule.setContent { InputEmail( title = "Label", - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -172,15 +165,13 @@ class InputEmailTest { @Test fun shouldEnableEmailActionButtonOnEnteringValidEmailAddress() { rule.setContent { - var inputValue by remember { mutableStateOf("") } + var inputValue by remember { mutableStateOf(TextFieldValue()) } InputEmail( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -207,15 +198,13 @@ class InputEmailTest { @Test fun shouldDisableEmailActionButtonOnEnteringInValidEmailAddress() { rule.setContent { - var inputValue by remember { mutableStateOf("fatiman@gmail.com") } + var inputValue by remember { mutableStateOf(TextFieldValue("fatiman@gmail.com")) } InputEmail( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, onEmailActionCLicked = {}, state = InputShellState.UNFOCUSED, diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputIntegerTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputIntegerTest.kt index 20170bb7d..226832940 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputIntegerTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputIntegerTest.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -38,14 +39,12 @@ class InputIntegerTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -70,14 +69,12 @@ class InputIntegerTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -91,15 +88,13 @@ class InputIntegerTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("Input") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -116,7 +111,7 @@ class InputIntegerTest { rule.setContent { InputInteger( title = "Label", - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -131,7 +126,7 @@ class InputIntegerTest { rule.setContent { InputInteger( title = "Label", - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -143,14 +138,12 @@ class InputIntegerTest { @Test fun shouldNotAllowAnInitialValueOfZero() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -164,14 +157,12 @@ class InputIntegerTest { @Test fun shouldNotAllowDecimalValues() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -185,14 +176,12 @@ class InputIntegerTest { @Test fun shouldAllowNegativeValues() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetterTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetterTest.kt index 0f611e9f3..39198a6e8 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetterTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLetterTest.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -41,15 +42,13 @@ class InputLetterTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLetter( title = "Label", modifier = Modifier.testTag("INPUT_LETTER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -75,15 +74,13 @@ class InputLetterTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLetter( title = "Label", modifier = Modifier.testTag("INPUT_LETTER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -97,16 +94,14 @@ class InputLetterTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("Input") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputLetter( title = "Label", modifier = Modifier.testTag("INPUT_LETTER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) @@ -124,7 +119,7 @@ class InputLetterTest { InputLetter( title = "Label", modifier = Modifier.testTag("INPUT_LETTER"), - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -140,7 +135,7 @@ class InputLetterTest { InputLetter( title = "Label", modifier = Modifier.testTag("INPUT_LETTER"), - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -152,15 +147,13 @@ class InputLetterTest { @Test fun shouldOnlyAllowASingleUpperCaseCharacter() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLetter( title = "Label", modifier = Modifier.testTag("INPUT_LETTER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { - if (it != null) { - inputValue = it - } + inputValue = it ?: TextFieldValue() }, state = InputShellState.UNFOCUSED, ) diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLinkTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLinkTest.kt index ab58154d9..13d0f6aca 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLinkTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLinkTest.kt @@ -16,6 +16,7 @@ import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextClearance import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -42,10 +43,10 @@ class InputLinkTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLink( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -76,10 +77,10 @@ class InputLinkTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLink( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -98,11 +99,11 @@ class InputLinkTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("example.com") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("example.com")) } InputLink( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -122,11 +123,11 @@ class InputLinkTest { @Test fun shouldHideResetButtonWhenDisabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("example.com") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("example.com")) } InputLink( title = "Label", state = InputShellState.DISABLED, - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -144,7 +145,7 @@ class InputLinkTest { rule.setContent { InputLink( title = "Label", - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), onLinkActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -160,7 +161,7 @@ class InputLinkTest { rule.setContent { InputLink( title = "Label", - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), onLinkActionCLicked = {}, state = InputShellState.UNFOCUSED, @@ -173,11 +174,11 @@ class InputLinkTest { @Test fun shouldEnableLinkActionButtonOnEnteringValidLinkAddress() { rule.setContent { - var inputValue by remember { mutableStateOf("") } + var inputValue by remember { mutableStateOf(TextFieldValue()) } InputLink( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -208,11 +209,11 @@ class InputLinkTest { @Test fun shouldDisableLinkActionButtonOnEnteringInValidLinkAddress() { rule.setContent { - var inputValue by remember { mutableStateOf("example.com") } + var inputValue by remember { mutableStateOf(TextFieldValue("example.com")) } InputLink( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongTextTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongTextTest.kt index f7a6d4c79..ccd8a9eb4 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongTextTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputLongTextTest.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -41,11 +42,11 @@ class InputLongTextTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLongText( title = "Label", modifier = Modifier.testTag("INPUT_LONG_TEXT"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -75,11 +76,11 @@ class InputLongTextTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputLongText( title = "Label", modifier = Modifier.testTag("INPUT_LONG_TEXT"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -97,12 +98,12 @@ class InputLongTextTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("Input") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputLongText( title = "Label", modifier = Modifier.testTag("INPUT_LONG_TEXT"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -124,7 +125,7 @@ class InputLongTextTest { InputLongText( title = "Label", modifier = Modifier.testTag("INPUT_LONG_TEXT"), - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -140,7 +141,7 @@ class InputLongTextTest { InputLongText( title = "Label", modifier = Modifier.testTag("INPUT_LONG_TEXT"), - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeIntegerTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeIntegerTest.kt index 2f2c4edfc..b4d8d4422 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeIntegerTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNegativeIntegerTest.kt @@ -12,6 +12,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -37,10 +38,10 @@ class InputNegativeIntegerTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNegativeInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -69,10 +70,10 @@ class InputNegativeIntegerTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNegativeInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -90,11 +91,11 @@ class InputNegativeIntegerTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("1234") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } InputNegativeInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -114,7 +115,7 @@ class InputNegativeIntegerTest { rule.setContent { InputNegativeInteger( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -129,7 +130,7 @@ class InputNegativeIntegerTest { rule.setContent { InputNegativeInteger( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -141,10 +142,10 @@ class InputNegativeIntegerTest { @Test fun shouldNotAllowDecimalValues() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNegativeInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -161,10 +162,10 @@ class InputNegativeIntegerTest { @Test fun shouldNotAllowValuesWithALeadingZero() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNegativeInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumberTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumberTest.kt index 338de2fcf..d9406f007 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumberTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputNumberTest.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -41,11 +42,11 @@ class InputNumberTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNumber( title = "Label", modifier = Modifier.testTag("INPUT_NUMBER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -75,11 +76,11 @@ class InputNumberTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNumber( title = "Label", modifier = Modifier.testTag("INPUT_NUMBER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -97,12 +98,12 @@ class InputNumberTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("1234") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } InputNumber( title = "Label", modifier = Modifier.testTag("INPUT_NUMBER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -124,7 +125,7 @@ class InputNumberTest { InputNumber( title = "Label", modifier = Modifier.testTag("INPUT_NUMBER"), - inputText = "", + inputTextFieldValue = TextFieldValue(), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -140,7 +141,7 @@ class InputNumberTest { InputNumber( title = "Label", modifier = Modifier.testTag("INPUT_NUMBER"), - inputText = "", + inputTextFieldValue = TextFieldValue(), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -152,11 +153,11 @@ class InputNumberTest { @Test fun shouldAllowOnlyNumbersAsInput() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputNumber( title = "Label", modifier = Modifier.testTag("INPUT_NUMBER"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentageTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentageTest.kt index 79795d8f4..699d91348 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentageTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPercentageTest.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -38,10 +39,10 @@ class InputPercentageTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPercentage( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -70,10 +71,10 @@ class InputPercentageTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPercentage( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -91,11 +92,11 @@ class InputPercentageTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("25") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("25")) } InputPercentage( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -115,7 +116,7 @@ class InputPercentageTest { rule.setContent { InputPercentage( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -130,7 +131,7 @@ class InputPercentageTest { rule.setContent { InputPercentage( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -142,10 +143,10 @@ class InputPercentageTest { @Test fun shouldNotAllowValuesOver100() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPercentage( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -162,10 +163,10 @@ class InputPercentageTest { @Test fun shouldNotAllowValuesWithALeadingZero() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPercentage( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumberTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumberTest.kt index 20fe597fc..3af2ba0d7 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumberTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPhoneNumberTest.kt @@ -11,6 +11,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.junit.Rule import org.junit.Test @@ -22,11 +23,11 @@ class InputPhoneNumberTest { @Test fun shouldAllowDigitsInputOnly() { rule.setContent { - var inputValue by remember { mutableStateOf("") } + var inputValue by remember { mutableStateOf(TextFieldValue()) } InputPhoneNumber( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -48,11 +49,11 @@ class InputPhoneNumberTest { @Test fun shouldEnableCallActionButtonAfterInputTextReachesCharacterLimit() { rule.setContent { - var inputValue by remember { mutableStateOf("") } + var inputValue by remember { mutableStateOf(TextFieldValue()) } InputPhoneNumber( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, maxLength = 10, onValueChanged = { if (it != null) { @@ -75,7 +76,7 @@ class InputPhoneNumberTest { rule.setContent { InputPhoneNumber( title = "Phone Number", - inputText = "", + inputTextFieldValue = TextFieldValue(), state = InputShellState.UNFOCUSED, onValueChanged = { // no-op @@ -90,7 +91,7 @@ class InputPhoneNumberTest { rule.setContent { InputPhoneNumber( title = "Phone Number", - inputText = "", + inputTextFieldValue = TextFieldValue(), state = InputShellState.ERROR, onValueChanged = { // no-op @@ -107,11 +108,11 @@ class InputPhoneNumberTest { @Test fun shouldClearPhoneNumberWhenClearButtonIsClicked() { rule.setContent { - var inputValue by remember { mutableStateOf("1234") } + var inputValue by remember { mutableStateOf(TextFieldValue("1234")) } InputPhoneNumber( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) inputValue = it }, diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZeroTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZeroTest.kt index 3e35b9518..6aef58ef9 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZeroTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerOrZeroTest.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -38,10 +39,10 @@ class InputPositiveIntegerOrZeroTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -70,10 +71,10 @@ class InputPositiveIntegerOrZeroTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -91,11 +92,11 @@ class InputPositiveIntegerOrZeroTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("1234") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -116,7 +117,7 @@ class InputPositiveIntegerOrZeroTest { rule.setContent { InputPositiveIntegerOrZero( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -131,7 +132,7 @@ class InputPositiveIntegerOrZeroTest { rule.setContent { InputPositiveIntegerOrZero( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -143,10 +144,10 @@ class InputPositiveIntegerOrZeroTest { @Test fun shouldNotAllowDecimalValues() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -163,10 +164,10 @@ class InputPositiveIntegerOrZeroTest { @Test fun shouldNotAllowNegativeValues() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -183,10 +184,10 @@ class InputPositiveIntegerOrZeroTest { @Test fun shouldNotAllowValuesAfterLeadingAZero() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -203,10 +204,10 @@ class InputPositiveIntegerOrZeroTest { @Test fun shouldAllowZero() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveIntegerOrZero( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerTest.kt index b964ffcd5..925396a90 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputPositiveIntegerTest.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -38,10 +39,10 @@ class InputPositiveIntegerTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -70,10 +71,10 @@ class InputPositiveIntegerTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -91,11 +92,11 @@ class InputPositiveIntegerTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("1234") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("1234")) } InputPositiveInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -116,7 +117,7 @@ class InputPositiveIntegerTest { rule.setContent { InputPositiveInteger( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -131,7 +132,7 @@ class InputPositiveIntegerTest { rule.setContent { InputPositiveInteger( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -143,10 +144,10 @@ class InputPositiveIntegerTest { @Test fun shouldNotAllowDecimalValues() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -163,10 +164,10 @@ class InputPositiveIntegerTest { @Test fun shouldNotAllowNegativeValues() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -183,10 +184,10 @@ class InputPositiveIntegerTest { @Test fun shouldNotAllowValuesWithALeadingZero() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputPositiveInteger( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCodeTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCodeTest.kt index ae5084e14..628336d96 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCodeTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputQRCodeTest.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.test.assertTextEquals import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick +import androidx.compose.ui.text.input.TextFieldValue import org.junit.Rule import org.junit.Test @@ -20,11 +21,11 @@ class InputQRCodeTest { @Test fun shouldDisplayComponentCorrectly() { rule.setContent { - var inputValue by remember { mutableStateOf("") } + var inputValue by remember { mutableStateOf(TextFieldValue()) } InputQRCode( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -42,11 +43,11 @@ class InputQRCodeTest { @Test fun shouldDeleteContentWhenResetIsClicked() { rule.setContent { - var inputValue by remember { mutableStateOf("12345") } + var inputValue by remember { mutableStateOf(TextFieldValue("12345")) } InputQRCode( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -68,11 +69,11 @@ class InputQRCodeTest { @Test fun shouldShowActionButtonCorrectlyAndBeClickable() { rule.setContent { - var inputValue by remember { mutableStateOf("12345") } + var inputValue by remember { mutableStateOf(TextFieldValue("12345")) } InputQRCode( title = "Phone Number", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputTextTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputTextTest.kt index 00181993b..59ed14fbd 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputTextTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputTextTest.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -41,11 +42,11 @@ class InputTextTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputText( title = "Label", modifier = Modifier.testTag("INPUT_TEXT"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -75,11 +76,11 @@ class InputTextTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputText( title = "Label", modifier = Modifier.testTag("INPUT_TEXT"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -97,12 +98,12 @@ class InputTextTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("Input") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("Input")) } InputText( title = "Label", modifier = Modifier.testTag("INPUT_TEXT"), - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -124,7 +125,7 @@ class InputTextTest { InputText( title = "Label", modifier = Modifier.testTag("INPUT_TEXT"), - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -140,7 +141,7 @@ class InputTextTest { InputText( title = "Label", modifier = Modifier.testTag("INPUT_TEXT"), - inputText = "Input", + inputTextFieldValue = TextFieldValue("Input"), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitIntervalTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitIntervalTest.kt index 5542e6e4b..04cde78ea 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitIntervalTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputUnitIntervalTest.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.text.input.TextFieldValue import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor import org.junit.Rule import org.junit.Test @@ -38,10 +39,10 @@ class InputUnitIntervalTest { @Test fun shouldAllowUserInputWhenEnabled() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputUnitInterval( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -70,10 +71,10 @@ class InputUnitIntervalTest { @Test fun shouldShowResetButtonWhenTextFieldHasContent() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputUnitInterval( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -91,11 +92,11 @@ class InputUnitIntervalTest { @Test fun shouldDeleteContentWhenResetButtonIsClickedAndHideResetButton() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("0.25") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue("0.25")) } InputUnitInterval( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -115,7 +116,7 @@ class InputUnitIntervalTest { rule.setContent { InputUnitInterval( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), legendData = LegendData(SurfaceColor.CustomGreen, "Legend"), state = InputShellState.UNFOCUSED, ) @@ -130,7 +131,7 @@ class InputUnitIntervalTest { rule.setContent { InputUnitInterval( title = "Label", - inputText = "", + inputTextFieldValue = TextFieldValue(), supportingText = listOf(SupportingTextData("Supporting text", SupportingTextState.DEFAULT)), state = InputShellState.UNFOCUSED, ) @@ -142,10 +143,10 @@ class InputUnitIntervalTest { @Test fun shouldNotAllowValuesOver1() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputUnitInterval( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it @@ -162,10 +163,10 @@ class InputUnitIntervalTest { @Test fun shouldNotAllowValuesBelow0() { rule.setContent { - var inputValue by rememberSaveable { mutableStateOf("") } + var inputValue by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } InputUnitInterval( title = "Label", - inputText = inputValue, + inputTextFieldValue = inputValue, onValueChanged = { if (it != null) { inputValue = it