Repository navigation
ref(nav3): [Part 2] Extract shared back stack policies #6698
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
Merged
+117
−105
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
...3/src/main/kotlin/io/sentry/compose/navigation3/internal/backstack/ArgumentConstraints.kt
This file contains hidden or 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,45 @@ | ||
| package io.sentry.compose.navigation3.internal.backstack | ||
|
|
||
| internal object ArgumentConstraints { | ||
|
|
||
| /** | ||
| * Max combined length of map keys and text values visited in one back stack update. | ||
| * | ||
| * If exceeded, the entry that overflows loses its arguments, as do older entries; newer entries | ||
| * are preserved. | ||
| * | ||
| * Caps payload size in the presence of large individual arguments. | ||
| */ | ||
| const val MAX_ARGUMENT_CHARACTERS = 4_096 | ||
|
|
||
| /** | ||
| * Max depth of an argument value within one back stack entry. Root arguments have depth 1; each | ||
| * nested map or list adds one level. | ||
| * | ||
| * For instance, `mapOf("id" to 123)` reaches a depth of 1; `mapOf("items" to listOf("apple", | ||
| * "banana"))` reaches a depth of 2. | ||
| * | ||
| * If exceeded, all arguments for that back stack entry are dropped. | ||
| */ | ||
| const val MAX_ARGUMENT_DEPTH = 10 | ||
|
|
||
| /** | ||
| * Max number of argument values visited in one back stack update. Each scalar or nested container | ||
| * counts as one value; map keys and each entry's root argument map are excluded. | ||
| * | ||
| * For instance, `mapOf("id" to 123)` consumes 1 value; `mapOf("profile" to mapOf("id" to 123, | ||
| * "name" to "Ada"))` consumes 3 values. | ||
| * | ||
| * If exceeded, the entry that overflows loses its arguments, as do older entries; newer entries | ||
| * are preserved. | ||
| * | ||
| * For instance, suppose we have the following back stack: | ||
| * | ||
| * - /Checkout -> Top of the stack and processed first | ||
| * - /ProductDetail -> Processed second and exceeds the `MAX_ARGUMENT_VALUES` budget | ||
| * - /Home | ||
| * | ||
| * Then /ProductDetail and /Home will have no arguments, but /Checkout will. | ||
| */ | ||
| const val MAX_ARGUMENT_VALUES = 200 | ||
| } |
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
35
...igation3/src/main/kotlin/io/sentry/compose/navigation3/internal/backstack/BackStackKey.kt
This file contains hidden or 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,35 @@ | ||
| package io.sentry.compose.navigation3.internal.backstack | ||
|
|
||
| /** | ||
| * A key for distinguishing back stacks over time. | ||
| * | ||
| * Lets `*Effect`s restart when either the identity of a stack entry changes or the stack's entries | ||
| * are reordered. | ||
| */ | ||
| internal class BackStackKey<T : Any>(private val backStack: List<T>) { | ||
|
|
||
| override fun equals(other: Any?): Boolean { | ||
| // Use of identity rather than structural equality frees us from entries' equals() and | ||
| // hashCode() implementations, which are provided by the host app and may be incomplete, | ||
| // expensive, or incorrect for our purposes. | ||
| if (this === other) { | ||
| return true | ||
| } | ||
| if (other !is BackStackKey<*>) { | ||
| return false | ||
| } | ||
| if (backStack.size != other.backStack.size) { | ||
| return false | ||
| } | ||
|
|
||
| return backStack.indices.all { index -> backStack[index] === other.backStack[index] } | ||
| } | ||
|
|
||
| override fun hashCode(): Int { | ||
| var result = backStack.size | ||
| for (entry in backStack) { | ||
| result = 31 * result + System.identityHashCode(entry) | ||
| } | ||
| return result | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
26 changes: 26 additions & 0 deletions
26
...kotlin/io/sentry/compose/navigation3/internal/backstack/ForwardingBackStackEntryMapper.kt
This file contains hidden or 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,26 @@ | ||
| package io.sentry.compose.navigation3.internal.backstack | ||
|
|
||
| import androidx.compose.runtime.snapshots.Snapshot | ||
| import io.sentry.compose.navigation3.BackStackEntryMapper | ||
| import io.sentry.compose.navigation3.SentryBackStackEntry | ||
|
|
||
| /** | ||
| * A Compose-compatible version of [BackStackEntryMapper] that generates [SentryBackStackEntry]s by | ||
| * forwarding the request to the host app mapper in effect at the time [map] is called. | ||
| * | ||
| * Dynamically determining the current mapper lets us separate two concerns: | ||
| * | ||
| * 1. the lifetime of a consumer that tracks navigation state over time (e.g., [BackStackObserver]); | ||
| * and | ||
| * 2. the lifetime of the mapper used to generate `SentryBackStackEntry`s. | ||
| * | ||
| * Without that separation, a long-lived consumer would have to choose between holding stale mapping | ||
| * logic or recreating its own state whenever the mapper changed. | ||
| */ | ||
| internal class ForwardingBackStackEntryMapper<T : Any>( | ||
| private val currentMapper: () -> BackStackEntryMapper<T>, | ||
| ) { | ||
| fun map(backStackEntry: T): SentryBackStackEntry? = Snapshot.withoutReadObservation { | ||
| currentMapper().map(backStackEntry) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
...y/compose/navigation3/BackStackKeyTest.kt → ...n3/internal/backstack/BackStackKeyTest.kt
This file contains hidden or 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 hidden or 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 hidden or 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
4 changes: 3 additions & 1 deletion
4
...on3/ForwardingBackStackEntryMapperTest.kt → ...ack/ForwardingBackStackEntryMapperTest.kt
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.