android: remove TopAppBar scroll out behaviour

I'm not a fan of this behaviour.

This fully reverts commit 0ce95ef770 and partially reverts commit 0db4e48613.
This commit is contained in:
Harsh Shandilya 2022-02-24 01:18:42 +05:30
parent 31e30406ba
commit 2f60aa0ae0
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 10 additions and 35 deletions

View file

@ -2,30 +2,20 @@ package dev.msfjarvis.claw.android.ui
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
@ -66,7 +56,6 @@ fun LobstersApp(
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
val postActions = rememberPostActions(urlLauncher, navController, viewModel) val postActions = rememberPostActions(urlLauncher, navController, viewModel)
val currentDestination by currentNavigationDestination(navController) val currentDestination by currentNavigationDestination(navController)
val scrollBehavior = remember { TopAppBarDefaults.enterAlwaysScrollBehavior() }
val networkPosts = viewModel.pagerFlow.collectAsLazyPagingItems() val networkPosts = viewModel.pagerFlow.collectAsLazyPagingItems()
val savedPosts by viewModel.savedPosts.collectAsState(emptyList()) val savedPosts by viewModel.savedPosts.collectAsState(emptyList())
@ -108,27 +97,10 @@ fun LobstersApp(
} }
Scaffold( Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = { topBar = {
ClawAppBar( ClawAppBar(
modifier = Modifier.statusBarsPadding(), modifier = Modifier.statusBarsPadding(),
backgroundColor = systemBarsColor, backgroundColor = systemBarsColor,
scrollBehavior = scrollBehavior,
navigationIcon = {
if (navItems.none { it.route == currentDestination }) {
IconButton(onClick = { navController.popBackStack() }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Go back to previous screen"
)
}
}
},
title = {
if (navItems.any { it.route == currentDestination }) {
Text(text = stringResource(R.string.app_name), fontWeight = FontWeight.Bold)
}
}
) )
}, },
bottomBar = { bottomBar = {

View file

@ -1,25 +1,28 @@
package dev.msfjarvis.claw.android.ui.decorations package dev.msfjarvis.claw.android.ui.decorations
import androidx.compose.material3.SmallTopAppBar import androidx.compose.material3.SmallTopAppBar
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import dev.msfjarvis.claw.android.R
@Composable @Composable
fun ClawAppBar( fun ClawAppBar(
backgroundColor: Color, backgroundColor: Color,
scrollBehavior: TopAppBarScrollBehavior? = null,
navigationIcon: @Composable () -> Unit = {},
title: @Composable () -> Unit = {},
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
SmallTopAppBar( SmallTopAppBar(
title = title, title = {
Text(
text = stringResource(R.string.app_name),
fontWeight = FontWeight.Bold,
)
},
modifier = modifier, modifier = modifier,
colors = TopAppBarDefaults.smallTopAppBarColors(containerColor = backgroundColor), colors = TopAppBarDefaults.smallTopAppBarColors(containerColor = backgroundColor),
scrollBehavior = scrollBehavior,
navigationIcon = navigationIcon
) )
} }