-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Use tabs for built-in and custom rules.
- Loading branch information
Showing
7 changed files
with
168 additions
and
104 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
38 changes: 38 additions & 0 deletions
38
app/src/main/java/me/zhanghai/android/untracker/ui/component/TopAppBarContainer.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,38 @@ | ||
package me.zhanghai.android.untracker.ui.component | ||
|
||
import androidx.compose.animation.animateColorAsState | ||
import androidx.compose.animation.core.Spring | ||
import androidx.compose.animation.core.spring | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.TopAppBarScrollBehavior | ||
import androidx.compose.material3.surfaceColorAtElevation | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.SideEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
fun TopAppBarContainer(scrollBehavior: TopAppBarScrollBehavior, content: @Composable () -> Unit) { | ||
val heightOffsetLimit = with(LocalDensity.current) { -64.0.dp.toPx() } | ||
SideEffect { | ||
if (scrollBehavior.state.heightOffsetLimit != heightOffsetLimit) { | ||
scrollBehavior.state.heightOffsetLimit = heightOffsetLimit | ||
} | ||
} | ||
val targetColor = | ||
if (scrollBehavior.state.overlappedFraction > 0.01f) { | ||
MaterialTheme.colorScheme.surfaceColorAtElevation(3.dp) | ||
} else { | ||
MaterialTheme.colorScheme.surface | ||
} | ||
val color by | ||
animateColorAsState( | ||
targetValue = targetColor, | ||
animationSpec = spring(stiffness = Spring.StiffnessMediumLow) | ||
) | ||
Surface(color = color, content = content) | ||
} |
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
Oops, something went wrong.