Skip to content
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

[andr][replay] Add support for ignoring Compose elements via Modifiers #129

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.text.HtmlCompat
import io.bitdrift.capture.Capture
import io.bitdrift.capture.replay.internal.compose.CaptureModifier.captureIgnore
import timber.log.Timber

@Composable
Expand Down Expand Up @@ -62,7 +62,7 @@ fun SecondScreen() {
)
ElevatedButton(
onClick = { Timber.w("Warning logged from Compose Screen") },
modifier = centerWithPaddingModifier.padding(top = normalSpacing)
modifier = centerWithPaddingModifier.padding(top = normalSpacing).captureIgnore(ignoreSubTree = false)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example use

) {
Text("Log-a-log (Warning)")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.bitdrift.capture.replay.internal.compose

import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.semantics.semantics

object CaptureModifier {

val CaptureIgnore = SemanticsPropertyKey<Boolean>(
name = "CaptureIgnoreModifier",
mergePolicy = { parentValue, _ ->
parentValue
}
)

@JvmStatic
fun Modifier.captureIgnore(ignoreSubTree: Boolean = false): Modifier {
return semantics(
properties = {
this[CaptureIgnore] = ignoreSubTree
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import io.bitdrift.capture.replay.ReplayType
import io.bitdrift.capture.replay.SessionReplayController
import io.bitdrift.capture.replay.internal.ReplayRect
import io.bitdrift.capture.replay.internal.ScannableView
import io.bitdrift.capture.replay.internal.compose.ComposeTreeParser.unclippedGlobalBounds

internal object ComposeTreeParser {
internal val View.mightBeComposeView: Boolean
Expand All @@ -50,9 +49,18 @@ internal object ComposeTreeParser {
@OptIn(ExperimentalComposeUiApi::class, InternalComposeUiApi::class)
private fun SemanticsNode.toScannableView(): ScannableView {
val notAttachedOrPlaced = !this.layoutNode.isPlaced || !this.layoutNode.isAttached
val isVisible = !this.isTransparent && !unmergedConfig.contains(SemanticsProperties.InvisibleToUser)
val captureIgnoreSubTree = this.unmergedConfig.getOrNull(CaptureModifier.CaptureIgnore)
val isVisible = !this.isTransparent && !this.unmergedConfig.contains(SemanticsProperties.InvisibleToUser)
val type = if (notAttachedOrPlaced) {
return ScannableView.IgnoredComposeView
} else if (captureIgnoreSubTree != null) {
if (captureIgnoreSubTree) {
// short-circuit the entire sub-tree
return ScannableView.IgnoredComposeView
} else {
// just ignore this one element
ReplayType.Ignore
}
} else if (!isVisible) {
ReplayType.TransparentView
} else {
Expand Down
Loading