-
Notifications
You must be signed in to change notification settings - Fork 0
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
f22d1d7
commit b57775c
Showing
14 changed files
with
389 additions
and
82 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.yrovas.linklater.ui.common | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material3.MaterialTheme.colorScheme | ||
import androidx.compose.material3.SnackbarHost | ||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
|
||
@Composable | ||
fun Frame( | ||
page: String, | ||
back: (() -> Unit), | ||
fab: (@Composable () -> Unit)? = null, | ||
snackState: SnackbarHostState, | ||
content: @Composable () -> Unit, | ||
) { | ||
Frame(appBar = { AppBar(page, back)}, | ||
fab = fab, | ||
snackState = snackState) { | ||
content() | ||
} | ||
} | ||
|
||
@Composable | ||
fun Frame( | ||
appBar: @Composable () -> Unit, | ||
fab: (@Composable () -> Unit)? = null, | ||
snackState: SnackbarHostState, | ||
content: @Composable () -> Unit, | ||
) { | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = colorScheme.background, | ||
contentColor = colorScheme.onBackground | ||
) { | ||
Box(modifier = Modifier.fillMaxSize()) { | ||
Column { | ||
appBar() | ||
content() | ||
} | ||
Column(modifier = Modifier.align(Alignment.BottomStart)) { | ||
fab?.let { | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.End | ||
) { fab() } | ||
} | ||
SnackbarHost(hostState = snackState) | ||
} | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/src/main/java/org/yrovas/linklater/ui/common/RefreshIcon.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,76 @@ | ||
package org.yrovas.linklater.ui.common | ||
|
||
import androidx.compose.animation.core.Animatable | ||
import androidx.compose.animation.core.CubicBezierEasing | ||
import androidx.compose.animation.core.Easing | ||
import androidx.compose.animation.core.LinearEasing | ||
import androidx.compose.animation.core.RepeatMode | ||
import androidx.compose.animation.core.infiniteRepeatable | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Refresh | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
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.draw.rotate | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun RefreshIcon( | ||
modifier: Modifier = Modifier, | ||
refreshing: StateFlow<Boolean>, | ||
icon: ImageVector = Icons.Default.Refresh, | ||
tint: Color = MaterialTheme.colorScheme.primary, | ||
) { | ||
val slowInFastOutEasing: Easing = | ||
remember { CubicBezierEasing(0.25f, 0.1f, 0.25f, 1.0f) } | ||
val linearInFastOutEasing: Easing = | ||
remember { CubicBezierEasing(0.4f, 0.0f, 0.25f, 1.0f) } | ||
|
||
val isRefreshing by refreshing.collectAsState() | ||
var didRefresh by remember { mutableStateOf(false) } | ||
val rotation = remember { Animatable(0f) } | ||
|
||
LaunchedEffect(isRefreshing) { | ||
launch { | ||
val duration = 750 | ||
val target = 360f | ||
if (isRefreshing) { | ||
didRefresh = true | ||
rotation.animateTo( | ||
targetValue = 360f, animationSpec = infiniteRepeatable( | ||
animation = tween( | ||
durationMillis = duration, easing = slowInFastOutEasing | ||
), repeatMode = RepeatMode.Restart | ||
) | ||
) | ||
} else if (didRefresh) { | ||
val remainingMillis: Int = ((target - rotation.value) / target * duration).toInt() | ||
val easing = if (remainingMillis > (duration/2)) linearInFastOutEasing else LinearEasing | ||
rotation.animateTo( | ||
targetValue = 360f, | ||
initialVelocity = rotation.velocity, | ||
animationSpec = tween( | ||
durationMillis = remainingMillis, easing = easing | ||
) | ||
) | ||
rotation.snapTo(0f) | ||
} | ||
} | ||
} | ||
|
||
Icon( | ||
imageVector = icon, | ||
tint = tint, | ||
modifier = modifier.rotate(rotation.value) | ||
) | ||
} |
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
Oops, something went wrong.