Skip to content

Commit a90feee

Browse files
committed
Address SentryBot, etc. comments
1 parent f778083 commit a90feee

2 files changed

Lines changed: 38 additions & 21 deletions

File tree

‎sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav2/Nav2Activity.kt‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ class Nav2Activity : AppCompatActivity() {
212212
onCaptureException = { captureSampleException("Nav2") },
213213
onCrashApp = { showCrashConfirmation("Nav2") },
214214
selectedScenario = composeScenario.value,
215-
onRouteChanged = { _, currentRoute, backStack ->
216-
updateComposeNavigationUi(currentRoute, backStack)
215+
onRouteChanged = { scenario, _, currentRoute, backStack ->
216+
updateComposeNavigationUi(scenario, currentRoute, backStack)
217217
},
218218
onExitRoot = { finish() },
219219
)
@@ -347,11 +347,19 @@ class Nav2Activity : AppCompatActivity() {
347347
}
348348
Nav2Scenario.COMPOSE -> {
349349
contentHosts.showCompose()
350-
updateComposeNavigationUi("/${RouteNames.HOME}", "/${RouteNames.HOME}")
350+
updateComposeNavigationUi(
351+
scenario = Nav2Scenario.COMPOSE,
352+
currentRoute = "/${RouteNames.HOME}",
353+
backStack = "/${RouteNames.HOME}",
354+
)
351355
}
352356
Nav2Scenario.CUSTOM -> {
353357
contentHosts.showCompose()
354-
updateComposeNavigationUi("/${RouteNames.CUSTOM}", "/${RouteNames.CUSTOM}")
358+
updateComposeNavigationUi(
359+
scenario = Nav2Scenario.CUSTOM,
360+
currentRoute = "/${RouteNames.CUSTOM}",
361+
backStack = "/${RouteNames.CUSTOM}",
362+
)
355363
}
356364
Nav2Scenario.FRAGMENTS -> {
357365
contentHosts.showFragments()
@@ -488,11 +496,13 @@ class Nav2Activity : AppCompatActivity() {
488496
}
489497
}
490498

491-
private fun updateComposeNavigationUi(currentRoute: String, backStack: String) {
499+
private fun updateComposeNavigationUi(
500+
scenario: Nav2Scenario,
501+
currentRoute: String,
502+
backStack: String,
503+
) {
492504
topBar.update(
493-
scenario =
494-
if (currentRoute.startsWith("/${RouteNames.CUSTOM}")) Nav2Scenario.CUSTOM
495-
else Nav2Scenario.COMPOSE,
505+
scenario = scenario,
496506
currentRoute = currentRoute,
497507
backStack = backStack,
498508
)

‎sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav2/Nav2ComposeRoutes.kt‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import androidx.compose.runtime.LaunchedEffect
3838
import androidx.compose.runtime.getValue
3939
import androidx.compose.runtime.mutableStateListOf
4040
import androidx.compose.runtime.mutableStateOf
41+
import androidx.compose.runtime.remember
4142
import androidx.compose.runtime.rememberUpdatedState
4243
import androidx.compose.runtime.saveable.listSaver
4344
import androidx.compose.runtime.saveable.rememberSaveable
@@ -94,7 +95,8 @@ internal fun Nav2ComposeApp(
9495
onCaptureException: () -> Unit,
9596
onCrashApp: () -> Unit,
9697
selectedScenario: Nav2Scenario,
97-
onRouteChanged: (routeName: String, currentRoute: String, backStack: String) -> Unit,
98+
onRouteChanged:
99+
(scenario: Nav2Scenario, routeName: String, currentRoute: String, backStack: String) -> Unit,
98100
onExitRoot: () -> Unit,
99101
) {
100102

@@ -105,7 +107,7 @@ internal fun Nav2ComposeApp(
105107
var customTransactionMode by rememberSaveable {
106108
mutableStateOf(Nav2CustomTransactionMode.PER_SCREEN)
107109
}
108-
var asyncBrowseProductsJob by rememberSaveable { mutableStateOf<Job?>(null) }
110+
var asyncBrowseProductsJob by remember { mutableStateOf<Job?>(null) }
109111
var isAsyncBrowseProductsRunning by rememberSaveable { mutableStateOf(false) }
110112
val customTransactionsScope = androidx.compose.runtime.rememberCoroutineScope()
111113
val customTransactionController =
@@ -147,15 +149,15 @@ internal fun Nav2ComposeApp(
147149
backStack.resetTo(Home)
148150
shareSheetProductId.value = null
149151
navController.navigate(Home.route) {
150-
popUpTo(Home.route) { inclusive = true }
152+
popUpTo(Home.route) { inclusive = false }
151153
launchSingleTop = true
152154
}
153155
}
154156
Nav2Scenario.CUSTOM -> {
155157
backStack.resetTo(Custom)
156158
shareSheetProductId.value = null
157159
navController.navigate(Custom.route) {
158-
popUpTo(Home.route) { inclusive = true }
160+
popUpTo(Home.route) { inclusive = false }
159161
launchSingleTop = true
160162
}
161163
}
@@ -176,6 +178,7 @@ internal fun Nav2ComposeApp(
176178

177179
LaunchedEffect(currentDestination, backStack.size) {
178180
onRouteChanged(
181+
selectedScenario,
179182
currentDestination.routeName,
180183
currentDestination.displayRoute(),
181184
backStack.toComposeBackStackText(),
@@ -205,13 +208,13 @@ internal fun Nav2ComposeApp(
205208
popExitTransition = { fadeOut(animationSpec = tween(COMPOSE_ROUTE_TRANSITION_MILLIS)) },
206209
) {
207210
composable(Home.route) {
208-
TracedNav2ComposeRoute(Home.routeName) {
211+
TracedNav2ComposeRoute(selectedScenario, Home.routeName) {
209212
Nav2ComposeHomeRoute(routeSpec = RouteSpecs.home) { navigateTo(ProductList) }
210213
}
211214
}
212215

213216
composable(Custom.route) {
214-
TracedNav2ComposeRoute(Custom.routeName) {
217+
TracedNav2ComposeRoute(selectedScenario, Custom.routeName) {
215218
Nav2ComposeCustomRoute(
216219
routeSpec = RouteSpecs.custom,
217220
mode = customTransactionMode,
@@ -248,7 +251,7 @@ internal fun Nav2ComposeApp(
248251
}
249252

250253
composable(ProductList.route) {
251-
TracedNav2ComposeRoute(ProductList.routeName) {
254+
TracedNav2ComposeRoute(selectedScenario, ProductList.routeName) {
252255
Nav2ComposeProductListRoute(
253256
routeSpec = RouteSpecs.productList,
254257
onOpenProduct42 = {
@@ -282,7 +285,7 @@ internal fun Nav2ComposeApp(
282285
val productId = entry.arguments?.getString(NavArgs.PRODUCT_ID).orEmpty()
283286
val source = entry.arguments?.getString(NavArgs.SOURCE).orEmpty()
284287
val campaign = entry.arguments?.getString(NavArgs.CAMPAIGN).orEmpty()
285-
TracedNav2ComposeRoute(RouteNames.PRODUCT_DETAIL) {
288+
TracedNav2ComposeRoute(selectedScenario, RouteNames.PRODUCT_DETAIL) {
286289
Nav2ComposeProductDetailRoute(
287290
routeSpec = RouteSpecs.productDetail,
288291
productId = productId,
@@ -302,7 +305,7 @@ internal fun Nav2ComposeApp(
302305
arguments = listOf(navArgument(NavArgs.PRODUCT_ID) { type = NavType.StringType }),
303306
) { entry ->
304307
val productId = entry.arguments?.getString(NavArgs.PRODUCT_ID).orEmpty()
305-
TracedNav2ComposeRoute(RouteNames.CHECKOUT) {
308+
TracedNav2ComposeRoute(selectedScenario, RouteNames.CHECKOUT) {
306309
Nav2ComposeCheckoutRoute(
307310
routeSpec = RouteSpecs.checkout,
308311
productId = productId,
@@ -317,7 +320,7 @@ internal fun Nav2ComposeApp(
317320
route = Nav2ComposeDestination.CONFIRMATION_ROUTE,
318321
arguments = listOf(navArgument(NavArgs.ORDER_ID) { type = NavType.StringType }),
319322
) { entry ->
320-
TracedNav2ComposeRoute(RouteNames.CONFIRMATION) {
323+
TracedNav2ComposeRoute(selectedScenario, RouteNames.CONFIRMATION) {
321324
Nav2ComposeConfirmationRoute(
322325
routeSpec = RouteSpecs.confirmation,
323326
orderId = entry.arguments?.getString(NavArgs.ORDER_ID).orEmpty(),
@@ -333,7 +336,7 @@ internal fun Nav2ComposeApp(
333336
// This dialog is a real Nav destination, so it participates in Nav2 the same way as the
334337
// rest of the route graph. Compare it with the share sheet overlay below when inspecting
335338
// Sentry's Nav2 breadcrumbs, destination arguments, and route transactions.
336-
TracedNav2ComposeRoute(RouteNames.PROMO_DIALOG) {
339+
TracedNav2ComposeRoute(selectedScenario, RouteNames.PROMO_DIALOG) {
337340
Nav2ComposePromoDialogRoute(
338341
routeSpec = RouteSpecs.promoDialog,
339342
promoId = entry.arguments?.getString(NavArgs.PROMO_ID).orEmpty(),
@@ -378,8 +381,12 @@ internal fun Nav2ComposeApp(
378381

379382
@OptIn(ExperimentalComposeUiApi::class)
380383
@Composable
381-
private fun TracedNav2ComposeRoute(routeName: String, content: @Composable BoxScope.() -> Unit) {
382-
tagCurrentNav2Scenario(Nav2Scenario.COMPOSE)
384+
private fun TracedNav2ComposeRoute(
385+
scenario: Nav2Scenario,
386+
routeName: String,
387+
content: @Composable BoxScope.() -> Unit,
388+
) {
389+
tagCurrentNav2Scenario(scenario)
383390
SentryTraced(
384391
tag = "Nav2 /$routeName",
385392
// Keep interaction tagging off here so route wrappers do not turn every Compose click into a

0 commit comments

Comments
 (0)