Skip to content

Commit 8d953d1

Browse files
committed
Apply default styling for AndroidView in Header
1 parent 7308b70 commit 8d953d1

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

datacapture/src/main/java/com/google/android/fhir/datacapture/extensions/MoreQuestionItemStyle.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 Google LLC
2+
* Copyright 2024-2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ import com.google.android.fhir.datacapture.R
2929
*
3030
* If the custom style resource name is valid, it applies the custom style to the view. If the
3131
* custom style resource name is not valid or not found, it falls back to applying the default style
32-
* defined by the given style resource ID. It sets the view's tag to resourceId to indicate that the
33-
* custom style has been applied.
32+
* defined by the given style resource ID.
3433
*
3534
* @param context the context used to access resources.
3635
* @param view the view to which the style should be applied.
@@ -46,7 +45,6 @@ internal fun applyCustomOrDefaultStyle(
4645
val customStyleResId = customStyleName?.let { getStyleResIdByName(context, it) } ?: 0
4746
when {
4847
customStyleResId != 0 -> {
49-
view.tag = customStyleResId
5048
QuestionItemCustomStyle().applyStyle(context, view, customStyleResId)
5149
}
5250
defaultStyleResId != 0 -> {
@@ -58,11 +56,6 @@ internal fun applyCustomOrDefaultStyle(
5856
/**
5957
* Applies the default style to the given view if the default style has not already been applied.
6058
*
61-
* This function checks the `view`'s tag to determine if a style has been previously applied. If the
62-
* tag is an integer, it will apply the default style specified by `defaultStyleResId`. After
63-
* applying the style, it resets the view's tag to `null` to indicate that the default style has
64-
* been applied.
65-
*
6659
* @param context The context used to access resources and themes.
6760
* @param view The view to which the default style will be applied.
6861
* @param defaultStyleResId The resource ID of the default style to apply.
@@ -72,10 +65,7 @@ private fun applyDefaultStyleIfNotApplied(
7265
view: View,
7366
defaultStyleResId: Int,
7467
) {
75-
(view.tag as? Int)?.let {
76-
QuestionItemDefaultStyle().applyStyle(context, view, defaultStyleResId)
77-
view.tag = null
78-
}
68+
QuestionItemDefaultStyle().applyStyle(context, view, defaultStyleResId)
7969
}
8070

8171
/**

datacapture/src/main/java/com/google/android/fhir/datacapture/views/compose/Header.kt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.padding
2727
import androidx.compose.foundation.layout.size
2828
import androidx.compose.foundation.layout.width
2929
import androidx.compose.material3.Card
30+
import androidx.compose.material3.CardDefaults
3031
import androidx.compose.material3.Icon
3132
import androidx.compose.material3.IconButton
3233
import androidx.compose.material3.MaterialTheme
@@ -43,9 +44,9 @@ import androidx.compose.ui.platform.testTag
4344
import androidx.compose.ui.res.dimensionResource
4445
import androidx.compose.ui.res.painterResource
4546
import androidx.compose.ui.res.stringResource
46-
import androidx.compose.ui.unit.dp
4747
import androidx.compose.ui.viewinterop.AndroidView
4848
import com.google.android.fhir.datacapture.R
49+
import com.google.android.fhir.datacapture.extensions.QuestionItemDefaultStyle
4950
import com.google.android.fhir.datacapture.extensions.StyleUrl
5051
import com.google.android.fhir.datacapture.extensions.appendAsteriskToQuestionText
5152
import com.google.android.fhir.datacapture.extensions.applyCustomOrDefaultStyle
@@ -254,7 +255,8 @@ internal fun Help(
254255
helpButtonOnClick(isCardOpen)
255256
},
256257
modifier =
257-
Modifier.padding(start = dimensionResource(R.dimen.help_button_margin_start))
258+
Modifier.padding(dimensionResource(R.dimen.help_icon_padding))
259+
.padding(start = dimensionResource(R.dimen.help_button_margin_start))
258260
.testTag(HELP_BUTTON_TAG)
259261
.size(
260262
width = dimensionResource(R.dimen.help_button_width),
@@ -270,12 +272,22 @@ internal fun Help(
270272
}
271273

272274
if (isCardOpen) {
273-
Card(modifier = Modifier.padding(top = 8.dp).testTag(HELP_CARD_TAG)) {
274-
Column(modifier = Modifier.padding(8.dp)) {
275+
Card(
276+
modifier =
277+
Modifier.padding(top = dimensionResource(R.dimen.help_card_margin_top))
278+
.testTag(HELP_CARD_TAG),
279+
colors =
280+
CardDefaults.cardColors().copy(containerColor = MaterialTheme.colorScheme.surfaceVariant),
281+
) {
282+
Column {
275283
Text(
276284
text = stringResource(id = R.string.help),
277285
modifier =
278-
Modifier.padding(horizontal = dimensionResource(R.dimen.help_header_margin_horizontal)),
286+
Modifier.padding(horizontal = dimensionResource(R.dimen.help_header_margin_horizontal))
287+
.padding(
288+
top = dimensionResource(R.dimen.help_header_margin_top),
289+
bottom = dimensionResource(R.dimen.help_header_margin_bottom),
290+
),
279291
style = MaterialTheme.typography.titleSmall,
280292
)
281293

@@ -284,10 +296,18 @@ internal fun Help(
284296
TextView(it).apply {
285297
id = R.id.helpText
286298
movementMethod = LinkMovementMethod.getInstance()
299+
300+
QuestionItemDefaultStyle()
301+
.applyStyle(
302+
context,
303+
this,
304+
getStyleResIdFromAttribute(it, R.attr.questionnaireHelpTextStyle),
305+
)
287306
}
288307
},
289308
modifier =
290-
Modifier.padding(horizontal = dimensionResource(R.dimen.help_text_margin_horizontal)),
309+
Modifier.padding(horizontal = dimensionResource(R.dimen.help_text_margin_horizontal))
310+
.padding(bottom = dimensionResource(R.dimen.help_text_margin_bottom)),
291311
update = { it.text = helpCardLocalizedText },
292312
)
293313
}

0 commit comments

Comments
 (0)