-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #293 from chattymin/feature/animate-topappbar
[Feature/#275] animated topAppBar
- Loading branch information
Showing
2 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...rc/commonMain/kotlin/io/github/droidkaigi/confsched/ui/component/AnimatedTextTopAppBar.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,68 @@ | ||
package io.github.droidkaigi.confsched.ui.component | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.material3.TopAppBarColors | ||
import androidx.compose.material3.TopAppBarDefaults | ||
import androidx.compose.material3.TopAppBarScrollBehavior | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.ui.text.style.TextAlign | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun AnimatedTextTopAppBar( | ||
title: String, | ||
modifier: Modifier = Modifier, | ||
navigationIcon: @Composable () -> Unit = {}, | ||
actions: @Composable RowScope.() -> Unit = {}, | ||
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, | ||
colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors(), | ||
scrollBehavior: TopAppBarScrollBehavior? = null, | ||
) { | ||
val scrollFraction = scrollBehavior?.state?.overlappedFraction ?: 0f | ||
val transitionFraction = scrollFraction.coerceIn(0f, 1f) | ||
|
||
TopAppBar( | ||
title = { | ||
Box(modifier = Modifier.fillMaxWidth()) { | ||
Text( | ||
text = title, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.graphicsLayer { | ||
alpha = 1f - transitionFraction | ||
}, | ||
textAlign = TextAlign.Start, | ||
style = MaterialTheme.typography.headlineSmall, | ||
) | ||
|
||
Text( | ||
text = title, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.align(Alignment.Center) | ||
.graphicsLayer { | ||
alpha = transitionFraction | ||
}, | ||
textAlign = TextAlign.Center, | ||
style = MaterialTheme.typography.titleMedium, | ||
) | ||
} | ||
}, | ||
modifier = modifier, | ||
navigationIcon = navigationIcon, | ||
actions = actions, | ||
windowInsets = windowInsets, | ||
colors = colors, | ||
scrollBehavior = scrollBehavior, | ||
) | ||
} |
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