Skip to content

Commit 2019bef

Browse files
committed
fix(RevenueCatUI): keep Tabs' state publish behind visibility check (parity with iOS)
Reverts the effect of e830f1e: a hidden Tabs component should not publish its selected tab id into the state store, matching the merged iOS reference implementation.
1 parent 3adbae4 commit 2019bef

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

  • ui/revenuecatui/src

ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/tabs/TabsComponentView.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,19 @@ internal fun TabsComponentView(
8181
style = style,
8282
paywallState = state,
8383
)
84+
85+
if (!tabsState.visible) return
86+
8487
// State-driven paywalls: publish the selected tab id into the state store so components that react to it via a
85-
// `state_condition` override recompose. Done before the visibility check so a hidden Tabs still publishes its
86-
// selected state. Runs on first composition (seed) and whenever the selection changes.
88+
// `state_condition` override recompose. Gated behind visibility (parity with iOS): a hidden Tabs never
89+
// publishes. Runs on first composition (seed) and whenever the selection changes.
8790
val selectedTabId = style.tabs[state.selectedTabIndex.coerceIn(0..style.tabs.lastIndex)].id
8891
LaunchedEffect(selectedTabId) {
8992
style.stateUpdates?.takeIf { it.isNotEmpty() }?.let { updates ->
9093
state.stateStore.applyUpdates(updates, payload = JsonPrimitive(selectedTabId))
9194
}
9295
}
9396

94-
if (!tabsState.visible) return
95-
9697
val backgroundStyle = tabsState.background?.let { rememberBackgroundStyle(it) }
9798
val borderStyle = tabsState.border?.let { rememberBorderStyle(border = it) }
9899
val shadowStyle = tabsState.shadow?.let { rememberShadowStyle(shadow = it) }

ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/tabs/TabStateTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class TabStateTests {
183183
}
184184

185185
@Test
186-
fun `A hidden tabs component still publishes its selected tab id`(): Unit = with(composeTestRule) {
186+
fun `A hidden tabs component does not publish its selected tab id`(): Unit = with(composeTestRule) {
187187
val tab0LabelKey = LocalizationKey("tab0_label")
188188
val tab1LabelKey = LocalizationKey("tab1_label")
189189
val localizations = nonEmptyMapOf(
@@ -240,6 +240,6 @@ class TabStateTests {
240240
setContent { TabsComponentView(style = style, state = state, clickHandler = { }) }
241241
waitForIdle()
242242

243-
assertThat(state.stateStore.currentValueOrDefault(stateKey)).isEqualTo(JsonPrimitive("annual"))
243+
assertThat(state.stateStore.currentValueOrDefault(stateKey)).isEqualTo(JsonPrimitive("monthly"))
244244
}
245245
}

0 commit comments

Comments
 (0)