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

Development #329

Merged
merged 2 commits into from
Jan 14, 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
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {

defaultConfig {
applicationId = "com.joeloewi.croissant"
versionCode = 51
versionName = "1.2.2"
versionCode = 52
versionName = "1.2.3"
targetSdk = 34

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
100 changes: 50 additions & 50 deletions app/src/main/kotlin/com/joeloewi/croissant/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import com.joeloewi.croissant.ui.theme.CroissantTheme
import com.joeloewi.croissant.util.LocalActivity
import com.joeloewi.croissant.util.LocalHourFormat
import com.joeloewi.croissant.util.RequireAppUpdate
import com.joeloewi.croissant.util.isCompactWindowSize
import com.joeloewi.croissant.util.useNavRail
import com.joeloewi.croissant.viewmodel.MainActivityViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.collections.immutable.ImmutableList
Expand Down Expand Up @@ -186,6 +186,29 @@ fun CroissantApp(
CroissantNavigation.Settings
).toImmutableList()
}
val currentBackStackEntry by remember(navController) {
navController.currentBackStackEntryFlow
}.collectAsStateWithLifecycle(initialValue = null)
val isNavigationRailVisible by remember {
derivedStateOf {
!fullScreenDestinations.any { route ->
(currentBackStackEntry?.destination?.route?.contains(
route
) != false)
} && windowSizeClass.useNavRail()
&& currentBackStackEntry?.destination?.route == currentBackStackEntry?.destination?.parent?.startDestinationRoute
}
}
val isBottomNavigationBarVisible by remember {
derivedStateOf {
!fullScreenDestinations.any { route ->
(currentBackStackEntry?.destination?.route?.contains(
route
) != false)
} && !windowSizeClass.useNavRail()
&& currentBackStackEntry?.destination?.route == currentBackStackEntry?.destination?.parent?.startDestinationRoute
}
}

LaunchedEffect(navController) {
withContext(Dispatchers.IO + CoroutineExceptionHandler { _, _ -> }) {
Expand All @@ -204,20 +227,6 @@ fun CroissantApp(
Scaffold(
contentWindowInsets = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal),
bottomBar = {
val currentBackStackEntry by remember(navController) {
navController.currentBackStackEntryFlow
}.collectAsStateWithLifecycle(initialValue = null)
val isBottomNavigationBarVisible by remember {
derivedStateOf {
!fullScreenDestinations.any { route ->
(currentBackStackEntry?.destination?.route?.contains(
route
) != false)
} && windowSizeClass.isCompactWindowSize()
&& currentBackStackEntry?.destination?.route == currentBackStackEntry?.destination?.parent?.startDestinationRoute
}
}

if (isBottomNavigationBarVisible) {
CroissantBottomNavigationBar(
croissantNavigations = croissantNavigations,
Expand All @@ -241,45 +250,36 @@ fun CroissantApp(
.padding(innerPadding)
) {
Row {
Column {
val currentBackStackEntry by navController.currentBackStackEntryFlow.collectAsStateWithLifecycle(
initialValue = null,
)
val isNavigationRailVisible by remember {
derivedStateOf {
!fullScreenDestinations.any { route ->
(currentBackStackEntry?.destination?.route?.contains(
route
) != false)
} && !windowSizeClass.isCompactWindowSize()
if (isNavigationRailVisible) {
CroissantNavigationRail(
croissantNavigations = croissantNavigations,
currentBackStackEntry = { currentBackStackEntry },
onClickNavigationButton = { route ->
navController.navigate(route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
}

if (isNavigationRailVisible) {
CroissantNavigationRail(
croissantNavigations = croissantNavigations,
currentBackStackEntry = { currentBackStackEntry },
onClickNavigationButton = { route ->
navController.navigate(route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
)
}
Column(
modifier = remember(isNavigationRailVisible) {
Modifier
.fillMaxSize(1f)
.run {
if (isNavigationRailVisible) {
navigationBarsPadding()
} else {
this
}
}
)
}
}
Column {
) {
CroissantNavHost(
modifier = Modifier.run {
if (windowSizeClass.isCompactWindowSize()) {
this
} else {
navigationBarsPadding()
}
},
modifier = Modifier.fillMaxSize(1f),
navController = StableWrapper(navController),
snackbarHostState = snackbarHostState,
deepLinkUri = deepLinkUri.toString()
Expand Down Expand Up @@ -594,7 +594,7 @@ private fun CroissantNavigationRail(
)
}
) {
croissantNavigations.forEach { croissantNavigation ->
croissantNavigations.fastForEach { croissantNavigation ->
key(croissantNavigation.route) {
val isSelected by remember(croissantNavigation.route) {
derivedStateOf { currentBackStackEntry()?.destination?.hierarchy?.any { it.route == croissantNavigation.route } == true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ import com.joeloewi.croissant.ui.theme.successContainerColor
import com.joeloewi.croissant.ui.theme.warningContainerColor
import com.joeloewi.croissant.util.LocalActivity
import com.joeloewi.croissant.util.generateCalendarDays
import com.joeloewi.croissant.util.isCompactWindowSize
import com.joeloewi.croissant.util.navigationIconButton
import com.joeloewi.croissant.util.useNavRail
import com.joeloewi.croissant.viewmodel.AttendanceLogsCalendarViewModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -316,7 +316,7 @@ private fun DayGridItem(
.padding(1.dp)
.fillMaxWidth()
.aspectRatio(
if (windowSizeClass.isCompactWindowSize()) {
if (!windowSizeClass.useNavRail()) {
0.5f
} else {
1f
Expand Down
Loading