Skip to content

Commit

Permalink
Merge pull request #26 from pseudoankit/scoping-via-local-provider
Browse files Browse the repository at this point in the history
Scoping via local provider
  • Loading branch information
pseudoankit authored Jan 27, 2024
2 parents 45c7629 + 21d4f55 commit 7ce5f8e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion coachmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
compileSdk 34

defaultConfig {
minSdk 19
minSdk 21
targetSdk 34
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoachMarkScope?> =
compositionLocalOf { null }
public val LocalCoachMarkScope: ProvidableCompositionLocal<CoachMarkScope> =
compositionLocalOf { error("CompositionLocal CoachMarkScope not present") }

@Composable
public fun UnifyCoachmark(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

/**
* 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<Float> = CoachMarkDefaults.ToolTip.animationSpec,
highlightedViewConfig: HighlightedViewConfig = HighlightedViewConfig()
): Modifier = with(coachMarkScope) {
enableCoachMark(
key = key,
toolTipPlacement = toolTipPlacement,
tooltipAnimationSpec = tooltipAnimationSpec,
highlightedViewConfig = highlightedViewConfig
)
}

0 comments on commit 7ce5f8e

Please sign in to comment.