From d141b921fa97b4ed7a6a81cb391dd524f76d3fab Mon Sep 17 00:00:00 2001 From: Boonapart Date: Mon, 14 Jul 2025 14:31:40 +0300 Subject: [PATCH] Add QuestionItem to core --- design/api/current.api | 66 ++++++++++++++ .../ui/question/models/QuestionColors.kt | 10 ++ .../ui/question/models/QuestionConstants.kt | 7 ++ .../ui/question/models/QuestionDimen.kt | 14 +++ .../design/ui/question/ui/QuestionItem.kt | 91 +++++++++++++++++++ 5 files changed, 188 insertions(+) create mode 100644 design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionColors.kt create mode 100644 design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionConstants.kt create mode 100644 design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionDimen.kt create mode 100644 design/src/main/java/com/urlaunched/android/design/ui/question/ui/QuestionItem.kt diff --git a/design/api/current.api b/design/api/current.api index 52f02a66..90966c69 100644 --- a/design/api/current.api +++ b/design/api/current.api @@ -253,6 +253,72 @@ package com.urlaunched.android.design.ui.pulltorefresh { } +package com.urlaunched.android.design.ui.question.models { + + public final class QuestionColors { + ctor public QuestionColors(optional long borderColor, optional long driverColor, optional long questionTextColor, optional long answerTextColor); + method public long component1-0d7_KjU(); + method public long component2-0d7_KjU(); + method public long component3-0d7_KjU(); + method public long component4-0d7_KjU(); + method public com.urlaunched.android.design.ui.question.models.QuestionColors copy-jRlVdoo(long borderColor, long driverColor, long questionTextColor, long answerTextColor); + method public long getAnswerTextColor(); + method public long getBorderColor(); + method public long getDriverColor(); + method public long getQuestionTextColor(); + property public final long answerTextColor; + property public final long borderColor; + property public final long driverColor; + property public final long questionTextColor; + } + + public final class QuestionConstants { + ctor public QuestionConstants(optional float rotateAngleArrow, optional float defaultAngleArrow, optional String rotateStateArrowLabel); + method public float component1(); + method public float component2(); + method public String component3(); + method public com.urlaunched.android.design.ui.question.models.QuestionConstants copy(float rotateAngleArrow, float defaultAngleArrow, String rotateStateArrowLabel); + method public float getDefaultAngleArrow(); + method public float getRotateAngleArrow(); + method public String getRotateStateArrowLabel(); + property public final float defaultAngleArrow; + property public final float rotateAngleArrow; + property public final String rotateStateArrowLabel; + } + + public final class QuestionDimens { + ctor public QuestionDimens(optional float borderWidth, optional float borderShape, optional float horizontalPadding, optional float minHeight, optional float answerTextVerticalPadding, optional float questionButtonSpacing); + method public float component1-D9Ej5fM(); + method public float component2-D9Ej5fM(); + method public float component3-D9Ej5fM(); + method public float component4-D9Ej5fM(); + method public float component5-D9Ej5fM(); + method public float component6-D9Ej5fM(); + method public com.urlaunched.android.design.ui.question.models.QuestionDimens copy-erZIsFM(float borderWidth, float borderShape, float horizontalPadding, float minHeight, float answerTextVerticalPadding, float questionButtonSpacing); + method public float getAnswerTextVerticalPadding(); + method public float getBorderShape(); + method public float getBorderWidth(); + method public float getHorizontalPadding(); + method public float getMinHeight(); + method public float getQuestionButtonSpacing(); + property public final float answerTextVerticalPadding; + property public final float borderShape; + property public final float borderWidth; + property public final float horizontalPadding; + property public final float minHeight; + property public final float questionButtonSpacing; + } + +} + +package com.urlaunched.android.design.ui.question.ui { + + public final class QuestionItemKt { + method @androidx.compose.runtime.Composable public static void QuestionItem(optional androidx.compose.ui.Modifier modifier, String questionText, String answerText, androidx.compose.ui.text.TextStyle questionTextStyle, androidx.compose.ui.text.TextStyle answerTextStyle, optional com.urlaunched.android.design.ui.question.models.QuestionDimens questionDimens, optional com.urlaunched.android.design.ui.question.models.QuestionConstants questionConstants, optional com.urlaunched.android.design.ui.question.models.QuestionColors questionColors, kotlin.jvm.functions.Function1 arrowButton); + } + +} + package com.urlaunched.android.design.ui.scrollbar { public final class ColumnScrollbarKt { diff --git a/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionColors.kt b/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionColors.kt new file mode 100644 index 00000000..546e56d8 --- /dev/null +++ b/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionColors.kt @@ -0,0 +1,10 @@ +package com.urlaunched.android.design.ui.question.models + +import androidx.compose.ui.graphics.Color + +data class QuestionColors( + val borderColor: Color = Color.Black, + val driverColor: Color = Color.Black, + val questionTextColor: Color = Color.Black, + val answerTextColor: Color = Color.Black +) \ No newline at end of file diff --git a/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionConstants.kt b/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionConstants.kt new file mode 100644 index 00000000..d39fcfa7 --- /dev/null +++ b/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionConstants.kt @@ -0,0 +1,7 @@ +package com.urlaunched.android.design.ui.question.models + +data class QuestionConstants( + val rotateAngleArrow: Float = 180f, + val defaultAngleArrow: Float = 0f, + val rotateStateArrowLabel: String = "rotate_state_arrow", +) diff --git a/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionDimen.kt b/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionDimen.kt new file mode 100644 index 00000000..44ac9699 --- /dev/null +++ b/design/src/main/java/com/urlaunched/android/design/ui/question/models/QuestionDimen.kt @@ -0,0 +1,14 @@ +package com.urlaunched.android.design.ui.question.models + +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.urlaunched.android.design.resources.dimens.Dimens + +data class QuestionDimens( + val borderWidth: Dp = 1.dp, + val borderShape: Dp = 14.dp, + val horizontalPadding: Dp = Dimens.spacingNormalSpecial, + val minHeight: Dp = 64.dp, + val answerTextVerticalPadding: Dp = Dimens.spacingNormalSpecial, + val questionButtonSpacing: Dp = Dimens.spacingNormalSpecial, +) \ No newline at end of file diff --git a/design/src/main/java/com/urlaunched/android/design/ui/question/ui/QuestionItem.kt b/design/src/main/java/com/urlaunched/android/design/ui/question/ui/QuestionItem.kt new file mode 100644 index 00000000..4d6e3227 --- /dev/null +++ b/design/src/main/java/com/urlaunched/android/design/ui/question/ui/QuestionItem.kt @@ -0,0 +1,91 @@ +package com.urlaunched.android.design.ui.question.ui + +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.defaultMinSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.selection.toggleable +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Divider +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.TextStyle +import com.urlaunched.android.design.ui.question.models.QuestionColors +import com.urlaunched.android.design.ui.question.models.QuestionConstants +import com.urlaunched.android.design.ui.question.models.QuestionDimens + +@Composable +fun QuestionItem( + modifier: Modifier = Modifier, + questionText: String, + answerText: String, + questionTextStyle: TextStyle, + answerTextStyle: TextStyle, + questionDimens: QuestionDimens = QuestionDimens(), + questionConstants: QuestionConstants = QuestionConstants(), + questionColors: QuestionColors = QuestionColors(), + arrowButton: @Composable (rotation: Float) -> Unit +) { + var expanded by rememberSaveable { mutableStateOf(false) } + + val rotateState by animateFloatAsState( + targetValue = if (expanded) questionConstants.rotateAngleArrow else questionConstants.defaultAngleArrow, + label = questionConstants.rotateStateArrowLabel + ) + + Column( + modifier + .border( + border = BorderStroke(width = questionDimens.borderWidth, color = questionColors.borderColor), + shape = RoundedCornerShape(questionDimens.borderShape) + ) + .toggleable( + value = expanded, + onValueChange = { value -> + expanded = value + }, + indication = null, + interactionSource = null + ) + .padding(horizontal = questionDimens.horizontalPadding) + ) { + Row( + modifier = Modifier.defaultMinSize(minHeight = questionDimens.minHeight), + verticalAlignment = Alignment.CenterVertically + ) { + Text( + modifier = Modifier.weight(1f), + text = questionText, + style = questionTextStyle, + color = questionColors.questionTextColor + ) + + Spacer(modifier = Modifier.width(questionDimens.questionButtonSpacing)) + + arrowButton(rotateState) + } + + Divider(color = questionColors.driverColor) + + AnimatedVisibility(visible = expanded) { + Text( + modifier = Modifier.padding(vertical = questionDimens.answerTextVerticalPadding), + text = answerText, + style = answerTextStyle, + color = questionColors.answerTextColor + ) + } + } +} \ No newline at end of file