I am currently working on a code snipped for the A...
# compose-android
t
I am currently working on a code snipped for the Android Studio preview. So you can add this to the preview composable and then it detects overlaps with window insets. My question is about how to design the DSL to check for overlaps. I think the best approach would be to use SemanticsMatcher like in the ComposeContentTestRule in test. But than the problem is that i have a dependency to "androidx.compose.ui.test" what we normally do not want in production code. I will provide some samples in the thread for better understanding.
So one sample would be to check for overlaps with text. This would be look like this in testing:
Copy code
composeTestRule
    .onAllNodes(SemanticsMatcher.keyIsDefined(SemanticsProperties.Text))
    .assertWindowInsets(
        insetType = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout(),
    )
Or here a sample to check for overlaps with buttons:
Copy code
composeTestRule
    .onAllNodes(hasClickAction())
    .assertWindowInsets(
        insetType = WindowInsetsCompat.Type.tappableElement()
    )
So the question is if it is possible to make sure the dependency is not in release version of the app but available in debug. So of course i could include the dependency in debug only but than i need to write the previews in debug folder which is also not what i want.
Other option which is working for now but much less flexible is to just check for the SemanticsPropertyKey. This looks like this:
Copy code
TestWindowInsets {
    checkOverlap(WindowInsets.safeDrawing, SemanticsProperties.Text)
    checkOverlap(WindowInsets.systemGestures, SemanticsActions.OnClick)
}
image.png
a
Is
compileOnly
+
debugImplementation
enough?
t
Ah ok i will check that. Thank you for the idea
I checked it and it looks good. So the SemanticMatcher and the hasClickAction() functions are inside of the release apk but nothing else. So i think this is ok. Not sure in general if there is a good option to exclude anything preview related from the release builds.
a
Preview code should be stripped out if R8 is enabled. If it's not, you may want to check if you are calling it in production code.