From c18fc64541b9627fa46fd2a51f01ab01f8aa6ecb Mon Sep 17 00:00:00 2001 From: Jose Jimenez Date: Tue, 17 Nov 2026 10:39:08 -0500 Subject: [PATCH 1/2] feat: add theme-configurable collapsible privacy notice - Add opt-in inline expansion with Read more and Show less controls - Support an optional summary or configurable line-limited preview - Show expansion controls only when additional content exists - Preserve linked text in the expanded notice - Keep existing notices fully expanded by default - Add accessibility support, tests, documentation, and demo configuration --- Documentation/style-guide.md | 24 +++++ .../messages/PrivacyNoticeViewTest.kt | 93 +++++++++++++++++++ .../components/messages/PrivacyNoticeView.kt | 78 ++++++++++++++-- .../ui/theme/ConciergeThemeModels.kt | 16 +++- .../mobile/concierge/ui/theme/ThemeParser.kt | 26 +++++- .../concierge/src/main/res/values/strings.xml | 4 + .../ui/theme/PrivacyNoticeConfigTest.kt | 34 ++++++- code/testapp/src/main/assets/themeDemo.json | 8 +- 8 files changed, 270 insertions(+), 13 deletions(-) diff --git a/Documentation/style-guide.md b/Documentation/style-guide.md index 3d9ed238..9a9a1097 100644 --- a/Documentation/style-guide.md +++ b/Documentation/style-guide.md @@ -367,6 +367,11 @@ Feature toggles and interaction configuration. | `behavior.privacyNotice.title` | string | `"Privacy Notice"` | Heading shown above the notice body. Blank hides only the heading. When omitted, the SDK uses its `concierge_privacy_notice_title` string resource, which apps can localize. | | `behavior.privacyNotice.text` | string | `""` | Notice copy with optional `{Label}` placeholders; absent, empty, or whitespace-only text hides the notice. | | `behavior.privacyNotice.links` | array | `[]` | Link objects use the same `{ "text": "...", "url": "..." }` shape as disclaimer links. The first exact label match is used. A link whose URL is blank or malformed renders as plain, unlinked text. | +| `behavior.privacyNotice.presentation` | string | `"inline"` | `"inline"` shows the full notice; `"collapsible"` starts collapsed and expands in place. | +| `behavior.privacyNotice.summary` | string | `""` | Optional approved summary for the collapsed notice; blank uses a line-limited preview. | +| `behavior.privacyNotice.collapsedMaxLines` | positive integer | `3` | Maximum preview lines when no summary is provided; short notices have no toggle. | +| `behavior.privacyNotice.readMoreLabel` | string | `"Read more"` | Expansion label; omitted uses the localizable `concierge_privacy_notice_read_more` resource. | +| `behavior.privacyNotice.showLessLabel` | string | `"Show less"` | Collapse label; omitted uses the localizable `concierge_privacy_notice_show_less` resource. | The notice is informational and does not block submission or require acknowledgment. It appears immediately before the first user-authored text message in a conversation, @@ -380,6 +385,15 @@ runs first, then App Links, an in-app web view for `http`/`https`, or the system for other schemes. `javascript`, `file`, `content`, `intent`, and `data` URLs are ignored. Taps are tracked as link clicks with origin `privacyNotice`. +Use `"presentation": "collapsible"` to opt in without changing existing themes. Supply an +approved `summary` to keep essential information visible; summaries are not truncated. +Without a summary, the full text is previewed with an ellipsis only when it exceeds +`collapsedMaxLines`. Expansion pushes subsequent messages down; collapse restores the compact +card. There is no automatic animation or modal. Links become interactive in the full notice, +using the same routing and tracking as inline notices. Invalid presentation values and +nonpositive line limits fail decoding. Select **Demo Theme** in the test app to try sample copy; +replace it with approved legal copy before release. + > **Strict decoding:** unlike other `behavior` keys, a wrong type anywhere under > `privacyNotice` (for example `"title": 42` or `"links": {}`) fails theme decoding, so the > whole theme falls back to the defaults and an error is logged. This matches iOS. Missing @@ -466,6 +480,11 @@ Before a vote, both thumbs use the concierge message text color. After a vote, t "privacyNotice": { "title": "Privacy Notice", "text": "Your messages are processed by {Company}.", + "presentation": "inline", + "summary": "", + "collapsedMaxLines": 3, + "readMoreLabel": "Read more", + "showLessLabel": "Show less", "links": [ {"text": "Company", "url": "https://example.com/privacy"} ] @@ -1530,6 +1549,11 @@ This section documents which properties are fully implemented, partially impleme | `behavior.privacyNotice.title` | ✅ | Optional heading; blank hides only the heading | `PrivacyNoticeView` | | `behavior.privacyNotice.text` | ✅ | First user-message transcript notice; blank body hides the card | `MessageList` → `PrivacyNoticeView` | | `behavior.privacyNotice.links` | ✅ | Brace placeholders share the disclaimer formatter; links use the shared chat link handling with origin `privacyNotice` | `PrivacyNoticeView` | +| `behavior.privacyNotice.presentation` | ✅ | Opt-in inline expansion | `PrivacyNoticeView` | +| `behavior.privacyNotice.summary` | ✅ | Authored collapsed summary | `PrivacyNoticeView` | +| `behavior.privacyNotice.collapsedMaxLines` | ✅ | Overflow-aware preview | `PrivacyNoticeView` | +| `behavior.privacyNotice.readMoreLabel` | ✅ | Localizable expansion label | `PrivacyNoticeView` | +| `behavior.privacyNotice.showLessLabel` | ✅ | Localizable collapse label | `PrivacyNoticeView` | ### Disclaimer diff --git a/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt b/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt index 7c1424cf..bd6ebe3a 100644 --- a/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt +++ b/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt @@ -12,6 +12,8 @@ package com.adobe.marketing.mobile.concierge.ui.components.messages +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Text import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.testTag @@ -25,6 +27,7 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performSemanticsAction +import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.test.click import androidx.compose.ui.text.TextLayoutResult @@ -36,6 +39,7 @@ import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeTheme import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeThemeData import com.adobe.marketing.mobile.concierge.ui.theme.DisclaimerLink import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticeConfig +import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticePresentation import com.adobe.marketing.mobile.concierge.ui.theme.ThemeParser import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue @@ -47,6 +51,95 @@ class PrivacyNoticeViewTest { @get:Rule val composeTestRule = createComposeRule() + @Test + fun notice_summaryExpandsAndCollapsesWithoutMovingFollowingContentAboveIt() { + composeTestRule.setContent { + ConciergeTheme { + Column { + PrivacyNoticeView( + config = PrivacyNoticeConfig( + text = "Full notice.\nAdditional details.\nRead {Privacy}.", + summary = "Short summary.", + presentation = PrivacyNoticePresentation.COLLAPSIBLE, + links = listOf(DisclaimerLink("Privacy", "https://example.com/privacy")) + ), + handleLink = noOpLink + ) + Text("Following message") + } + } + } + + composeTestRule.onNodeWithText("Short summary.").assertIsDisplayed() + val collapsedTop = composeTestRule.onNodeWithText("Following message").getUnclippedBoundsInRoot().top + composeTestRule.onNodeWithText("Read more").performClick() + composeTestRule.onNodeWithText("Short summary.").assertDoesNotExist() + composeTestRule.onNodeWithText("Full notice.\nAdditional details.\nRead Privacy.").assertIsDisplayed() + .assert(SemanticsMatcher.keyIsDefined(SemanticsActions.CustomActions)) + assertTrue(composeTestRule.onNodeWithText("Following message").getUnclippedBoundsInRoot().top > collapsedTop) + composeTestRule.onNodeWithText("Show less").performClick() + composeTestRule.onNodeWithText("Short summary.").assertIsDisplayed() + assertEquals( + collapsedTop.value, + composeTestRule.onNodeWithText("Following message").getUnclippedBoundsInRoot().top.value, + 1f + ) + } + + @Test + fun notice_withoutSummaryOnlyOffersExpansionWhenPreviewOverflows() { + val longText = "First line.\nSecond line.\nThird line.\nFourth line." + composeTestRule.setContent { + ConciergeTheme { + Column { + PrivacyNoticeView( + config = PrivacyNoticeConfig( + title = "Short", + text = "Fits.", + presentation = PrivacyNoticePresentation.COLLAPSIBLE + ), + handleLink = noOpLink + ) + PrivacyNoticeView( + config = PrivacyNoticeConfig( + title = "Long", + text = longText, + collapsedMaxLines = 2, + presentation = PrivacyNoticePresentation.COLLAPSIBLE + ), + handleLink = noOpLink + ) + } + } + } + val layouts = mutableListOf() + composeTestRule.onNodeWithText(longText) + .performSemanticsAction(SemanticsActions.GetTextLayoutResult) { it(layouts) } + assertEquals(2, layouts.single().lineCount) + composeTestRule.onNodeWithText("Read more").performClick() + layouts.clear() + composeTestRule.onNodeWithText(longText) + .performSemanticsAction(SemanticsActions.GetTextLayoutResult) { it(layouts) } + assertEquals(4, layouts.single().lineCount) + composeTestRule.onNodeWithText("Show less").performClick() + composeTestRule.onNodeWithText("Read more").assertIsDisplayed() + } + + @Test + fun notice_inlineRemainsFullyVisibleEvenWithSummary() { + composeTestRule.setContent { + ConciergeTheme { + PrivacyNoticeView( + config = PrivacyNoticeConfig(text = "Full notice.", summary = "Summary."), + handleLink = noOpLink + ) + } + } + composeTestRule.onNodeWithText("Full notice.").assertIsDisplayed() + composeTestRule.onNodeWithText("Summary.").assertDoesNotExist() + composeTestRule.onNodeWithText("Read more").assertDoesNotExist() + } + @Test fun notice_displaysHeadingAndBodyWithOuterTopSpacing() { var expectedInset = 0.dp diff --git a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt index 9810fa76..b067f3c7 100644 --- a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt +++ b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt @@ -16,15 +16,26 @@ import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.selection.SelectionContainer +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ExpandLess +import androidx.compose.material.icons.filled.ExpandMore +import androidx.compose.material3.Icon import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState +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.draw.clip import androidx.compose.ui.res.stringResource @@ -32,9 +43,11 @@ import androidx.compose.ui.semantics.CustomAccessibilityAction import androidx.compose.ui.semantics.customActions import androidx.compose.ui.semantics.heading import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.semantics.stateDescription import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.adobe.marketing.mobile.concierge.ConciergeConstants import com.adobe.marketing.mobile.concierge.R @@ -42,6 +55,7 @@ import com.adobe.marketing.mobile.concierge.ui.components.links.LinkedTextFormat import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeStyles import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeTheme import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticeConfig +import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticePresentation /** * Informational privacy notice shown before the first user query. @@ -82,6 +96,23 @@ internal fun PrivacyNoticeView( linkColor = linkColor ) } + val collapsible = config.presentation == PrivacyNoticePresentation.COLLAPSIBLE + val hasSummary = config.summary.isNotBlank() && config.summary.trim() != config.text.trim() + var expanded by rememberSaveable(config.text, config.summary, config.presentation) { mutableStateOf(false) } + var truncated by remember(config.text, config.collapsedMaxLines) { mutableStateOf(false) } + val summaryText = remember(config, linkColor) { + LinkedTextFormatter.format( + text = config.summary, + links = config.links, + baseStyle = SpanStyle(), + linkColor = linkColor + ).text + } + val readMore = config.readMoreLabel ?: stringResource(R.string.concierge_privacy_notice_read_more) + val showLess = config.showLessLabel ?: stringResource(R.string.concierge_privacy_notice_show_less) + val expandedState = stringResource( + if (expanded) R.string.concierge_privacy_notice_expanded else R.string.concierge_privacy_notice_collapsed + ) val linkActions = remember(annotatedText, openLinkFormat) { annotatedText.getStringAnnotations("URL", 0, annotatedText.length) .map { range -> @@ -115,15 +146,44 @@ internal fun PrivacyNoticeView( modifier = Modifier.semantics { heading() } ) } - ClickableText( - text = annotatedText, - textStyle = bodyStyle, - textAlign = TextAlign.Start, - handleLink = openLink, - modifier = Modifier.semantics { - if (linkActions.isNotEmpty()) customActions = linkActions - } - ) + if (collapsible && !expanded) { + Text( + text = if (hasSummary) summaryText else annotatedText.text, + style = bodyStyle, + color = bodyColor, + maxLines = if (hasSummary) Int.MAX_VALUE else config.collapsedMaxLines, + overflow = TextOverflow.Ellipsis, + onTextLayout = { if (!hasSummary) truncated = it.hasVisualOverflow } + ) + } else { + ClickableText( + text = annotatedText, + textStyle = bodyStyle, + textAlign = TextAlign.Start, + handleLink = openLink, + modifier = Modifier.semantics { + if (linkActions.isNotEmpty()) customActions = linkActions + } + ) + } + } + } + if (collapsible && (hasSummary || truncated)) { + TextButton( + onClick = { expanded = !expanded }, + modifier = Modifier.heightIn(min = 48.dp).semantics { stateDescription = expandedState } + ) { + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Text(text = if (expanded) showLess else readMore, style = bodyStyle, color = linkColor) + Icon( + imageVector = if (expanded) Icons.Default.ExpandLess else Icons.Default.ExpandMore, + contentDescription = null, + tint = linkColor + ) + } } } } diff --git a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ConciergeThemeModels.kt b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ConciergeThemeModels.kt index 30c844d0..d0f28a93 100644 --- a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ConciergeThemeModels.kt +++ b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ConciergeThemeModels.kt @@ -147,12 +147,26 @@ data class DisclaimerConfig( data class PrivacyNoticeConfig( val title: String? = null, val text: String = "", - val links: List = emptyList() + val links: List = emptyList(), + val presentation: PrivacyNoticePresentation = PrivacyNoticePresentation.INLINE, + val summary: String = "", + val collapsedMaxLines: Int = 3, + val readMoreLabel: String? = null, + val showLessLabel: String? = null ) { + init { + require(collapsedMaxLines > 0) { "collapsedMaxLines must be positive" } + } + val hasContent: Boolean get() = text.isNotBlank() } +enum class PrivacyNoticePresentation { + INLINE, + COLLAPSIBLE +} + data class DisclaimerLink( val text: String, val url: String diff --git a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ThemeParser.kt b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ThemeParser.kt index 4528ee4c..7f4a7acc 100644 --- a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ThemeParser.kt +++ b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/ThemeParser.kt @@ -582,7 +582,31 @@ internal object ThemeParser { } else -> throw IllegalArgumentException("behavior.privacyNotice.links must be an array or null") } - return PrivacyNoticeConfig(title = title, text = text, links = links) + val presentation = when (privacyNoticeString(noticeMap, "presentation")) { + null, "inline" -> PrivacyNoticePresentation.INLINE + "collapsible" -> PrivacyNoticePresentation.COLLAPSIBLE + else -> throw IllegalArgumentException("behavior.privacyNotice.presentation must be inline or collapsible") + } + val collapsedMaxLines = when (val lines = noticeMap["collapsedMaxLines"]) { + null -> 3 + is Number -> { + require(lines.toDouble() == lines.toInt().toDouble() && lines.toInt() > 0) { + "behavior.privacyNotice.collapsedMaxLines must be a positive integer" + } + lines.toInt() + } + else -> throw IllegalArgumentException("behavior.privacyNotice.collapsedMaxLines must be a positive integer") + } + return PrivacyNoticeConfig( + title = title, + text = text, + links = links, + presentation = presentation, + summary = privacyNoticeString(noticeMap, "summary") ?: "", + collapsedMaxLines = collapsedMaxLines, + readMoreLabel = privacyNoticeString(noticeMap, "readMoreLabel"), + showLessLabel = privacyNoticeString(noticeMap, "showLessLabel") + ) } private fun privacyNoticeString(map: Map<*, *>, key: String): String? = diff --git a/code/concierge/src/main/res/values/strings.xml b/code/concierge/src/main/res/values/strings.xml index 86130db0..05b59c9d 100644 --- a/code/concierge/src/main/res/values/strings.xml +++ b/code/concierge/src/main/res/values/strings.xml @@ -15,4 +15,8 @@ Privacy Notice Open %1$s + Read more + Show less + Expanded + Collapsed diff --git a/code/concierge/src/test/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/PrivacyNoticeConfigTest.kt b/code/concierge/src/test/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/PrivacyNoticeConfigTest.kt index 7ffb50c8..a7145bc0 100644 --- a/code/concierge/src/test/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/PrivacyNoticeConfigTest.kt +++ b/code/concierge/src/test/kotlin/com/adobe/marketing/mobile/concierge/ui/theme/PrivacyNoticeConfigTest.kt @@ -126,6 +126,30 @@ class PrivacyNoticeConfigTest { assertEquals(expected, decoded) } + @Test + fun `collapsible settings decode and null settings retain inline defaults`() { + val configured = ThemeParser.parseThemeTokens( + """{"behavior":{"privacyNotice":{"text":"Full notice","presentation":"collapsible", + "summary":"Short summary","collapsedMaxLines":2,"readMoreLabel":"Details","showLessLabel":"Less"}}}""" + )!!.behavior.privacyNotice + assertEquals( + PrivacyNoticeConfig( + text = "Full notice", + presentation = PrivacyNoticePresentation.COLLAPSIBLE, + summary = "Short summary", + collapsedMaxLines = 2, + readMoreLabel = "Details", + showLessLabel = "Less" + ), + configured + ) + val defaults = ThemeParser.parseThemeTokens( + """{"behavior":{"privacyNotice":{"presentation":null,"summary":null,"collapsedMaxLines":null, + "readMoreLabel":null,"showLessLabel":null}}}""" + )!!.behavior.privacyNotice + assertEquals(PrivacyNoticeConfig(), defaults) + } + @Test fun `malformed privacy field types fail theme decoding`() { listOf( @@ -136,7 +160,15 @@ class PrivacyNoticeConfigTest { """{"privacyNotice":{"links":[null]}}""", """{"privacyNotice":{"links":["invalid"]}}""", """{"privacyNotice":{"links":[{"text":42,"url":"https://example.com"}]}}""", - """{"privacyNotice":{"links":[{"text":"Privacy","url":42}]}}""" + """{"privacyNotice":{"links":[{"text":"Privacy","url":42}]}}""", + """{"privacyNotice":{"presentation":"sheet"}}""", + """{"privacyNotice":{"summary":false}}""", + """{"privacyNotice":{"collapsedMaxLines":0}}""", + """{"privacyNotice":{"collapsedMaxLines":-1}}""", + """{"privacyNotice":{"collapsedMaxLines":1.5}}""", + """{"privacyNotice":{"collapsedMaxLines":"3"}}""", + """{"privacyNotice":{"readMoreLabel":42}}""", + """{"privacyNotice":{"showLessLabel":false}}""" ).forEach { privacyNotice -> assertNull( ThemeParser.parseThemeTokens( diff --git a/code/testapp/src/main/assets/themeDemo.json b/code/testapp/src/main/assets/themeDemo.json index dda2e0fb..01e1351b 100644 --- a/code/testapp/src/main/assets/themeDemo.json +++ b/code/testapp/src/main/assets/themeDemo.json @@ -32,7 +32,13 @@ }, "privacyNotice": { "title": "Privacy Notice", - "text": "Privacy notice text." + "presentation": "collapsible", + "summary": "Demo notice: messages are processed to answer your questions. Please do not share sensitive information.", + "collapsedMaxLines": 3, + "text": "Demo only - replace this sample with approved privacy copy before release.\n\nInformation you share in this conversation is processed to understand your request and generate a response. Avoid sharing passwords, payment details, health information, or other sensitive personal information.\n\nAI-generated answers may be incomplete or inaccurate. Verify important information before making a decision. Read our {Privacy Policy} for details about data handling and your choices.\n\nYou can expand or collapse this notice at any time during this conversation.", + "links": [ + {"text": "Privacy Policy", "url": "https://www.example.com/privacy"} + ] }, "feedback": { "displayMode": "action", From f803a33825f9d39fe2f18c1cf5cc74a460080237 Mon Sep 17 00:00:00 2001 From: Jose Jimenez Date: Thu, 19 Nov 2026 09:30:52 -0500 Subject: [PATCH 2/2] fix: preserve privacy notice collapse control after state restoration Keep Show less visible whenever the notice is expanded, even when the overflow flag resets after state restoration or lazy-list disposal. Add regression tests for both scenarios, verifying that the notice stays expanded and can still be collapsed. --- .../messages/PrivacyNoticeViewTest.kt | 78 +++++++++++++++++++ .../components/messages/PrivacyNoticeView.kt | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt b/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt index bd6ebe3a..0d687421 100644 --- a/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt +++ b/code/concierge/src/androidTest/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeViewTest.kt @@ -13,7 +13,11 @@ package com.adobe.marketing.mobile.concierge.ui.components.messages import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.Text +import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.testTag @@ -28,7 +32,9 @@ import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performSemanticsAction import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performScrollToIndex import androidx.compose.ui.test.performTouchInput +import androidx.compose.ui.test.junit4.StateRestorationTester import androidx.compose.ui.test.click import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.text.SpanStyle @@ -42,6 +48,7 @@ import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticeConfig import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticePresentation import com.adobe.marketing.mobile.concierge.ui.theme.ThemeParser import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test @@ -51,6 +58,77 @@ class PrivacyNoticeViewTest { @get:Rule val composeTestRule = createComposeRule() + private val restorationNotice = PrivacyNoticeConfig( + text = "First privacy line.\nSecond privacy line.\nThird privacy line.\nFourth privacy line.\nFinal privacy line.", + presentation = PrivacyNoticePresentation.COLLAPSIBLE, + collapsedMaxLines = 3 + ) + + @Test + fun notice_withoutSummaryKeepsCollapseControlAfterSavedStateRestoration() { + val restoration = StateRestorationTester(composeTestRule) + restoration.setContent { + ConciergeTheme { + PrivacyNoticeView(config = restorationNotice, handleLink = noOpLink) + } + } + + assertRestorationNoticeLineCount(3) + composeTestRule.onNodeWithText("Read more").performClick() + assertRestorationNoticeLineCount(5) + composeTestRule.onNodeWithText("Show less").assertIsDisplayed() + + restoration.emulateSavedInstanceStateRestore() + + assertRestorationNoticeLineCount(5) + composeTestRule.onNodeWithText("Show less").assertIsDisplayed().performClick() + assertRestorationNoticeLineCount(3) + composeTestRule.onNodeWithText("Read more").assertIsDisplayed() + } + + @Test + fun notice_withoutSummaryKeepsCollapseControlAfterLazyItemDisposal() { + var noticeInComposition = false + composeTestRule.setContent { + ConciergeTheme { + LazyColumn(Modifier.fillMaxSize().testTag("transcript")) { + item(key = "privacy-notice") { + DisposableEffect(Unit) { + noticeInComposition = true + onDispose { noticeInComposition = false } + } + PrivacyNoticeView(config = restorationNotice, handleLink = noOpLink) + } + items(100) { index -> + Text("Message $index", modifier = Modifier.height(72.dp)) + } + } + } + } + + assertRestorationNoticeLineCount(3) + composeTestRule.onNodeWithText("Read more").performClick() + assertRestorationNoticeLineCount(5) + composeTestRule.onNodeWithText("Show less").assertIsDisplayed() + + composeTestRule.onNodeWithTag("transcript").performScrollToIndex(80) + composeTestRule.runOnIdle { assertFalse("Notice must actually leave composition", noticeInComposition) } + composeTestRule.onNodeWithTag("transcript").performScrollToIndex(0) + composeTestRule.runOnIdle { assertTrue(noticeInComposition) } + + assertRestorationNoticeLineCount(5) + composeTestRule.onNodeWithText("Show less").assertIsDisplayed().performClick() + assertRestorationNoticeLineCount(3) + composeTestRule.onNodeWithText("Read more").assertIsDisplayed() + } + + private fun assertRestorationNoticeLineCount(expected: Int) { + val layouts = mutableListOf() + composeTestRule.onNodeWithText(restorationNotice.text) + .performSemanticsAction(SemanticsActions.GetTextLayoutResult) { it(layouts) } + assertEquals(expected, layouts.single().lineCount) + } + @Test fun notice_summaryExpandsAndCollapsesWithoutMovingFollowingContentAboveIt() { composeTestRule.setContent { diff --git a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt index b067f3c7..782ec436 100644 --- a/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt +++ b/code/concierge/src/main/kotlin/com/adobe/marketing/mobile/concierge/ui/components/messages/PrivacyNoticeView.kt @@ -168,7 +168,7 @@ internal fun PrivacyNoticeView( } } } - if (collapsible && (hasSummary || truncated)) { + if (collapsible && (expanded || hasSummary || truncated)) { TextButton( onClick = { expanded = !expanded }, modifier = Modifier.heightIn(min = 48.dp).semantics { stateDescription = expandedState }