-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change rememberRetain not to retain the value of removed node #1794
Merged
ZacSweers
merged 40 commits into
slackhq:main
from
vulpeszerda:remember-retained-redesigned
Feb 6, 2025
Merged
Changes from 9 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
019c8cc
Added navigableCircuitContentRetainTest
vulpeszerda 5b279d4
Added condition retain test
vulpeszerda 4b0cc82
Changed rememberRetained to be cleared when node removed
vulpeszerda d769169
Changed AndroidContinuity to save values on stopped
vulpeszerda 465f98f
Fixed recreation test scenario
vulpeszerda 24d8547
Replaced registry usage with RetainedStateProvider
vulpeszerda affec25
Fixed retainedTest to use RetainedStateProvider
vulpeszerda c42dd26
Merge branch 'main' into remember-retained-redesigned
vulpeszerda 67d156f
Generate apiDumps
vulpeszerda ff654b4
Replaced RetainedStateProvider with RetainedStateHolder
vulpeszerda 5d30dd7
Removed duplicated codes
vulpeszerda a367cbb
Changed to use record.registryKey
vulpeszerda 0e4e8e3
Moved RetainedStateProvider to inner of movableContentOf
vulpeszerda 9fbc2df
Restored un-intended changes
vulpeszerda fb672cf
Added removeState in RetainedStateHolder
vulpeszerda b6b0cec
Merge branch 'main' into remember-retained-redesigned
vulpeszerda 16cf579
Changed RetainedStateHolder to use ReusableContent
vulpeszerda ff477ad
Changed RetainedStateHolderWithReturn to use key (instead of Reusable…
vulpeszerda 7900ffb
Changed test method names for more readability
vulpeszerda df33d07
Added saveAll return value
vulpeszerda 82e84a1
Changed RetainedStateRegistry not to save empty registry
vulpeszerda 1e8083e
Add RetainedStateHolderTests (cherry-pick)
ZacSweers afebc7a
Added default RetainedStateRegistry
vulpeszerda 9714ce3
Added RetainedStateHolder to star sample
vulpeszerda 0c3c6b1
spotless
vulpeszerda ffcf6f6
apiDump
vulpeszerda 91c2fcd
Fixed lint
vulpeszerda b726772
Moved rememberRetainedStateHolder declaration in NavigableCircuitContent
vulpeszerda 28d601a
Removed redundant contentComposed = true
vulpeszerda b9d1afd
Changed NavigableCircuitContent comment
vulpeszerda ae1cd94
Merge branch 'main' into remember-retained-redesigned
vulpeszerda b267800
Handled CanRetainChecker stale case
vulpeszerda 0eb7efb
Added CanRetainChecker switch test cases
vulpeszerda 17b40a5
Added scoped CanRetainChecker tests
vulpeszerda 6b6467e
Changed rememberRetained not to save its value when CanRetainChecker …
vulpeszerda b6bdea4
apiDumps
vulpeszerda 2fe5950
Merge branch 'main' into remember-retained-redesigned
vulpeszerda a9407b1
Removed debug code
vulpeszerda 58ba1cd
Minor code re-arrange
vulpeszerda 32efffd
Added changelog
vulpeszerda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../src/commonMain/kotlin/com/slack/circuit/foundation/internal/WithRetainedStateProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (C) 2024 Slack Technologies, LLC | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package com.slack.circuit.foundation.internal | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.DisposableEffect | ||
import com.slack.circuit.retained.CanRetainChecker | ||
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.rememberRetained | ||
|
||
/** Copy of [RetainedStateProvider] to return content value */ | ||
@Composable | ||
internal fun <T> withRetainedStateProvider(key: String, content: @Composable () -> T): T { | ||
val canRetainChecker = LocalCanRetainChecker.current ?: CanRetainChecker.Always | ||
val parentRegistry = LocalRetainedStateRegistry.current | ||
val registry = rememberRetained(key = key) { RetainedStateRegistry() } | ||
return withCompositionLocalProvider( | ||
LocalRetainedStateRegistry provides registry, | ||
LocalCanRetainChecker provides CanRetainChecker.Always, | ||
) { | ||
content() | ||
} | ||
.also { | ||
DisposableEffect(key, registry) { | ||
onDispose { | ||
registry.saveAll() | ||
if (canRetainChecker.canRetain(registry)) { | ||
parentRegistry.saveValue(key) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this comment is now a bit out of date, it could probably point to how
RetainedStateProvider
worksThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um.. yes I changed a little bit.