diff --git a/pin/src/main/java/ua/gov/diia/pin/ui/Utils.kt b/pin/src/main/java/ua/gov/diia/pin/ui/Utils.kt new file mode 100644 index 0000000..0ce2252 --- /dev/null +++ b/pin/src/main/java/ua/gov/diia/pin/ui/Utils.kt @@ -0,0 +1,38 @@ +package ua.gov.diia.pin.ui + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.remember +import ua.gov.diia.ui_base.R +import ua.gov.diia.ui_base.components.DiiaResourceIcon +import ua.gov.diia.ui_base.components.atom.text.textwithparameter.TextWithParametersData +import ua.gov.diia.ui_base.components.infrastructure.DataActionWrapper +import ua.gov.diia.ui_base.components.infrastructure.utils.resource.UiText +import ua.gov.diia.ui_base.components.molecule.header.TitleGroupMlcData +import ua.gov.diia.ui_base.components.organism.header.TopGroupOrgData +import ua.gov.diia.ui_base.components.organism.tile.NumButtonTileOrganismData + +@Composable +inline fun List.asSnapshotStateList() = + remember { mutableStateListOf(*this.toTypedArray()) } + +fun getPinTestData(headerText: String, bodyText: String, pinLength: Int = 4) = listOf( + TopGroupOrgData( + titleGroupMlcData = TitleGroupMlcData( + heroText = UiText.DynamicString(headerText), + leftNavIcon = TitleGroupMlcData.LeftNavIcon( + code = DiiaResourceIcon.BACK.code, + accessibilityDescription = UiText.StringResource(R.string.accessibility_back_button), + action = DataActionWrapper( + type = "back", + subtype = null, + resource = null + ) + ) + ) + ), + TextWithParametersData( + text = UiText.DynamicString(bodyText) + ), + NumButtonTileOrganismData(pinLength = pinLength) +) \ No newline at end of file diff --git a/pin/src/main/java/ua/gov/diia/pin/ui/create/compose/CreatePinScreen.kt b/pin/src/main/java/ua/gov/diia/pin/ui/create/compose/CreatePinScreen.kt index 3428ad1..5f3b05f 100644 --- a/pin/src/main/java/ua/gov/diia/pin/ui/create/compose/CreatePinScreen.kt +++ b/pin/src/main/java/ua/gov/diia/pin/ui/create/compose/CreatePinScreen.kt @@ -3,8 +3,6 @@ package ua.gov.diia.pin.ui.create.compose import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateListOf -import androidx.compose.runtime.remember import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.ui.Modifier import androidx.compose.ui.draw.paint @@ -12,14 +10,11 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout +import ua.gov.diia.pin.ui.asSnapshotStateList +import ua.gov.diia.pin.ui.getPinTestData import ua.gov.diia.ui_base.R -import ua.gov.diia.ui_base.components.DiiaResourceIcon -import ua.gov.diia.ui_base.components.atom.text.textwithparameter.TextWithParametersData -import ua.gov.diia.ui_base.components.infrastructure.DataActionWrapper import ua.gov.diia.ui_base.components.infrastructure.UIElementData import ua.gov.diia.ui_base.components.infrastructure.event.UIAction -import ua.gov.diia.ui_base.components.infrastructure.utils.resource.UiText -import ua.gov.diia.ui_base.components.molecule.header.TitleGroupMlcData import ua.gov.diia.ui_base.components.molecule.text.TextLabelMlc import ua.gov.diia.ui_base.components.molecule.text.TextLabelMlcData import ua.gov.diia.ui_base.components.organism.header.TopGroupOrg @@ -89,66 +84,24 @@ fun CreatePinScreen( } } +private val testData = getPinTestData( + headerText = "Повторіть код з 4 цифр", + bodyText = "Цей код ви будете вводити для входу у застосунок Дія.", + pinLength = 5 +) + @Composable @Preview fun CreatePinScreenPreview() { - val _uiData = remember { mutableStateListOf() } - val uiData: SnapshotStateList = _uiData - _uiData.add( - TopGroupOrgData( - titleGroupMlcData = TitleGroupMlcData( - heroText = UiText.DynamicString("Повторіть код з 4 цифр"), - leftNavIcon = TitleGroupMlcData.LeftNavIcon( - code = DiiaResourceIcon.BACK.code, - accessibilityDescription = UiText.StringResource(R.string.accessibility_back_button), - action = DataActionWrapper( - type = "back", - subtype = null, - resource = null - ) - ) - ) - ) - ) - _uiData.add( - TextLabelMlcData( - text = UiText.DynamicString("Цей код ви будете вводити для входу у застосунок Дія.") - ) - ) - _uiData.add( - NumButtonTileOrganismData() - ) + val uiData = testData.asSnapshotStateList() + CreatePinScreen(data = uiData, onUIAction = { }) } @Composable @Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480") fun CreatePinScreenPreview_small_screen() { - val _uiData = remember { mutableStateListOf() } - val uiData: SnapshotStateList = _uiData - _uiData.add( - TopGroupOrgData( - titleGroupMlcData = TitleGroupMlcData( - heroText = UiText.DynamicString("Повторіть код з 4 цифр"), - leftNavIcon = TitleGroupMlcData.LeftNavIcon( - code = DiiaResourceIcon.BACK.code, - accessibilityDescription = UiText.StringResource(R.string.accessibility_back_button), - action = DataActionWrapper( - type = "back", - subtype = null, - resource = null - ) - ) - ) - ) - ) - _uiData.add( - TextWithParametersData( - text = UiText.DynamicString("Цей код ви будете вводити для входу у застосунок Дія.") - ) - ) - _uiData.add( - NumButtonTileOrganismData(pinLength = 5) - ) + val uiData = testData.asSnapshotStateList() + CreatePinScreen(data = uiData, onUIAction = { }) } \ No newline at end of file diff --git a/pin/src/main/java/ua/gov/diia/pin/ui/reset/compose/ResetPinScreen.kt b/pin/src/main/java/ua/gov/diia/pin/ui/reset/compose/ResetPinScreen.kt index 0a289a3..5af8527 100644 --- a/pin/src/main/java/ua/gov/diia/pin/ui/reset/compose/ResetPinScreen.kt +++ b/pin/src/main/java/ua/gov/diia/pin/ui/reset/compose/ResetPinScreen.kt @@ -2,31 +2,15 @@ package ua.gov.diia.pin.ui.reset.compose import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateListOf -import androidx.compose.runtime.remember import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.paint -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview -import androidx.constraintlayout.compose.ConstraintLayout -import ua.gov.diia.ui_base.R -import ua.gov.diia.ui_base.components.DiiaResourceIcon -import ua.gov.diia.ui_base.components.infrastructure.DataActionWrapper +import ua.gov.diia.pin.ui.asSnapshotStateList +import ua.gov.diia.pin.ui.create.compose.CreatePinScreen +import ua.gov.diia.pin.ui.getPinTestData import ua.gov.diia.ui_base.components.infrastructure.UIElementData import ua.gov.diia.ui_base.components.infrastructure.event.UIAction -import ua.gov.diia.ui_base.components.infrastructure.utils.resource.UiText -import ua.gov.diia.ui_base.components.molecule.header.TitleGroupMlcData -import ua.gov.diia.ui_base.components.molecule.text.TextLabelMlc -import ua.gov.diia.ui_base.components.molecule.text.TextLabelMlcData -import ua.gov.diia.ui_base.components.organism.header.TopGroupOrg -import ua.gov.diia.ui_base.components.organism.header.TopGroupOrgData -import ua.gov.diia.ui_base.components.organism.tile.NumButtonTileOrganism -import ua.gov.diia.ui_base.components.organism.tile.NumButtonTileOrganismData -import ua.gov.diia.ui_base.components.provideTestTagsAsResourceId import ua.gov.diia.ui_base.components.subatomic.loader.TridentLoaderWithUIBlocking @@ -38,123 +22,32 @@ fun ResetPinScreen( onUIAction: (UIAction) -> Unit ) { Box(modifier = Modifier.fillMaxSize()) { - ConstraintLayout( - modifier = modifier - .fillMaxSize() - .paint( - painterResource(id = R.drawable.bg_blue_yellow_gradient), - contentScale = ContentScale.FillBounds - ) - .safeDrawingPadding() - .provideTestTagsAsResourceId() - ) { - val title = createRef() - val numButton = createRef() - val descriptionText = createRef() - data.forEach { item -> - if (item is TopGroupOrgData) { - TopGroupOrg( - modifier = modifier - .constrainAs(title) { - start.linkTo(parent.start) - end.linkTo(parent.end) - top.linkTo(parent.top) - }, - data = item, - onUIAction = onUIAction - ) - } - - if (item is TextLabelMlcData) { - TextLabelMlc( - modifier = modifier - .constrainAs(descriptionText) { - top.linkTo(title.bottom) - }, - data = item, - onUIAction = onUIAction - ) - } - if (item is NumButtonTileOrganismData) { - NumButtonTileOrganism( - modifier = Modifier - .constrainAs(numButton) { - linkTo( - top = descriptionText.bottom, - bottom = parent.bottom, - bias = 0.3f - ) - }, - data = item, - onUIAction = onUIAction - ) - } - } - } + CreatePinScreen( + modifier = modifier, + data = data, + onUIAction = onUIAction + ) TridentLoaderWithUIBlocking(contentLoaded = contentLoaded) } } +private val testData = getPinTestData( + headerText = "Повторіть код з 4 цифр", + bodyText = "Щоб впевнитися, що це ви змінюєте код для входу.", +) + @Composable @Preview fun ResetPinScreenPreview() { - val _uiData = remember { mutableStateListOf() } - val uiData: SnapshotStateList = _uiData - _uiData.add( - TopGroupOrgData( - titleGroupMlcData = TitleGroupMlcData( - heroText = UiText.DynamicString("Повторіть код з 4 цифр"), - leftNavIcon = TitleGroupMlcData.LeftNavIcon( - code = DiiaResourceIcon.BACK.code, - accessibilityDescription = UiText.StringResource(R.string.accessibility_back_button), - action = DataActionWrapper( - type = "back", - subtype = null, - resource = null - ) - ) - ) - ) - ) - _uiData.add( - TextLabelMlcData( - text = UiText.DynamicString("Щоб впевнитися, що це ви змінюєте код для входу.") - ) - ) - _uiData.add( - NumButtonTileOrganismData() - ) + val uiData = testData.asSnapshotStateList() + ResetPinScreen(data = uiData, contentLoaded = "" to true, onUIAction = { }) } @Composable @Preview(name = "phone", device = "spec:shape=Normal,width=360,height=640,unit=dp,dpi=480") fun ResetPinScreenPreview_small_screen() { - val _uiData = remember { mutableStateListOf() } - val uiData: SnapshotStateList = _uiData - _uiData.add( - TopGroupOrgData( - titleGroupMlcData = TitleGroupMlcData( - heroText = UiText.DynamicString("Повторіть код з 4 цифр"), - leftNavIcon = TitleGroupMlcData.LeftNavIcon( - code = DiiaResourceIcon.BACK.code, - accessibilityDescription = UiText.StringResource(R.string.accessibility_back_button), - action = DataActionWrapper( - type = "back", - subtype = null, - resource = null - ) - ) - ) - ) - ) - _uiData.add( - TextLabelMlcData( - text = UiText.DynamicString("Щоб впевнитися, що це ви змінюєте код для входу.") - ) - ) - _uiData.add( - NumButtonTileOrganismData() - ) + val uiData = testData.asSnapshotStateList() + ResetPinScreen(data = uiData, contentLoaded = "" to true, onUIAction = { }) } \ No newline at end of file