Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kazemihabib committed May 16, 2020
1 parent fbf0fdf commit 489da1a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import androidx.ui.graphics.*
import androidx.ui.unit.PxSize
import kotlin.math.tan

/**
* Used to specify this type of [ShimmerEffect] for [shimmer].
*/
object DefaultLinearShimmerEffectFactory : ShimmerEffectFactory {
override fun create(
baseAlpha: Float,
Expand All @@ -24,7 +27,7 @@ object DefaultLinearShimmerEffectFactory : ShimmerEffectFactory {
repeatMode: RepeatMode,
clock: AnimationClockObservable
): ShimmerEffect {
return DefaultShimmerEffect(
return DefaultLinearShimmerEffect(
baseAlpha,
highlightAlpha,
direction,
Expand All @@ -39,7 +42,7 @@ object DefaultLinearShimmerEffectFactory : ShimmerEffectFactory {
}
}

private class DefaultShimmerEffect(
private class DefaultLinearShimmerEffect(
val baseAlpha: Float,
val highlightAlpha: Float,
val direction: Direction,
Expand Down Expand Up @@ -93,8 +96,7 @@ private class DefaultShimmerEffect(
else if (state == ShimmerTransition.State.End)
if (repeatMode == RepeatMode.RESTART) {
animation.toState(ShimmerTransition.State.Reset)
}
else if (repeatMode == RepeatMode.REVERSE) {
} else if (repeatMode == RepeatMode.REVERSE) {
animation.toState(ShimmerTransition.State.Begin)
}
}
Expand Down
16 changes: 16 additions & 0 deletions shimmer/src/main/java/com/github/kazemihabib/shimmer/Shimmer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ import androidx.ui.graphics.painter.drawCanvas
import androidx.ui.graphics.withSaveLayer
import androidx.ui.unit.PxSize
import androidx.ui.unit.ipx
import com.github.kazemihabib.shimmer.RepeatMode.RESTART
import com.github.kazemihabib.shimmer.RepeatMode.REVERSE

/**
* Shimmer is a [Modifier] which adds a shimmering effect to any widget.
*
* @sample com.github.kazemihabib.compose_shimmer.App
*
* @param durationMs Time it takes for the highlight to move from one end of the layout to the other.
* @param delay Delay after which the current animation will repeat.
* @param repeatMode What the animation should do after reaching the end, either restart from the beginning or reverse back towards it.
* @param clock The animation clock observable that will drive this ripple effect
*/
@Composable
fun Modifier.shimmer(
durationMs: Int = 3000,
Expand Down Expand Up @@ -95,6 +107,10 @@ internal class ShimmerModifier(
}
}

/**
* [RESTART] restarts the [shimmer] effect animation after reaching the end of layout
* [REVERSE] reverses the [shimmer] effect animation after reaching the end of layout
*/
enum class RepeatMode {
RESTART,
REVERSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,43 @@ package com.github.kazemihabib.shimmer
import androidx.annotation.FloatRange
import androidx.compose.ambientOf

/**
* Defines the appearance and the behavior for [shimmer]s.
*
* You can define new theme and apply it via [ShimmerThemeAmbient].
*/
data class ShimmerTheme(
/**
* Defines the current [ShimmerEffect] implementation.
*/
val factory: ShimmerEffectFactory,

/**
* The alpha for unhighlighted section
*/
@FloatRange(from = 0.0, to = 1.0)
val baseAlpha: Float,

/**
* The alpha for highlighted section
*/
@FloatRange(from = 0.0, to = 1.0)
val highlightAlpha: Float,

/**
* The direction of [shimmer] effect
*/
val direction: Direction,

/**
* Controls the size of the fading edge of the highlight.
*/
@FloatRange(from = 0.0, to = 1.0)
val dropOff: Float,

/**
* Controls the brightness of the highlight at the center
*/
@FloatRange(from = 0.0, to = 1.0)
val intensity: Float,

/**
* Angle in degrees at which the [shimmer] is tilted
*/
val tilt: Float
) {
init {
Expand All @@ -33,13 +53,19 @@ data class ShimmerTheme(
}
}

/**
* Enum class defining the direction of [shimmer] effect
*/
enum class Direction {
LeftToRight,
TopToBottom,
RightToLeft,
BottomToTop
}

/**
* Ambient used for providing [ShimmerTheme] down the tree.
*/
val ShimmerThemeAmbient = ambientOf { defaultShimmerTheme }

private val defaultShimmerTheme = ShimmerTheme(
Expand Down

0 comments on commit 489da1a

Please sign in to comment.