Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoping via local provider #26

Merged
merged 3 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
}
Loading