-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
478 additions
and
38 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
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
41 changes: 41 additions & 0 deletions
41
sentry-compose-helper/src/jvmMain/java/io/sentry/compose/SentryComposeHelper.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.sentry.compose; | ||
|
||
import androidx.compose.ui.geometry.Rect; | ||
import androidx.compose.ui.layout.LayoutCoordinatesKt; | ||
import androidx.compose.ui.node.LayoutNode; | ||
import androidx.compose.ui.node.LayoutNodeLayoutDelegate; | ||
import io.sentry.ILogger; | ||
import io.sentry.SentryLevel; | ||
import java.lang.reflect.Field; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class SentryComposeHelper { | ||
|
||
private final @NotNull ILogger logger; | ||
private Field layoutDelegateField = null; | ||
|
||
public SentryComposeHelper(final @NotNull ILogger logger) { | ||
this.logger = logger; | ||
try { | ||
final Class<?> clazz = Class.forName("androidx.compose.ui.node.LayoutNode"); | ||
layoutDelegateField = clazz.getDeclaredField("layoutDelegate"); | ||
layoutDelegateField.setAccessible(true); | ||
} catch (Exception e) { | ||
logger.log(SentryLevel.WARNING, "Could not find LayoutNode.layoutDelegate field"); | ||
} | ||
} | ||
|
||
public @Nullable Rect getLayoutNodeBoundsInWindow(@NotNull final LayoutNode node) { | ||
if (layoutDelegateField != null) { | ||
try { | ||
final LayoutNodeLayoutDelegate delegate = | ||
(LayoutNodeLayoutDelegate) layoutDelegateField.get(node); | ||
return LayoutCoordinatesKt.boundsInWindow(delegate.getOuterCoordinator().getCoordinates()); | ||
} catch (Exception e) { | ||
logger.log(SentryLevel.WARNING, "Could not fetch position for LayoutNode", e); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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.