Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add : add Medium TopBar #753

Merged
merged 7 commits into from
Sep 2, 2024
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
@@ -0,0 +1,108 @@
package io.github.droidkaigi.confsched.droidkaigiui.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.fadeIn
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons.AutoMirrored.Filled
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MediumTopAppBar
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarColors
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
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.draw.alpha
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AnimatedMediumTopAppBar(
title: String,
onBackClick: () -> Unit,
navIconContentDescription: String?,
modifier: Modifier = Modifier,
actions: @Composable RowScope.() -> Unit = {},
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
colors: TopAppBarColors = TopAppBarDefaults.largeTopAppBarColors().copy(
scrolledContainerColor = MaterialTheme.colorScheme.surfaceContainer,
),
scrollBehavior: TopAppBarScrollBehavior? = null,
) {
val density = LocalDensity.current.density
var navigationIconWidthDp by remember { mutableStateOf(0f) }
val isCenterTitle = remember(scrollBehavior?.state?.collapsedFraction) {
if (scrollBehavior == null) {
// Always left-align when scrollBehavior is not present
false
} else {
// Hide title position because it doesn't look smooth if it is displayed when collapsing
when (scrollBehavior.state.collapsedFraction) {
in 0.7f..1.0f -> true
in 0.0f..0.5f -> false
else -> null // Don't display while on the move.
}
}
}

MediumTopAppBar(
title = {
AnimatedVisibility(
visible = isCenterTitle != null,
enter = fadeIn(),
// No animation required as it is erased with alpha
exit = ExitTransition.None,
) {
Text(
text = title,
modifier = Modifier.then(
when (isCenterTitle) {
true -> {
Modifier
.padding(end = navigationIconWidthDp.dp)
.fillMaxWidth()
}
false -> Modifier
null -> Modifier.alpha(0f)
},
),
textAlign = TextAlign.Center,
)
}
},
modifier = modifier,
navigationIcon = {
IconButton(
modifier = Modifier
.onGloballyPositioned {
navigationIconWidthDp = it.size.width / density
},
onClick = onBackClick,
) {
Icon(
imageVector = Filled.ArrowBack,
contentDescription = navIconContentDescription,
)
}
},
actions = actions,
windowInsets = windowInsets,
colors = colors,
scrollBehavior = scrollBehavior,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ class SponsorsScreenRobot @Inject constructor(
)
}

fun scrollBottom() {
composeTestRule
.onNode(hasTestTag(SponsorsListLazyVerticalGridTestTag))
.performScrollToNode(
hasTestTag(SponsorsListSponsorItemTestTagPrefix.plus(Sponsor.fakes().last().name)),
)
}

fun checkDisplayPlatinumSponsors() {
checkSponsorItemsDisplayedByRangeAndSponsorType(
sponsorType = SponsorType.Platinum,
Expand All @@ -92,7 +100,8 @@ class SponsorsScreenRobot @Inject constructor(
sponsorType: SponsorType,
fromTo: IntRange,
) {
val sponsorList = Sponsor.fakes().filter { it.plan.toSponsorType() == sponsorType }.subList(fromTo.first, fromTo.last)
val sponsorList = Sponsor.fakes().filter { it.plan.toSponsorType() == sponsorType }
.subList(fromTo.first, fromTo.last)
sponsorList.forEach { sponsor ->
composeTestRule
.onNode(hasTestTag(SponsorsListSponsorItemTestTagPrefix.plus(sponsor.name)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import io.github.droidkaigi.confsched.compose.rememberEventFlow
import io.github.droidkaigi.confsched.contributors.component.ContributorsItem
import io.github.droidkaigi.confsched.droidkaigiui.SnackbarMessageEffect
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageStateHolder
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedLargeTopAppBar
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedMediumTopAppBar
import io.github.droidkaigi.confsched.model.Contributor
import kotlinx.collections.immutable.PersistentList
import org.jetbrains.compose.resources.stringResource
Expand Down Expand Up @@ -100,7 +100,7 @@ fun ContributorsScreen(
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
topBar = {
if (!isTopAppBarHidden) {
AnimatedLargeTopAppBar(
AnimatedMediumTopAppBar(
title = stringResource(ContributorsRes.string.contributor_title),
onBackClick = onBackClick,
scrollBehavior = scrollBehavior,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,9 @@ internal fun CardScreen(
text = stringResource(ProfileCardRes.string.edit),
modifier = Modifier.padding(8.dp),
style = MaterialTheme.typography.labelLarge,
color = Color.Black
color = Color.Black,
)
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched.droidkaigiui.SnackbarMessageEffect
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageStateHolder
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageStateHolderImpl
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedLargeTopAppBar
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedMediumTopAppBar
import io.github.droidkaigi.confsched.droidkaigiui.plus
import io.github.droidkaigi.confsched.model.FontFamily
import io.github.droidkaigi.confsched.settings.section.accessibility
Expand Down Expand Up @@ -96,7 +96,7 @@ fun SettingsScreen(
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
topBar = {
if (!isTopAppBarHidden) {
AnimatedLargeTopAppBar(
AnimatedMediumTopAppBar(
title = stringResource(SettingsRes.string.settings_title),
onBackClick = onBackClick,
scrollBehavior = scrollBehavior,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class SponsorsScreenTest(
}
}

describe("when scroll to supporters header") {
describe("when scroll to scroll Bottom") {
doIt {
scrollToSupportersSponsorsHeader()
scrollBottom()
}
itShould("display supporters sponsors") {
captureScreenWithChecks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched.droidkaigiui.SnackbarMessageEffect
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageStateHolder
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageStateHolderImpl
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedLargeTopAppBar
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedMediumTopAppBar
import io.github.droidkaigi.confsched.model.Plan.GOLD
import io.github.droidkaigi.confsched.model.Plan.PLATINUM
import io.github.droidkaigi.confsched.model.Plan.SUPPORTER
Expand Down Expand Up @@ -106,7 +106,7 @@ fun SponsorsScreen(
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
topBar = {
if (!isTopAppBarHidden) {
AnimatedLargeTopAppBar(
AnimatedMediumTopAppBar(
title = stringResource(SponsorsRes.string.sponsor),
onBackClick = onBackClick,
scrollBehavior = scrollBehavior,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.github.droidkaigi.confsched.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched.droidkaigiui.SnackbarMessageEffect
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageStateHolder
import io.github.droidkaigi.confsched.droidkaigiui.UserMessageStateHolderImpl
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedLargeTopAppBar
import io.github.droidkaigi.confsched.droidkaigiui.component.AnimatedMediumTopAppBar
import io.github.droidkaigi.confsched.model.Staff
import io.github.droidkaigi.confsched.model.fakes
import io.github.droidkaigi.confsched.staff.component.StaffItem
Expand Down Expand Up @@ -103,7 +103,7 @@ fun StaffScreen(
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
topBar = {
if (!isTopAppBarHidden) {
AnimatedLargeTopAppBar(
AnimatedMediumTopAppBar(
title = stringResource(StaffRes.string.staff_title),
onBackClick = onBackClick,
scrollBehavior = scrollBehavior,
Expand Down
Loading