Skip to content

Commit 9c618a3

Browse files
authored
Fix QuestionnaireItem's title styling in Header, for compose (#2901)
* Fix compose Header space padding * Apply default styling for AndroidView in Header * Rename applyDefaultStyleIfNotApplied to better fit applyDefaultStyle
1 parent e5547a3 commit 9c618a3

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal fun applyCustomOrDefaultStyle(
4848
QuestionItemCustomStyle().applyStyle(context, view, customStyleResId)
4949
}
5050
defaultStyleResId != 0 -> {
51-
applyDefaultStyleIfNotApplied(context, view, defaultStyleResId)
51+
applyDefaultStyle(context, view, defaultStyleResId)
5252
}
5353
}
5454
}
@@ -60,7 +60,7 @@ internal fun applyCustomOrDefaultStyle(
6060
* @param view The view to which the default style will be applied.
6161
* @param defaultStyleResId The resource ID of the default style to apply.
6262
*/
63-
private fun applyDefaultStyleIfNotApplied(
63+
private fun applyDefaultStyle(
6464
context: Context,
6565
view: View,
6666
defaultStyleResId: Int,

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

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,16 @@ internal fun Header(
136136
) {
137137
PrefixQuestionTitle(prefixLocalizedText, questionLocalizedText, readCustomStyleName)
138138

139-
Help(
140-
hintLocalizedText,
141-
readCustomStyleName,
142-
isHelpCardOpen,
143-
isHelpButtonVisible,
144-
helpButtonOnClick,
145-
helpCardLocalizedText,
146-
)
139+
if (!hintLocalizedText.isNullOrBlank() || isHelpButtonVisible || isHelpCardOpen) {
140+
Help(
141+
hintLocalizedText,
142+
readCustomStyleName,
143+
isHelpCardOpen,
144+
isHelpButtonVisible,
145+
helpButtonOnClick,
146+
helpCardLocalizedText,
147+
)
148+
}
147149

148150
// Required/Optional Text
149151
if (showRequiredOrOptionalText && !requiredOptionalText.isNullOrBlank()) {
@@ -225,28 +227,31 @@ internal fun Help(
225227
var isCardOpen by remember { mutableStateOf(isHelpCardInitiallyOpen) }
226228

227229
Row(
228-
modifier = Modifier.padding(vertical = dimensionResource(R.dimen.help_container_margin_top)),
230+
modifier = Modifier.padding(top = dimensionResource(R.dimen.help_container_margin_top)),
229231
verticalAlignment = Alignment.CenterVertically,
230232
) {
231-
AndroidView(
232-
factory = {
233-
TextView(it).apply {
234-
id = R.id.hint
235-
movementMethod = LinkMovementMethod.getInstance()
236-
applyCustomOrDefaultStyle(
237-
context = it,
238-
view = this,
239-
customStyleName =
240-
readCustomStyleName(
241-
StyleUrl.SUBTITLE_TEXT_VIEW,
242-
),
243-
defaultStyleResId =
244-
getStyleResIdFromAttribute(it, R.attr.questionnaireSubtitleTextStyle),
245-
)
246-
}
247-
},
248-
update = { it.text = hintLocalizedText },
249-
)
233+
hintLocalizedText?.let {
234+
AndroidView(
235+
modifier = Modifier.weight(0.7f),
236+
factory = {
237+
TextView(it).apply {
238+
id = R.id.hint
239+
movementMethod = LinkMovementMethod.getInstance()
240+
applyCustomOrDefaultStyle(
241+
context = it,
242+
view = this,
243+
customStyleName =
244+
readCustomStyleName(
245+
StyleUrl.SUBTITLE_TEXT_VIEW,
246+
),
247+
defaultStyleResId =
248+
getStyleResIdFromAttribute(it, R.attr.questionnaireSubtitleTextStyle),
249+
)
250+
}
251+
},
252+
update = { it.text = hintLocalizedText },
253+
)
254+
}
250255

251256
if (isHelpButtonVisible) {
252257
IconButton(
@@ -258,6 +263,7 @@ internal fun Help(
258263
Modifier.padding(dimensionResource(R.dimen.help_icon_padding))
259264
.padding(start = dimensionResource(R.dimen.help_button_margin_start))
260265
.testTag(HELP_BUTTON_TAG)
266+
.weight(0.3f)
261267
.size(
262268
width = dimensionResource(R.dimen.help_button_width),
263269
height = dimensionResource(R.dimen.help_button_height),

0 commit comments

Comments
 (0)