`trackClick` implementation for Composable `onClick` functions that take parameters
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by locating the existing Compose SDK implementation of trackClick and TapActionTracker, then compare their callback types with ClickableText's (Int) -> Unit signature. Confirm how the current composable wrapper tracks clicks and forwards callbacks. Done means parameterized onClick functions can be wrapped while preserving their argument and existing click tracking behavior.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
In the Compose SDK, com.datadog.android.compose.trackClick cannot be used for Composables that take an onClick with parameters, such as ClickableText which has a function signature:
@Composable
fun ClickableText(
...
onClick: (Int) -> Unit
)
If we try to use it, there's a type mismatch:
@Composable
fun ClickableTextWithTrackedClicks(
onClick: (Int) -> Unit
) {
ClickableText(
...
onClick = trackClick(targetName = "Test") { TODO() } // Type mismatch here, as (Int) -> Unit is expected
)
}
Because trackClick is also a @Composable, it doesn't seem like there's a way to wrap it in a lambda.
eg. If we wished to print the Int parameter
ClickableText(
...
onClick = { i: Int ->
println(i)
trackClick(targetName = "Test") {}.invoke() // Can't be invoked because we're not in a `Composable` context
}
)
Describe the solution you'd like
An implementation of trackClick that accepts a generically typed onClick lambda parameter such as:
@Composable
fun <T> trackClick(
targetName: String,
onClick: (T) -> Unit
): (T) -> Unit {
val onTapState = rememberUpdatedState(newValue = onClick)
return remember(targetName, attributes) {
TapActionTracker(targetName, attributes, onTapState)
}
}
// This will require a separate mplementation of TapActionTracker as well
internal class TapActionTracker<T>(
private val targetName: String,
private val attributes: Map<String, Any?> = emptyMap(),
private val onTap: State<(T) -> Unit>,
private val rumMonitor: RumMonitor = GlobalRum.get()
) : (T) -> Unit {
override fun invoke(param: T) {
// RUM code
onTap.value.invoke(arg)
}
}
- Dominant language
- Kotlin
- Stars
- 226
- Forks
- 86
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 65
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DataDog/dd-sdk-android
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
DataDog/dd-sdk-android#3904 · 1 comment ·
Maintainers usually reply within 1 day
-
question
Difficulty 4/5 3-5 days Newbie friendliness 45/100
DataDog/dd-sdk-android#3888 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 32/100
DataDog/dd-sdk-android#3223 · 4 comments · 2 reactions ·
Maintainers usually reply within 1 day
-
automatically closed question stale
Difficulty 5/5 Over a week Newbie friendliness 25/100
DataDog/dd-sdk-android#2970 · 6 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 38/100
DataDog/dd-sdk-android#2700 · 1 comment ·
Maintainers usually reply within 1 day
All issues in DataDog/dd-sdk-android
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Source is down
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
keiyoushi/extensions-source#19491 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100