Skip to content

Commit

Permalink
Fixed retainedTest to use RetainedStateProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
vulpeszerda committed Nov 13, 2024
1 parent 24d8547 commit affec25
Showing 1 changed file with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.slack.circuit.retained.Continuity
import com.slack.circuit.retained.ContinuityViewModel
import com.slack.circuit.retained.LocalCanRetainChecker
import com.slack.circuit.retained.LocalRetainedStateRegistry
import com.slack.circuit.retained.RetainedStateProvider
import com.slack.circuit.retained.RetainedStateRegistry
import com.slack.circuit.retained.continuityRetainedStateRegistry
import com.slack.circuit.retained.rememberRetained
Expand Down Expand Up @@ -367,10 +368,8 @@ class RetainedTest {

val content =
@Composable {
val nestedRegistryLevel1 = rememberRetained { RetainedStateRegistry() }
CompositionLocalProvider(LocalRetainedStateRegistry provides nestedRegistryLevel1) {
val nestedRegistryLevel2 = rememberRetained { RetainedStateRegistry() }
CompositionLocalProvider(LocalRetainedStateRegistry provides nestedRegistryLevel2) {
RetainedStateProvider {
RetainedStateProvider {
@Suppress("UNUSED_VARIABLE") val retainedSubject = rememberRetained { subject }
}
}
Expand Down Expand Up @@ -654,10 +653,7 @@ private fun NestedRetainLevel1(useKeys: Boolean) {
label = {},
)

val nestedRegistry = rememberRetained { RetainedStateRegistry() }
CompositionLocalProvider(LocalRetainedStateRegistry provides nestedRegistry) {
NestedRetainLevel2(useKeys)
}
RetainedStateProvider("retained2-registry") { NestedRetainLevel2(useKeys) }
}

@Composable
Expand Down Expand Up @@ -705,13 +701,7 @@ private fun NestedRetainWithPushAndPop(useKeys: Boolean) {
// Keep the retained state registry around even if showNestedContent becomes false
CompositionLocalProvider(LocalCanRetainChecker provides CanRetainChecker.Always) {
if (showNestedContent.value) {
val nestedRegistry = rememberRetained { RetainedStateRegistry() }
CompositionLocalProvider(
LocalRetainedStateRegistry provides nestedRegistry,
LocalCanRetainChecker provides CanRetainChecker.Always,
) {
NestedRetainLevel1(useKeys)
}
RetainedStateProvider("retained1_registry") { NestedRetainLevel1(useKeys) }
}
}
}
Expand Down Expand Up @@ -747,15 +737,9 @@ private fun NestedRetainWithPushAndPopAndCannotRetain(useKeys: Boolean) {
}

// Keep the retained state registry around even if showNestedContent becomes false
CompositionLocalProvider(LocalCanRetainChecker provides CanRetainChecker.Always) {
CompositionLocalProvider(LocalCanRetainChecker provides { false }) {
if (showNestedContent.value) {
val nestedRegistry = rememberRetained { RetainedStateRegistry() }
CompositionLocalProvider(
LocalRetainedStateRegistry provides nestedRegistry,
LocalCanRetainChecker provides { false },
) {
NestedRetainLevel1(useKeys)
}
RetainedStateProvider("retained1_registry") { NestedRetainLevel1(useKeys) }
}
}
}
Expand Down

0 comments on commit affec25

Please sign in to comment.