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

fix: extract ComposeUtils to share with plugins #202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,14 +1,9 @@
package com.amplitude.android.internal.locators

import com.amplitude.android.utilities.LoadClass
import com.amplitude.android.utilities.ComposeUtils
import com.amplitude.common.Logger

internal object ViewTargetLocators {
private const val COMPOSE_CLASS_NAME = "androidx.compose.ui.node.Owner"
private const val SCROLLING_VIEW_CLASS_NAME = "androidx.core.view.ScrollingView"
private const val COMPOSE_GESTURE_LOCATOR_CLASS_NAME =
"com.amplitude.android.internal.locators.ComposeViewTargetLocator"

/**
* A list [ViewTargetLocator]s for classic Android [View][android.view.View]s and Jetpack
* Compose.
Expand All @@ -19,18 +14,10 @@ internal object ViewTargetLocators {
val ALL: (Logger) -> List<ViewTargetLocator> by lazy {
{ logger ->
mutableListOf<ViewTargetLocator>().apply {
val loadClass = LoadClass()
val isComposeUpstreamAvailable = loadClass.isClassAvailable(COMPOSE_CLASS_NAME, logger)
val isComposeAvailable =
isComposeUpstreamAvailable &&
loadClass.isClassAvailable(COMPOSE_GESTURE_LOCATOR_CLASS_NAME, logger)
val isAndroidXScrollViewAvailable =
loadClass.isClassAvailable(SCROLLING_VIEW_CLASS_NAME, logger)

if (isComposeAvailable) {
if (ComposeUtils.isComposeAvailable()) {
add(ComposeViewTargetLocator(logger))
}
add(AndroidViewTargetLocator(isAndroidXScrollViewAvailable))
add(AndroidViewTargetLocator(ComposeUtils.isAndroidXScrollViewAvailable(logger)))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.amplitude.android.utilities

import com.amplitude.common.Logger

class ComposeUtils {
companion object {
private val loadClass = LoadClass()
private const val COMPOSE_CLASS_NAME = "androidx.compose.ui.node.Owner"
private const val SCROLLING_VIEW_CLASS_NAME = "androidx.core.view.ScrollingView"
private const val COMPOSE_GESTURE_LOCATOR_CLASS_NAME =
"com.amplitude.android.internal.locators.ComposeViewTargetLocator"

fun isComposeAvailable(logger: Logger? = null): Boolean {
return loadClass.isClassAvailable(COMPOSE_CLASS_NAME, logger) &&
loadClass.isClassAvailable(COMPOSE_GESTURE_LOCATOR_CLASS_NAME, logger)
}

fun isAndroidXScrollViewAvailable(logger: Logger? = null): Boolean {
return loadClass.isClassAvailable(SCROLLING_VIEW_CLASS_NAME, logger)
}
}
}