-
-
Notifications
You must be signed in to change notification settings - Fork 468
Fix tags missing for compose view hierarchies #4275
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
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
20fe313
Fix tags missing for compose view hierarchies
markushi 194f3d4
Update Changelog
markushi 1b9ccc7
Merge branch 'main' into markushi/fix/compose-view-hierarchy-exporter
markushi f26cc63
Extract Jetpack Compose Tag extraction into a single method
markushi d9d17ec
Merge branch 'markushi/fix/compose-view-hierarchy-exporter' of github…
markushi aeed04d
Merge branch 'main' into markushi/fix/compose-view-hierarchy-exporter
markushi 73afd16
Cache internal fields
markushi 64df48e
Transfer Compose Helper to Compose library, Kotlin-ify
markushi 6a69939
Improve bounds calculation for ViewHierarchy and Gesture Target location
markushi ff4a437
Merge branch 'main' into markushi/fix/compose-view-hierarchy-exporter
markushi 24e9202
Fix formatting
markushi 5108160
Fix tests
markushi fd9987d
Minor cleanup
markushi 0f44b67
Fix lint + Kotlin compiler warnings
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package io.sentry.compose.viewhierarchy; | ||
|
|
||
| import androidx.compose.runtime.collection.MutableVector; | ||
| import androidx.compose.ui.Modifier; | ||
| import androidx.compose.ui.geometry.Rect; | ||
| import androidx.compose.ui.layout.ModifierInfo; | ||
| import androidx.compose.ui.node.LayoutNode; | ||
|
|
@@ -14,6 +15,7 @@ | |
| import io.sentry.internal.viewhierarchy.ViewHierarchyExporter; | ||
| import io.sentry.protocol.ViewHierarchyNode; | ||
| import io.sentry.util.AutoClosableReentrantLock; | ||
| import java.lang.reflect.Field; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -84,9 +86,13 @@ private static void addChild( | |
|
|
||
| private static void setTag( | ||
| final @NotNull LayoutNode node, final @NotNull ViewHierarchyNode vhNode) { | ||
| // needs to be in-sync with ComposeGestureTargetLocator | ||
| final List<ModifierInfo> modifiers = node.getModifierInfo(); | ||
| for (ModifierInfo modifierInfo : modifiers) { | ||
| if (modifierInfo.getModifier() instanceof SemanticsModifier) { | ||
| final @NotNull Modifier modifier = modifierInfo.getModifier(); | ||
| // Newer Jetpack Compose 1.5 uses Node modifier elements | ||
| final @Nullable String type = modifier.getClass().getCanonicalName(); | ||
| if (modifier instanceof SemanticsModifier) { | ||
| final SemanticsModifier semanticsModifierCore = | ||
| (SemanticsModifier) modifierInfo.getModifier(); | ||
| final SemanticsConfiguration semanticsConfiguration = | ||
|
|
@@ -99,6 +105,21 @@ private static void setTag( | |
| } | ||
| } | ||
| } | ||
| } else if ("androidx.compose.ui.platform.TestTagElement".equals(type) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to test it with robolectric/instrumented tests to avoid regressions in future? |
||
| || "io.sentry.compose.SentryModifier.SentryTagModifierNodeElement".equals(type)) { | ||
| // Newer Jetpack Compose uses TestTagElement as node elements | ||
| // See | ||
| // https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TestTag.kt;l=34;drc=dcaa116fbfda77e64a319e1668056ce3b032469f | ||
| try { | ||
| final Field tagField = modifier.getClass().getDeclaredField("tag"); | ||
| tagField.setAccessible(true); | ||
| final @Nullable Object value = tagField.get(modifier); | ||
| if (value instanceof String) { | ||
| vhNode.setTag((String) value); | ||
| } | ||
| } catch (Throwable e) { | ||
| // ignored | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.