Skip to content

Commit

Permalink
fix: extract ComposeUtils to share with plugins (#202)
Browse files Browse the repository at this point in the history
* fix: moved compose logic to ComposeUtils
  • Loading branch information
justin-fiedler authored Jun 27, 2024
1 parent 1a5a392 commit c239bba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
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)
}
}
}

0 comments on commit c239bba

Please sign in to comment.