[wip] chat materials; some experiments with local composition and blur
This commit is contained in:
@@ -9,6 +9,7 @@ import androidx.compose.animation.slideOut
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
@@ -16,19 +17,23 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarDefaults
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
@@ -36,9 +41,16 @@ import androidx.navigation.compose.navigation
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.meloda.app.fast.conversations.navigation.Conversations
|
||||
import com.meloda.app.fast.conversations.navigation.conversationsRoute
|
||||
import com.meloda.app.fast.designsystem.LocalBottomPadding
|
||||
import com.meloda.app.fast.designsystem.LocalHazeState
|
||||
import com.meloda.app.fast.designsystem.LocalTheme
|
||||
import com.meloda.app.fast.friends.navigation.Friends
|
||||
import com.meloda.app.fast.friends.navigation.friendsRoute
|
||||
import com.meloda.app.fast.model.BaseError
|
||||
import dev.chrisbanes.haze.HazeState
|
||||
import dev.chrisbanes.haze.hazeChild
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||
import kotlinx.serialization.Serializable
|
||||
import com.meloda.app.fast.designsystem.R as UiR
|
||||
|
||||
@@ -58,7 +70,7 @@ data class BottomNavigationItem(
|
||||
val route: Any,
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalHazeMaterialsApi::class)
|
||||
fun NavGraphBuilder.mainScreen(
|
||||
onError: (BaseError) -> Unit,
|
||||
onNavigateToSettings: () -> Unit,
|
||||
@@ -87,6 +99,8 @@ fun NavGraphBuilder.mainScreen(
|
||||
val routes = items.map(BottomNavigationItem::route)
|
||||
|
||||
composable<Main> {
|
||||
val currentTheme = LocalTheme.current
|
||||
val hazeState = remember { HazeState() }
|
||||
val navController = rememberNavController()
|
||||
|
||||
var selectedItemIndex by rememberSaveable {
|
||||
@@ -104,7 +118,21 @@ fun NavGraphBuilder.mainScreen(
|
||||
enter = slideIn { IntOffset(0, 400) },
|
||||
exit = slideOut { IntOffset(0, 400) }
|
||||
) {
|
||||
NavigationBar {
|
||||
NavigationBar(
|
||||
modifier = Modifier
|
||||
.then(
|
||||
if (currentTheme.usingBlur) {
|
||||
Modifier.hazeChild(
|
||||
state = hazeState,
|
||||
style = HazeMaterials.thick()
|
||||
)
|
||||
} else Modifier
|
||||
)
|
||||
.fillMaxWidth(),
|
||||
containerColor = NavigationBarDefaults.containerColor.copy(
|
||||
alpha = if (currentTheme.usingBlur) 0f else 1f
|
||||
)
|
||||
) {
|
||||
items.forEachIndexed { index, item ->
|
||||
NavigationBarItem(
|
||||
selected = selectedItemIndex == index,
|
||||
@@ -139,52 +167,57 @@ fun NavGraphBuilder.mainScreen(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(bottom = padding.calculateBottomPadding())
|
||||
.padding(bottom = if (currentTheme.usingBlur) 0.dp else padding.calculateBottomPadding())
|
||||
) {
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = MainGraph,
|
||||
enterTransition = { fadeIn(animationSpec = tween(200)) },
|
||||
exitTransition = { fadeOut(animationSpec = tween(200)) }
|
||||
CompositionLocalProvider(
|
||||
LocalHazeState provides hazeState,
|
||||
LocalBottomPadding provides if (currentTheme.usingBlur) padding.calculateBottomPadding() else 0.dp
|
||||
) {
|
||||
navigation<MainGraph>(startDestination = Conversations) {
|
||||
friendsRoute(
|
||||
onError = onError,
|
||||
navController = navController
|
||||
)
|
||||
conversationsRoute(
|
||||
onError = onError,
|
||||
onNavigateToMessagesHistory = onNavigateToMessagesHistory,
|
||||
navController = navController,
|
||||
onListScrollingUp = { isScrolling ->
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = MainGraph,
|
||||
enterTransition = { fadeIn(animationSpec = tween(200)) },
|
||||
exitTransition = { fadeOut(animationSpec = tween(200)) }
|
||||
) {
|
||||
navigation<MainGraph>(startDestination = Conversations) {
|
||||
friendsRoute(
|
||||
onError = onError,
|
||||
navController = navController
|
||||
)
|
||||
conversationsRoute(
|
||||
onError = onError,
|
||||
onNavigateToMessagesHistory = onNavigateToMessagesHistory,
|
||||
navController = navController,
|
||||
onListScrollingUp = { isScrolling ->
|
||||
// isBottomBarVisible = isScrolling
|
||||
}
|
||||
)
|
||||
|
||||
composable<Profile> {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(text = stringResource(id = UiR.string.title_profile))
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = onNavigateToSettings) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Settings,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding)
|
||||
) {
|
||||
)
|
||||
|
||||
composable<Profile> {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(text = stringResource(id = UiR.string.title_profile))
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = onNavigateToSettings) {
|
||||
Icon(
|
||||
imageVector = Icons.Rounded.Settings,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(padding)
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.PowerManager
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.meloda.app.fast.MainViewModelImpl
|
||||
import com.meloda.app.fast.auth.authModule
|
||||
import com.meloda.app.fast.chatmaterials.di.chatMaterialsModule
|
||||
import com.meloda.app.fast.conversations.di.conversationsModule
|
||||
import com.meloda.app.fast.data.di.dataModule
|
||||
import com.meloda.app.fast.friends.di.friendsModule
|
||||
@@ -32,7 +33,8 @@ val applicationModule = module {
|
||||
languagePickerModule,
|
||||
longPollModule,
|
||||
friendsModule,
|
||||
profileModule
|
||||
profileModule,
|
||||
chatMaterialsModule
|
||||
)
|
||||
|
||||
// TODO: 14/05/2024, Danil Nikolaev: research on memory leaks and potentials errors
|
||||
|
||||
Reference in New Issue
Block a user