-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dded48
commit 97b2ee4
Showing
17 changed files
with
383 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
library/src/main/java/com/abdullahalhakimi/smoothmotion/animations/AnimatedButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.abdullahalhakimi.smoothmotion.animations | ||
|
||
import androidx.compose.animation.core.animateFloatAsState | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.ui.unit.dp | ||
|
||
|
||
@Composable | ||
fun AnimatedButton( | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
scaleDownValue: Float = 0.95f, | ||
animationDuration: Int = 300, | ||
cornerRadius: Int = 8, | ||
padding: Int = 16, | ||
content: @Composable () -> Unit | ||
) { | ||
var isPressed by remember { mutableStateOf(false) } | ||
val scale by animateFloatAsState( | ||
targetValue = if (isPressed) scaleDownValue else 1f, | ||
animationSpec = tween(durationMillis = animationDuration) | ||
) | ||
|
||
Surface( | ||
modifier = modifier | ||
.graphicsLayer(scaleX = scale, scaleY = scale) | ||
.clickable( | ||
onClick = { | ||
isPressed = true | ||
onClick() | ||
isPressed = false | ||
} | ||
), | ||
shape = RoundedCornerShape(cornerRadius.dp), | ||
color = MaterialTheme.colorScheme.primary | ||
) { | ||
Box(modifier = Modifier.padding(padding.dp)) { | ||
content() | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
library/src/main/java/com/abdullahalhakimi/smoothmotion/animations/ExpandingCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.abdullahalhakimi.smoothmotion.animations | ||
|
||
import androidx.compose.animation.animateContentSize | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.* | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun ExpandingCard( | ||
headerContent: @Composable () -> Unit, | ||
expandedContent: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
isExpanded: Boolean = false, | ||
onClick: () -> Unit = {}, | ||
animationDuration: Int = 300, | ||
cornerRadius: Int = 8, | ||
padding: Int = 16 | ||
) { | ||
Surface( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(padding.dp) | ||
.clickable { onClick() } | ||
.animateContentSize(tween(durationMillis = animationDuration)), | ||
shape = RoundedCornerShape(cornerRadius.dp), | ||
color = MaterialTheme.colorScheme.surface, | ||
tonalElevation = 4.dp | ||
) { | ||
Column(modifier = Modifier.padding(padding.dp)) { | ||
headerContent() | ||
if (isExpanded) { | ||
Spacer(modifier = Modifier.height(8.dp)) | ||
expandedContent() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
//@Composable | ||
//fun ExpandingCard( | ||
// headerContent: @Composable () -> Unit, | ||
// expandedContent: @Composable () -> Unit, | ||
// modifier: Modifier = Modifier, | ||
// animationDuration: Int = 300, | ||
// cornerRadius: Int = 8, | ||
// padding: Int = 16 | ||
//) { | ||
// var expanded by remember { mutableStateOf(false) } | ||
// | ||
// Surface( | ||
// modifier = modifier | ||
// .fillMaxWidth() | ||
// .padding(padding.dp) | ||
// .clickable { expanded = !expanded } | ||
// .animateContentSize(tween(durationMillis = animationDuration)), | ||
// shape = RoundedCornerShape(cornerRadius.dp), | ||
// color = MaterialTheme.colorScheme.surface, | ||
// tonalElevation = 4.dp | ||
// ) { | ||
// Column(modifier = Modifier.padding(padding.dp)) { | ||
// headerContent() | ||
// if (expanded) { | ||
// Spacer(modifier = Modifier.height(8.dp)) | ||
// expandedContent() | ||
// } | ||
// } | ||
// } | ||
//} |
42 changes: 42 additions & 0 deletions
42
library/src/main/java/com/abdullahalhakimi/smoothmotion/animations/LoadingIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.abdullahalhakimi.smoothmotion.animations | ||
|
||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.animation.core.* | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun PulsatingLoadingIndicator( | ||
modifier: Modifier = Modifier, | ||
color: Color = Color.Blue, | ||
size: Int = 50, | ||
minScale: Float = 0.8f, | ||
maxScale: Float = 1.2f, | ||
pulsationDuration: Int = 1000, | ||
easing: Easing = LinearEasing | ||
) { | ||
val infiniteTransition = rememberInfiniteTransition(label = "LoadingIndicator") | ||
val scale by infiniteTransition.animateFloat( | ||
initialValue = minScale, | ||
targetValue = maxScale, | ||
animationSpec = infiniteRepeatable( | ||
animation = tween(pulsationDuration, easing = easing), | ||
repeatMode = RepeatMode.Reverse | ||
), | ||
label = "LoadingIndicator", | ||
) | ||
|
||
Surface( | ||
modifier = modifier | ||
.size(size.dp) | ||
.graphicsLayer(scaleX = scale, scaleY = scale), | ||
color = color, | ||
shape = CircleShape | ||
) {} | ||
} |
Oops, something went wrong.