diff --git a/app/build.gradle b/app/build.gradle index d50134d..e3cbc8a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,7 +52,8 @@ dependencies { implementation('org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0') } - implementation 'io.github.pseudoankit:coachmark:1.0.3' +// implementation project(":coachmark") + implementation 'io.github.pseudoankit:coachmark:1.6.1' implementation 'androidx.activity:activity-compose:1.7.2' implementation platform('androidx.compose:compose-bom:2022.10.00') implementation 'androidx.compose.ui:ui' diff --git a/coachmark/build.gradle b/coachmark/build.gradle index fa9cf9f..67d97ec 100644 --- a/coachmark/build.gradle +++ b/coachmark/build.gradle @@ -18,7 +18,7 @@ android { compileSdk 34 defaultConfig { - minSdk 19 + minSdk 21 targetSdk 34 } diff --git a/coachmark/src/main/java/com/pseudoankit/coachmark/UnifyCoachmark.kt b/coachmark/src/main/java/com/pseudoankit/coachmark/UnifyCoachmark.kt index 2d5aa90..c6a111b 100644 --- a/coachmark/src/main/java/com/pseudoankit/coachmark/UnifyCoachmark.kt +++ b/coachmark/src/main/java/com/pseudoankit/coachmark/UnifyCoachmark.kt @@ -15,8 +15,8 @@ import com.pseudoankit.coachmark.ui.CoachMarkImpl import com.pseudoankit.coachmark.util.CoachMarkDefaults import com.pseudoankit.coachmark.util.CoachMarkKey -public val LocalCoachMarkScope: ProvidableCompositionLocal = - compositionLocalOf { null } +public val LocalCoachMarkScope: ProvidableCompositionLocal = + compositionLocalOf { error("CompositionLocal CoachMarkScope not present") } @Composable public fun UnifyCoachmark( diff --git a/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt b/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt index 9a4afd9..dafa72f 100644 --- a/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt +++ b/coachmark/src/main/java/com/pseudoankit/coachmark/demo/UnifyCoachmarkDemo.kt @@ -20,6 +20,7 @@ import com.pseudoankit.coachmark.model.HighlightedViewConfig import com.pseudoankit.coachmark.model.OverlayClickEvent import com.pseudoankit.coachmark.model.ToolTipPlacement import com.pseudoankit.coachmark.overlay.DimOverlayEffect +import com.pseudoankit.coachmark.scope.enableCoachMark import com.pseudoankit.coachmark.shape.Arrow import com.pseudoankit.coachmark.shape.Balloon import com.pseudoankit.coachmark.util.CoachMarkKey @@ -65,23 +66,22 @@ private fun ColumnScope.CoachMarkTargetText( ) { val coachMarkScope = LocalCoachMarkScope.current - coachMarkScope?.apply { - Text( - text = text, - modifier = Modifier - .align(alignment) - .enableCoachMark( - key = key, - toolTipPlacement = placement, - highlightedViewConfig = HighlightedViewConfig( - shape = HighlightedViewConfig.Shape.Rect(12.dp), - padding = PaddingValues(8.dp) - ) - ) - .padding(16.dp), - color = Color.Black - ) - } + Text( + text = text, + modifier = Modifier + .align(alignment) + .enableCoachMark( + key = key, + toolTipPlacement = placement, + highlightedViewConfig = HighlightedViewConfig( + shape = HighlightedViewConfig.Shape.Rect(12.dp), + padding = PaddingValues(8.dp) + ), + coachMarkScope = coachMarkScope + ) + .padding(16.dp), + color = Color.Black + ) } @Preview diff --git a/coachmark/src/main/java/com/pseudoankit/coachmark/scope/CoachMarkScope.kt b/coachmark/src/main/java/com/pseudoankit/coachmark/scope/CoachMarkScope.kt index cf565ec..89fd149 100644 --- a/coachmark/src/main/java/com/pseudoankit/coachmark/scope/CoachMarkScope.kt +++ b/coachmark/src/main/java/com/pseudoankit/coachmark/scope/CoachMarkScope.kt @@ -49,4 +49,31 @@ public interface CoachMarkScope { * if passed multiple keys then it will be displayed sequentially on the basis of [OverlayClickEvent] */ public fun show(vararg keys: CoachMarkKey) -} \ No newline at end of file +} + +/** + * helper function to call [CoachMarkScope.enableCoachMark] when not in scope of [CoachMarkScope] + * + * Access [coachMarkScope] by LocalCoachMarkScope.current + * @see CoachMarkScope.enableCoachMark + * modifier extension to enable coachmark on a view + * @param coachMarkScope scope of coachmark + * @param key unique key to be applied for a view + * @param toolTipPlacement decides the placement of tooltip w.r.t the actual view + * @param tooltipAnimationSpec animation spec to be applied when showing/hiding tooltip + * @param highlightedViewConfig config to be applied to highlight the actual view when showing tooltip + */ +public fun Modifier.enableCoachMark( + coachMarkScope: CoachMarkScope, + key: CoachMarkKey, + toolTipPlacement: ToolTipPlacement, + tooltipAnimationSpec: AnimationSpec = CoachMarkDefaults.ToolTip.animationSpec, + highlightedViewConfig: HighlightedViewConfig = HighlightedViewConfig() +): Modifier = with(coachMarkScope) { + enableCoachMark( + key = key, + toolTipPlacement = toolTipPlacement, + tooltipAnimationSpec = tooltipAnimationSpec, + highlightedViewConfig = highlightedViewConfig + ) +}