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

Improved Adaptive Navigation in RYScaffold #877

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ dependencies {
implementation(libs.activity.compose)
implementation(libs.appcompat)

// Adaptive Navigation Suite
implementation(libs.androidx.compose.material3.adaptive.navigation.suite)
implementation(libs.androidx.compose.material3.adaptive.navigation)

// Testing
testImplementation(libs.junit)
androidTestImplementation(libs.junit.ext)
Expand Down
74 changes: 24 additions & 50 deletions app/src/main/java/me/ash/reader/ui/component/FilterBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ package me.ash.reader.ui.component
import android.os.Build
import android.view.SoundEffectConstants
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.material3.*
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffoldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
Expand Down Expand Up @@ -46,35 +42,24 @@ fun FilterBar(
MaterialTheme.colorScheme.primaryContainer
} onDark MaterialTheme.colorScheme.secondaryContainer

val layoutType = NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(
currentWindowAdaptiveInfo()
)

val containerHeight = when (filterBarStyle) {
FlowFilterBarStylePreference.Icon.value -> 64.dp
else -> 80.dp
}

Surface(
color = MaterialTheme.colorScheme.surfaceColorAtElevation(filterBarTonalElevation),
modifier = modifier
) {
Row(
modifier =
Modifier
.fillMaxWidth()
.windowInsetsPadding(NavigationBarDefaults.windowInsets)
.defaultMinSize(minHeight = containerHeight)
.selectableGroup(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {

Spacer(modifier = Modifier.width(filterBarPadding))
NavigationSuiteScaffold(
modifier = modifier.background(MaterialTheme.colorScheme.surfaceColorAtElevation(filterBarTonalElevation)),
navigationSuiteItems = {
Filter.values.forEach { item ->
NavigationBarItem(
modifier = Modifier.height(containerHeight),
alwaysShowLabel = when (filterBarStyle) {
FlowFilterBarStylePreference.Icon.value -> false
FlowFilterBarStylePreference.IconLabel.value -> true
FlowFilterBarStylePreference.IconLabelOnlySelected.value -> false
else -> false
item(
selected = filter == item,
onClick = {
view.playSoundEffect(SoundEffectConstants.CLICK)
filterOnClick(item)
},
icon = {
Icon(
Expand All @@ -92,28 +77,17 @@ fun FilterBar(
{
Text(
text = item.toName(),
// style = MaterialTheme.typography.labelLarge,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
},
selected = filter == item,
onClick = {
// view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
view.playSoundEffect(SoundEffectConstants.CLICK)
filterOnClick(item)
},
colors = NavigationBarItemDefaults.colors(
indicatorColor = indicatorColor,
unselectedIconColor = MaterialTheme.colorScheme.onSurfaceVariant,
selectedIconColor = MaterialTheme.colorScheme.contentColorFor(indicatorColor),
unselectedTextColor = MaterialTheme.colorScheme.onSurfaceVariant,
selectedTextColor = MaterialTheme.colorScheme.onSurface
)
}
)
}
Spacer(modifier = Modifier.width(filterBarPadding))
}
},
layoutType = layoutType,
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(filterBarTonalElevation),
) {
Spacer(modifier = Modifier.defaultMinSize(minHeight = containerHeight).navigationBarsPadding())
}
}
133 changes: 95 additions & 38 deletions app/src/main/java/me/ash/reader/ui/component/base/RYScaffold.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package me.ash.reader.ui.component.base

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffoldDefaults
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
Expand All @@ -24,43 +26,98 @@ fun RYScaffold(
navigationIcon: (@Composable () -> Unit)? = null,
actions: (@Composable RowScope.() -> Unit)? = null,
topBar: (@Composable () -> Unit)? = null,
bottomBar: (@Composable () -> Unit)? = null,
floatingActionButton: (@Composable () -> Unit)? = null,
navigationSuiteItems: (NavigationSuiteScope.() -> Unit)? = null,
content: @Composable () -> Unit = {},
) {
Scaffold(
modifier = modifier
.background(
MaterialTheme.colorScheme.surfaceColorAtElevation(
topBarTonalElevation,
color = containerColor
)
),
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
containerTonalElevation,
color = containerColor
) onDark MaterialTheme.colorScheme.surface,
topBar = {
if (topBar != null) topBar() else if (navigationIcon != null || actions != null) {
TopAppBar(
title = {},
navigationIcon = { navigationIcon?.invoke() },
actions = { actions?.invoke(this) },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
topBarTonalElevation
),
val layoutType = NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(
currentWindowAdaptiveInfo()
)

if (navigationSuiteItems != null) {
NavigationSuiteScaffold(
modifier = modifier
.background(
MaterialTheme.colorScheme.surfaceColorAtElevation(
topBarTonalElevation,
color = containerColor
)
)
),
layoutType = layoutType,
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
containerTonalElevation,
color = containerColor
) onDark MaterialTheme.colorScheme.surface,
navigationSuiteItems = navigationSuiteItems,
content = {
Column {
if (topBar != null) {
topBar()
} else if (navigationIcon != null || actions != null) {
TopAppBar(
title = {},
navigationIcon = { navigationIcon?.invoke() },
actions = { actions?.invoke(this) },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
topBarTonalElevation
),
)
)
}
content()
if (floatingActionButton != null) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.BottomEnd
) {
floatingActionButton()
}
}
}
}
},
content = {
Column {
Spacer(modifier = Modifier.height(it.calculateTopPadding()))
content()
}
},
bottomBar = { bottomBar?.invoke() },
floatingActionButton = { floatingActionButton?.invoke() },
)
)
} else {
Scaffold(
modifier = modifier
.background(
MaterialTheme.colorScheme.surfaceColorAtElevation(
topBarTonalElevation,
color = containerColor
)
),
topBar = {
if (topBar != null) {
topBar()
} else if (navigationIcon != null || actions != null) {
TopAppBar(
title = {},
navigationIcon = { navigationIcon?.invoke() },
actions = { actions?.invoke(this) },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
topBarTonalElevation
),
)
)
}
},
floatingActionButton = {
if (floatingActionButton != null) {
floatingActionButton()
}
},
content = {
Column {
Spacer(modifier = Modifier.height(it.calculateTopPadding()))
content()
}
},
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
containerTonalElevation,
color = containerColor
) onDark MaterialTheme.colorScheme.surface
)
}
}

