-
-
Notifications
You must be signed in to change notification settings - Fork 467
Support apps compiled against Jetpack Compose 1.10 #5189
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
+891
−77
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
72a523b
Compile against JPC 1.10
markushi c863646
Format code
getsentry-bot 7400d9c
Fix click/scroll target detection
markushi e51aca5
Merge branch 'markushi/fix/compose-110-api-changes' of github.com:get…
markushi 0e2a446
Update Changelog
markushi d9d89d9
Move changes into replay module
markushi 339c0cd
Switch to reflection
markushi 018df71
Fix Changelog
markushi 66db017
Improve LayoutNode iteration
markushi 18a13f4
Fix tag propagation
markushi 994b7b2
Add tests
markushi 3559ed4
Address PR feedback
markushi f7cca22
Merge branch 'main' into markushi/fix/compose-110-api-changes
markushi ee7eff5
Format code
getsentry-bot f188f6c
Update CHANGELOG for Jetpack Compose and SDK version
markushi 38865c2
Merge branch 'main' into markushi/fix/compose-110-api-changes
markushi 00f2c99
Merge branch 'markushi/fix/compose-110-api-changes' of github.com:get…
markushi 745e707
return first tag instead of last one
markushi 19d21a3
Fix exception propagation
markushi fa61cae
Return first non-null tag
markushi cea378d
Allow nullable semantics in case there are really none
markushi 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
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
90 changes: 90 additions & 0 deletions
90
...oid-replay/src/main/java/io/sentry/android/replay/viewhierarchy/SentryLayoutNodeHelper.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,90 @@ | ||
| @file:Suppress( | ||
| "INVISIBLE_MEMBER", | ||
| "INVISIBLE_REFERENCE", | ||
| "EXPOSED_PARAMETER_TYPE", | ||
| "EXPOSED_RETURN_TYPE", | ||
| "EXPOSED_FUNCTION_RETURN_TYPE", | ||
| ) | ||
|
|
||
| package io.sentry.android.replay.viewhierarchy | ||
|
|
||
| import androidx.compose.ui.node.LayoutNode | ||
| import androidx.compose.ui.node.NodeCoordinator | ||
| import java.lang.reflect.Method | ||
|
|
||
| /** | ||
| * Provides access to internal LayoutNode members that are subject to Kotlin name-mangling. | ||
| * | ||
| * This class is not thread-safe, as Compose UI operations are expected to be performed on the main | ||
| * thread. | ||
| * | ||
| * Compiled against Compose >= 1.10 where the mangled names use the "ui" module suffix (e.g. | ||
| * getChildren$ui()). For apps still on Compose < 1.10 (where the suffix is "$ui_release"), the | ||
| * direct call will throw [NoSuchMethodError] and we fall back to reflection-based accessors that | ||
| * are resolved and cached on first use. | ||
| */ | ||
| internal object SentryLayoutNodeHelper { | ||
| private class Fallback(val getChildren: Method?, val getOuterCoordinator: Method?) | ||
|
|
||
| private var useFallback: Boolean? = null | ||
| private var fallback: Fallback? = null | ||
|
|
||
| private fun tryResolve(clazz: Class<*>, name: String): Method? { | ||
| return try { | ||
| clazz.getDeclaredMethod(name).apply { isAccessible = true } | ||
| } catch (_: NoSuchMethodException) { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| @Suppress("UNCHECKED_CAST") | ||
| fun getChildren(node: LayoutNode): List<LayoutNode> { | ||
| when (useFallback) { | ||
| false -> return node.children | ||
| true -> { | ||
| return getFallback().getChildren!!.invoke(node) as List<LayoutNode> | ||
markushi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| null -> { | ||
| try { | ||
| return node.children.also { useFallback = false } | ||
| } catch (_: NoSuchMethodError) { | ||
| useFallback = true | ||
| return getFallback().getChildren!!.invoke(node) as List<LayoutNode> | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun isTransparent(node: LayoutNode): Boolean { | ||
| when (useFallback) { | ||
| false -> return node.outerCoordinator.isTransparent() | ||
| true -> { | ||
| val fb = getFallback() | ||
| val coordinator = fb.getOuterCoordinator!!.invoke(node) as NodeCoordinator | ||
| return coordinator.isTransparent() | ||
| } | ||
| null -> { | ||
| try { | ||
| return node.outerCoordinator.isTransparent().also { useFallback = false } | ||
| } catch (_: NoSuchMethodError) { | ||
| useFallback = true | ||
| val fb = getFallback() | ||
| val coordinator = fb.getOuterCoordinator!!.invoke(node) as NodeCoordinator | ||
| return coordinator.isTransparent() | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun getFallback(): Fallback { | ||
| fallback?.let { | ||
| return it | ||
| } | ||
|
|
||
| val layoutNodeClass = LayoutNode::class.java | ||
| val getChildren = tryResolve(layoutNodeClass, "getChildren\$ui_release") | ||
| val getOuterCoordinator = tryResolve(layoutNodeClass, "getOuterCoordinator\$ui_release") | ||
|
|
||
| return Fallback(getChildren, getOuterCoordinator).also { fallback = it } | ||
| } | ||
| } | ||
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
15 changes: 15 additions & 0 deletions
15
...ry-compose/src/androidUnitTest/kotlin/androidx/compose/foundation/GestureModifierStubs.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,15 @@ | ||
| package androidx.compose.foundation | ||
|
|
||
| import androidx.compose.ui.Modifier | ||
|
|
||
| /** | ||
| * Stub classes used by [io.sentry.compose.gestures.ComposeGestureTargetLocatorTest] so that Mockito | ||
| * mocks of these classes return the correct [Class.getName] values at runtime. | ||
| */ | ||
| internal open class ClickableElement : Modifier.Element | ||
|
|
||
| internal open class CombinedClickableElement : Modifier.Element | ||
|
|
||
| internal open class ScrollingLayoutElement : Modifier.Element | ||
|
|
||
| internal open class ScrollingContainerElement : Modifier.Element |
Oops, something went wrong.
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.