Skip to content

Commit

Permalink
Merge pull request #22 from zsoltk/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
zsoltk authored Oct 3, 2023
2 parents 5c35555 + 43e30b7 commit 92a7e99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.max
import com.bumble.appyx.components.backstack.BackStack
import com.bumble.appyx.components.backstack.BackStackModel
import com.bumble.appyx.components.backstack.operation.replace
Expand Down Expand Up @@ -151,7 +149,7 @@ class PuzzyxAppNode(
) {
Icon(
imageVector = if (isAutoPlayOn) Icons.Filled.Pause else Icons.Filled.PlayArrow,
contentDescription = "Toggle manual controls",
contentDescription = "Toggle auto-play",
tint = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.alpha(if (isAutoPlayOn) 0.035f else 1f),
)
Expand Down Expand Up @@ -188,22 +186,15 @@ class PuzzyxAppNode(
@Composable
private fun ClipShape(progress: Float): Shape {
val screenSize = LocalScreenSize.current
val density = LocalDensity.current
val (meshMin, meshMax) = 15 to 25
val (meshMin, meshMax) = 14 to 25
val meshSizeX = if (screenSize.widthDp > screenSize.heightDp) meshMax else meshMin
val meshSizeY = if (screenSize.widthDp > screenSize.heightDp) meshMin else meshMax
val maxRadius = remember(screenSize) {
with(density) {
max(screenSize.widthDp, screenSize.heightDp).toPx() / meshMin * 1.5f
}
}

val shape by remember(progress) {
mutableStateOf(
DottedMeshShape(
meshSizeX,
meshSizeY,
maxRadius,
progress
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.bumble.appyx.interactions.core.annotations.FloatRange
import com.bumble.appyx.interactions.core.ui.math.clamp
import com.bumble.appyx.interactions.core.ui.math.lerpFloat
import com.bumble.puzzyx.math.mapValueRange
import java.lang.Integer.max
import kotlin.math.abs
import kotlin.math.sqrt

Expand All @@ -23,7 +24,7 @@ import kotlin.math.sqrt
* Expecting a [progress] value that represents the state of the animation in the [0f..1f] range,
* each circle's radius will be calculated for the current frame such that:
* - the starting value for radius is 0
* - the maximum radius is [maxRadius]
* - the maximum radius is determined automatically based on mesh size
* - the radius animation for a given circle is delayed based on its position in the mesh,
* center ones starting first, gradually followed by ones closer to the edges
*
Expand All @@ -33,7 +34,6 @@ import kotlin.math.sqrt
class DottedMeshShape(
private val meshSizeX: Int,
private val meshSizeY: Int,
private val maxRadius: Float,
@FloatRange(from = 0.0, to = 1.0)
private val progress: Float = 0f
) : Shape {
Expand All @@ -44,6 +44,7 @@ class DottedMeshShape(
): Outline {
val (width, height) = size
val progressDelayed = lerpFloat(-1.0f, 1f, progress)
val targetRadius = size.maxDimension / max(meshSizeX, meshSizeY)

val sheet = Path().apply {
addRect(Rect(0f, 0f, width, height))
Expand All @@ -53,6 +54,7 @@ class DottedMeshShape(
val halfMeshWidth = 0.5f * (width / appliedMeshSizeX)
val halfMeshHeight = 0.5f * (height / appliedMeshSizeY)
val clampRadius = sqrt(halfMeshWidth * halfMeshWidth + halfMeshHeight * halfMeshHeight)

val dots = Path().apply {
for (y in 0 until meshSizeY) {
for (x in 0 until meshSizeX) {
Expand All @@ -64,15 +66,17 @@ class DottedMeshShape(
y = lerpFloat(0f, height, v)
)

val value = (progressDelayed
+ (0.5f - abs(u - 0.5f))
+ (0.5f - abs(v - 0.5f)))

val radius = clamp(
x = mapValueRange(
value = progressDelayed
+ (0.5f - abs(u - 0.5f))
+ (0.5f - abs(v - 0.5f)),
value.coerceAtMost(1f),
fromRangeMin = 0f,
fromRangeMax = 2f,
fromRangeMax = 1f,
destRangeMin = 0f,
destRangeMax = maxRadius
destRangeMax = targetRadius
),
min = 0f,
max = clampRadius,
Expand Down

0 comments on commit 92a7e99

Please sign in to comment.