Skip to content

Commit

Permalink
added animation progress callback
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudoankit committed Dec 2, 2023
1 parent fbab927 commit 5c3e582
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ public data class TooltipConfig(
* @param initialAlpha denotes the starting alpha value when visibility changes
* @param targetAlpha denotes the ending alpha value when visibility changes
* @param tooltipAnimationSpec denotes the animation that needs to be applied when changing visibility of tooltip
* @param onAlphaValueUpdated callback when alpha value is animating from [initialAlpha] to [targetAlpha]
*/
@Stable
public data class AnimationState(
val initialAlpha: Float = 0f,
val targetAlpha: Float = 0f,
val tooltipAnimationSpec: AnimationSpec<Float>
val tooltipAnimationSpec: AnimationSpec<Float>,
val onAlphaValueUpdated: (Float) -> Unit = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ internal fun CoachMarkImpl(
rememberTooltipHolder(
item = it,
animationSpec = it.animationState.tooltipAnimationSpec,
onAlphaValueUpdated = it.animationState.onAlphaValueUpdated
)
}

val previousTooltip = coachMarkScope.lastVisibleTooltip?.let {
rememberTooltipHolder(
item = it,
animationSpec = it.animationState.tooltipAnimationSpec,
onAlphaValueUpdated = it.animationState.onAlphaValueUpdated
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import com.pseudoankit.coachmark.model.TooltipHolder

/**
* utility to create a tooltip holder which wraps the tooltip along with alpha of the view to animate
* @param onAlphaValueUpdated callback when alpha value is animating from initial to target alpha
*/
@Composable
internal fun rememberTooltipHolder(
item: TooltipConfig,
animationSpec: AnimationSpec<Float>,
onAlphaValueUpdated: (Float) -> Unit
): TooltipHolder {

var alpha by rememberMutableStateOf(
Expand All @@ -31,6 +33,7 @@ internal fun rememberTooltipHolder(
animationSpec = animationSpec,
block = { value, _ ->
alpha = value
onAlphaValueUpdated(value)
}
)
}
Expand Down

0 comments on commit 5c3e582

Please sign in to comment.