From 1ab82a3ea4b7afd9e2e2b17d443ae01d5b100368 Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Tue, 24 Oct 2023 08:48:00 +0200 Subject: [PATCH] Fix user interaction tracking not working for Jetpack Compose 1.5+ (#3010) --- CHANGELOG.md | 1 + buildSrc/src/main/java/Config.kt | 2 +- .../compose/gestures/ComposeGestureTargetLocator.java | 9 +++++++++ sentry-compose/proguard-rules.pro | 5 +++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f19bdcdfb2..a40abd13f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix crash when HTTP connection error message contains formatting symbols ([#3002](https://github.com/getsentry/sentry-java/pull/3002)) - Cap max number of stack frames to 100 to not exceed payload size limit ([#3009](https://github.com/getsentry/sentry-java/pull/3009)) - This will ensure we report errors with a big number of frames such as `StackOverflowError` +- Fix user interaction tracking not working for Jetpack Compose 1.5+ ([#3010](https://github.com/getsentry/sentry-java/pull/3010)) ## 6.32.0 diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index 56ea4915c6..cdbbe0c190 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -10,7 +10,7 @@ object Config { val springBoot3Version = "3.0.3" val kotlinCompatibleLanguageVersion = "1.4" - val composeVersion = "1.3.0" + val composeVersion = "1.5.3" val androidComposeCompilerVersion = "1.4.0" object BuildPlugins { diff --git a/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java b/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java index 15db1558cb..24f0bab95a 100644 --- a/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java +++ b/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java @@ -87,6 +87,15 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) { } } } + } else { + // Newer Jetpack Compose 1.5 uses Node modifiers for clicks/scrolls + final @Nullable String type = modifierInfo.getModifier().getClass().getCanonicalName(); + if ("androidx.compose.foundation.ClickableElement".equals(type) + || "androidx.compose.foundation.CombinedClickableElement".equals(type)) { + isClickable = true; + } else if ("androidx.compose.foundation.ScrollingLayoutElement".equals(type)) { + isScrollable = true; + } } } diff --git a/sentry-compose/proguard-rules.pro b/sentry-compose/proguard-rules.pro index 31025505f6..80580b28fd 100644 --- a/sentry-compose/proguard-rules.pro +++ b/sentry-compose/proguard-rules.pro @@ -9,12 +9,17 @@ private androidx.compose.ui.node.LayoutNodeLayoutDelegate layoutDelegate; } +-keepnames class androidx.compose.foundation.ClickableElement +-keepnames class androidx.compose.foundation.CombinedClickableElement +-keepnames class androidx.compose.foundation.ScrollingLayoutElement + # R8 will warn about missing classes if people don't have androidx.compose-navigation on their # classpath, but this is fine, these classes are used in an internal class which is only used when # someone is using withSentryObservableEffect extension function (which, in turn, cannot be used # without having androidx.compose-navigation on the classpath) -dontwarn androidx.navigation.NavController$OnDestinationChangedListener -dontwarn androidx.navigation.NavController +-dontwarn androidx.compose.foundation.* # To ensure that stack traces is unambiguous # https://developer.android.com/studio/build/shrink-code#decode-stack-trace