67 changes: 40 additions & 27 deletions app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.KeyboardArrowRight
Expand All @@ -27,13 +26,13 @@ import androidx.compose.material.icons.rounded.UnfoldLess
import androidx.compose.material.icons.rounded.UnfoldMore
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilledTonalIconButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
Expand All @@ -49,26 +48,19 @@ import androidx.compose.runtime.snapshotFlow
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.window.core.layout.WindowWidthSizeClass
import androidx.work.WorkInfo
import kotlinx.coroutines.launch
import me.ash.reader.R
import me.ash.reader.infrastructure.preference.LocalFeedsFilterBarFilled
import me.ash.reader.infrastructure.preference.LocalFeedsFilterBarPadding
import me.ash.reader.infrastructure.preference.LocalFeedsFilterBarStyle
import me.ash.reader.infrastructure.preference.LocalFeedsFilterBarTonalElevation
import me.ash.reader.infrastructure.preference.LocalFeedsGroupListExpand
import me.ash.reader.infrastructure.preference.LocalFeedsGroupListTonalElevation
import me.ash.reader.infrastructure.preference.LocalFeedsTopBarTonalElevation
import me.ash.reader.infrastructure.preference.LocalNewVersionNumber
import me.ash.reader.infrastructure.preference.LocalSkipVersionNumber
import me.ash.reader.ui.component.FilterBar
import me.ash.reader.domain.model.general.Filter
import me.ash.reader.infrastructure.preference.*
import me.ash.reader.ui.component.base.Banner
import me.ash.reader.ui.component.base.DisplayText
import me.ash.reader.ui.component.base.FeedbackIconButton
Expand Down Expand Up @@ -103,6 +95,7 @@ fun FeedsPage(
subscribeViewModel: SubscribeViewModel = hiltViewModel(),
homeViewModel: HomeViewModel,
) {

var accountTabVisible by remember { mutableStateOf(false) }

val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -412,22 +405,42 @@ fun FeedsPage(
}
}
},
bottomBar = {
FilterBar(
filter = filterUiState.filter,
filterBarStyle = filterBarStyle.value,
filterBarFilled = filterBarFilled.value,
filterBarPadding = filterBarPadding.dp,
filterBarTonalElevation = filterBarTonalElevation.value.dp,
) {
filterChange(
navController = navController,
homeViewModel = homeViewModel,
filterState = filterUiState.copy(filter = it),
isNavigate = false,
navigationSuiteItems = {
Filter.values.forEach { item ->
item(
selected = filterUiState.filter == item,
onClick = {
filterChange(
navController = navController,
homeViewModel = homeViewModel,
filterState = filterUiState.copy(filter = item),
isNavigate = false,
)
},
icon = {
Icon(
imageVector = if (filterUiState.filter == item && filterBarFilled.value) {
item.iconFilled
} else {
item.iconOutline
},
contentDescription = item.toName()
)
},
label = if (filterBarStyle.value == FlowFilterBarStylePreference.Icon.value) {
null
} else {
{
Text(
text = item.toName(),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
)
}
}
},
)

SubscribeDialog(subscribeViewModel = subscribeViewModel)
Expand Down
Loading
Loading