From 56395445ac51ad6b288632ebb55d4ecb503ca360 Mon Sep 17 00:00:00 2001 From: HyunWoo Lee Date: Thu, 26 Dec 2024 19:27:56 +0900 Subject: [PATCH] =?UTF-8?q?[#1009]=20LocalTracker=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/analytics/build.gradle.kts | 1 + .../analytics/compose/CompositionLocal.kt | 17 +++++++++++++++++ .../official/analytics/compose/LocalTracker.kt | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100644 core/analytics/src/main/java/org/sopt/official/analytics/compose/CompositionLocal.kt create mode 100644 core/analytics/src/main/java/org/sopt/official/analytics/compose/LocalTracker.kt diff --git a/core/analytics/build.gradle.kts b/core/analytics/build.gradle.kts index 53d059ded..91a87e343 100644 --- a/core/analytics/build.gradle.kts +++ b/core/analytics/build.gradle.kts @@ -25,6 +25,7 @@ plugins { sopt("feature") + sopt("compose") } android { diff --git a/core/analytics/src/main/java/org/sopt/official/analytics/compose/CompositionLocal.kt b/core/analytics/src/main/java/org/sopt/official/analytics/compose/CompositionLocal.kt new file mode 100644 index 000000000..c7335d1bb --- /dev/null +++ b/core/analytics/src/main/java/org/sopt/official/analytics/compose/CompositionLocal.kt @@ -0,0 +1,17 @@ +package org.sopt.official.analytics.compose + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import org.sopt.official.analytics.Tracker + +@Composable +fun ProvideTracker( + tracker: Tracker, + content: @Composable () -> Unit +) { + CompositionLocalProvider( + LocalTracker provides tracker + ) { + content() + } +} diff --git a/core/analytics/src/main/java/org/sopt/official/analytics/compose/LocalTracker.kt b/core/analytics/src/main/java/org/sopt/official/analytics/compose/LocalTracker.kt new file mode 100644 index 000000000..2ae62f372 --- /dev/null +++ b/core/analytics/src/main/java/org/sopt/official/analytics/compose/LocalTracker.kt @@ -0,0 +1,8 @@ +package org.sopt.official.analytics.compose + +import androidx.compose.runtime.staticCompositionLocalOf +import org.sopt.official.analytics.Tracker + +val LocalTracker = staticCompositionLocalOf { + error("No Tracker provided") +}