Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.imashnake.animite.banner

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -15,6 +16,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
Expand All @@ -30,6 +32,7 @@ import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.util.fastCoerceIn
import com.imashnake.animite.core.ui.LocalPaddings
import com.imashnake.animite.core.ui.ext.thenIf

/**
* Most screens and pages follow a banner-style layout in Animite.
Expand Down Expand Up @@ -74,6 +77,7 @@ fun NestedScrollBannerLayout(
banner: @Composable BoxScope.(Float, Modifier) -> Unit,
bannerElevatedContent: @Composable BoxScope.(Float) -> Unit,
content: @Composable ColumnScope.() -> Unit,
isExpanded: Boolean,
modifier: Modifier = Modifier,
maxBannerHeight: Dp = dimensionResource(R.dimen.banner_height),
contentPadding: PaddingValues = PaddingValues(),
Expand All @@ -86,6 +90,16 @@ fun NestedScrollBannerLayout(
var bannerHeightPx by remember { mutableFloatStateOf(maxBannerHeightPx) }
var ratio by remember { mutableFloatStateOf(1f) }

LaunchedEffect(isExpanded) {
if (isExpanded) {
ratio = 1f
bannerHeightPx = maxBannerHeightPx
} else {
ratio = 0f
bannerHeightPx = minBannerHeightPx
}
}

// Copied from TopAppBar.ExitUntilCollapsedScrollBehavior
val nestedScrollConnection = remember {
object : NestedScrollConnection {
Expand Down Expand Up @@ -133,17 +147,18 @@ fun NestedScrollBannerLayout(
}
}

Box(modifier.nestedScroll(nestedScrollConnection)) {
Box(modifier.thenIf(condition = isExpanded) { nestedScroll(nestedScrollConnection) }) {
val bannerHeight by animateFloatAsState(bannerHeightPx)
banner(
ratio,
Modifier
.height(with(density) { bannerHeightPx.toDp() })
.height(with(density) { bannerHeight.toDp() })
.fillMaxWidth()
)
Column(
modifier = Modifier
.fillMaxSize()
.padding(top = with(density) { bannerHeightPx.toDp() })
.padding(top = with(density) { bannerHeight.toDp() })
.background(contentBackgroundColor)
.padding(contentPadding),
verticalArrangement = verticalArrangement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.animateIntAsState
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
Expand Down Expand Up @@ -66,9 +67,11 @@
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
Expand Down Expand Up @@ -182,18 +185,22 @@

var isRefreshing by remember { mutableStateOf(false) }
val pullToRefreshState = rememberPullToRefreshState()

var isBannerExpanded by remember { mutableStateOf(true) }
PullToRefreshBox(
isRefreshing = isRefreshing,
onRefresh = { viewModel.refresh { isRefreshing = it } },
state = pullToRefreshState,
) {
NestedScrollBannerLayout(
isExpanded = isBannerExpanded,
banner = { ratio, modifier ->
val animRatio by animateFloatAsState(ratio)
Box(Modifier.background(MaterialTheme.colorScheme.surfaceContainer)) {
AsyncImage(
model = crossfadeModel(banner),
contentDescription = null,
alpha = 1.2f * ratio - 0.2f,
alpha = 1.2f * animRatio - 0.2f,
modifier = modifier,
contentScale = ContentScale.Crop
)
Expand All @@ -212,12 +219,15 @@
topEnd = LocalPaddings.current.small,
)
)
.graphicsLayer { alpha = 1.5f * ratio - 0.5f },
.graphicsLayer { alpha = 1.5f * animRatio - 0.5f },
)
}
},
bannerElevatedContent = { ratio ->
val animRatio by animateFloatAsState(ratio)
SettingsAndMore(
isBannerExpanded = isBannerExpanded,
onBannerExpanded = { isBannerExpanded = !isBannerExpanded },
onNavigateToSettings = onNavigateToSettings,
logOut = { isLogOutDialogShown = true },
expanded = isDropdownExpanded,
Expand All @@ -230,7 +240,7 @@
bottom = LocalPaddings.current.large,
end = LocalPaddings.current.large
)
.padding(top = LocalPaddings.current.large * ratio)
.padding(top = LocalPaddings.current.large * animRatio)
)
},
content = {
Expand Down Expand Up @@ -341,6 +351,8 @@

@Composable
private fun SettingsAndMore(
isBannerExpanded: Boolean,
onBannerExpanded: () -> Unit,
onNavigateToSettings: (SettingsPage) -> Unit,
expanded: Boolean,
setExpanded: (Boolean) -> Unit,
Expand All @@ -358,6 +370,8 @@
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
) {
BannerHeightToggle(isBannerExpanded, onBannerExpanded)

SettingsIcon(onNavigateToSettings = onNavigateToSettings)

Box {
Expand Down Expand Up @@ -447,6 +461,35 @@
}
}

@Composable
fun BannerHeightToggle(
isExpanded: Boolean,
onToggleBannerHeight: () -> Unit,
modifier: Modifier = Modifier
) {
val haptic = LocalHapticFeedback.current
val angle by animateFloatAsState(if (isExpanded) 0f else 180f)
Surface(
color = MaterialTheme.colorScheme.surfaceContainer,
shape = CircleShape,
modifier = modifier,
) {
Icon(
imageVector = ImageVector.vectorResource(R.drawable.banner_toggle),
contentDescription = null,
tint = MaterialTheme.colorScheme.primary,
modifier = Modifier
.clickable {
haptic.performHapticFeedback(HapticFeedbackType.ContextClick)
onToggleBannerHeight()
}
.padding(LocalPaddings.current.small)
.size(16.dp)
.graphicsLayer { rotationZ = angle }
)
}
}

@Composable
fun LogOutDialog(
logOut: () -> Unit,
Expand Down
24 changes: 24 additions & 0 deletions profile/src/main/res/drawable/banner_toggle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
~ Copyright (C) 2026 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M368,460h224q14,0 19,-12t-5,-22l-98,-98q-12,-12 -28,-12t-28,12l-98,98q-10,10 -5,22t19,12ZM200,840q-33,0 -56.5,-23.5T120,760v-560q0,-33 23.5,-56.5T200,120h560q33,0 56.5,23.5T840,200v560q0,33 -23.5,56.5T760,840L200,840ZM200,640v120h560v-120L200,640ZM200,560h560v-360L200,200v360ZM200,640v120,-120Z"
android:fillColor="#e3e3e3"/>
</vector>
Loading