-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auto-instrumentation for compose navigation (#392)
- Loading branch information
Showing
27 changed files
with
627 additions
and
103 deletions.
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
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
82 changes: 82 additions & 0 deletions
82
...trumentation-sample/src/main/java/io/sentry/samples/instrumentation/ui/ComposeActivity.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,82 @@ | ||
package io.sentry.samples.instrumentation.ui | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.text.BasicText | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
|
||
class ComposeActivity : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
val navController = rememberNavController() | ||
|
||
NavHost( | ||
navController = navController, | ||
startDestination = Destination.Home.route | ||
) { | ||
val pillShape = RoundedCornerShape(50) | ||
|
||
composable(Destination.Home.route) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
BasicText( | ||
modifier = Modifier | ||
.border(2.dp, Color.Gray, pillShape) | ||
.clip(pillShape) | ||
.clickable { | ||
navController.navigate(Destination.Details.route) | ||
} | ||
.padding(24.dp), | ||
text = "Home. Tap to go to Details." | ||
) | ||
} | ||
} | ||
composable(Destination.Details.route) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
BasicText( | ||
modifier = Modifier | ||
.border(2.dp, Color.Gray, pillShape) | ||
.clip(pillShape) | ||
.clickable { | ||
navController.popBackStack() | ||
} | ||
.padding(24.dp), | ||
text = "Details. Tap or press back to return." | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
sealed class Destination( | ||
val route: String | ||
) { | ||
object Home : Destination("home") | ||
object Details : Destination("details") | ||
} | ||
} |
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
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
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
43 changes: 43 additions & 0 deletions
43
...ld/src/main/kotlin/io/sentry/android/gradle/autoinstall/compose/ComposeInstallStrategy.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,43 @@ | ||
package io.sentry.android.gradle.autoinstall.compose | ||
|
||
import io.sentry.android.gradle.SentryPlugin | ||
import io.sentry.android.gradle.autoinstall.AbstractInstallStrategy | ||
import io.sentry.android.gradle.autoinstall.AutoInstallState | ||
import io.sentry.android.gradle.autoinstall.InstallStrategyRegistrar | ||
import io.sentry.android.gradle.util.SemVer | ||
import javax.inject.Inject | ||
import org.gradle.api.artifacts.dsl.ComponentMetadataHandler | ||
import org.slf4j.Logger | ||
|
||
abstract class ComposeInstallStrategy : AbstractInstallStrategy { | ||
|
||
constructor(logger: Logger) : super() { | ||
this.logger = logger | ||
} | ||
|
||
@Suppress("unused") // used by Gradle | ||
@Inject // inject is needed to avoid Gradle error | ||
constructor() : this(SentryPlugin.logger) | ||
|
||
override val sentryModuleId: String get() = SENTRY_COMPOSE_ID | ||
|
||
override val shouldInstallModule: Boolean get() = AutoInstallState.getInstance().installCompose | ||
|
||
override val minSupportedSentryVersion: SemVer | ||
get() = SemVer(6, 7, 0) | ||
|
||
override val minSupportedThirdPartyVersion: SemVer | ||
get() = SemVer(1, 0, 0) | ||
|
||
companion object Registrar : InstallStrategyRegistrar { | ||
|
||
internal const val SENTRY_COMPOSE_ID = "sentry-compose-android" | ||
|
||
override fun register(component: ComponentMetadataHandler) { | ||
component.withModule( | ||
"androidx.compose.runtime:runtime", | ||
ComposeInstallStrategy::class.java | ||
) {} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.