-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #179.
- Loading branch information
Showing
11 changed files
with
391 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.adammcneilly.toa | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.material3.PermanentNavigationDrawer | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.adammcneilly.toa.core.ui.components.navigation.NavigationType | ||
|
||
@Composable | ||
fun TOAAppScaffold( | ||
navigationType: NavigationType, | ||
navigationContent: @Composable () -> Unit, | ||
appContent: @Composable () -> Unit, | ||
) { | ||
when (navigationType) { | ||
NavigationType.BOTTOM_NAVIGATION -> { | ||
VerticalAppScaffold( | ||
navigationContent = navigationContent, | ||
appContent = appContent, | ||
) | ||
} | ||
NavigationType.NAVIGATION_RAIL -> { | ||
HorizontalAppScaffold( | ||
navigationContent = navigationContent, | ||
appContent = appContent, | ||
) | ||
} | ||
NavigationType.PERMANENT_NAVIGATION_DRAWER -> { | ||
PermanentNavigationScaffold( | ||
navigationContent = navigationContent, | ||
appContent = appContent, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun HorizontalAppScaffold( | ||
navigationContent: @Composable () -> Unit, | ||
appContent: @Composable () -> Unit, | ||
) { | ||
Row { | ||
navigationContent() | ||
|
||
Box( | ||
modifier = Modifier | ||
.weight(1F), | ||
) { | ||
appContent() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun VerticalAppScaffold( | ||
navigationContent: @Composable () -> Unit, | ||
appContent: @Composable () -> Unit, | ||
) { | ||
Column { | ||
Box( | ||
modifier = Modifier | ||
.weight(1F), | ||
) { | ||
appContent() | ||
} | ||
|
||
navigationContent() | ||
} | ||
} | ||
|
||
@Composable | ||
private fun PermanentNavigationScaffold( | ||
navigationContent: @Composable () -> Unit, | ||
appContent: @Composable () -> Unit, | ||
) { | ||
PermanentNavigationDrawer( | ||
drawerContent = { | ||
navigationContent() | ||
}, | ||
content = { | ||
appContent() | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/adammcneilly/toa/core/ui/components/navigation/NavigationType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.adammcneilly.toa.core.ui.components.navigation | ||
|
||
enum class NavigationType { | ||
BOTTOM_NAVIGATION, | ||
NAVIGATION_RAIL, | ||
PERMANENT_NAVIGATION_DRAWER, | ||
} |
61 changes: 20 additions & 41 deletions
61
app/src/main/java/com/adammcneilly/toa/core/ui/components/navigation/TOABottomNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,39 @@ | ||
package com.adammcneilly.toa.core.ui.components.navigation | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.animation.expandVertically | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.compose.animation.shrinkVertically | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.NavigationBar | ||
import androidx.compose.material3.NavigationBarItem | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.navigation.NavHostController | ||
import com.ramcosta.composedestinations.utils.currentDestinationAsState | ||
|
||
@Composable | ||
fun TOABottomNavigation( | ||
navHostController: NavHostController, | ||
tabs: List<NavigationTab>, | ||
navigationConfig: TOANavigationConfig, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val currentRoute = navHostController.currentDestinationAsState().value?.route | ||
|
||
val shouldShowBottomBar = tabs.any { tab -> | ||
tab.screenRoute == currentRoute | ||
} | ||
|
||
AnimatedVisibility( | ||
visible = shouldShowBottomBar, | ||
NavigationBar( | ||
modifier = modifier, | ||
enter = fadeIn() + expandVertically(), | ||
exit = fadeOut() + shrinkVertically(), | ||
) { | ||
NavigationBar { | ||
tabs.forEach { tab -> | ||
NavigationBarItem( | ||
selected = tab.screenRoute == currentRoute, | ||
onClick = { | ||
if (tab.screenRoute != currentRoute) { | ||
navHostController.navigate(tab.screenRoute) | ||
} | ||
}, | ||
icon = { | ||
Icon( | ||
imageVector = tab.icon, | ||
contentDescription = stringResource(id = tab.labelTextRes), | ||
) | ||
}, | ||
label = { | ||
Text( | ||
text = stringResource(id = tab.labelTextRes), | ||
) | ||
}, | ||
) | ||
} | ||
navigationConfig.tabs.forEach { tab -> | ||
NavigationBarItem( | ||
selected = tab == navigationConfig.selectedTab, | ||
onClick = { | ||
navigationConfig.onTabClicked.invoke(tab) | ||
}, | ||
icon = { | ||
Icon( | ||
imageVector = tab.icon, | ||
contentDescription = stringResource(id = tab.labelTextRes), | ||
) | ||
}, | ||
label = { | ||
Text( | ||
text = stringResource(id = tab.labelTextRes), | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/adammcneilly/toa/core/ui/components/navigation/TOANavigationConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.adammcneilly.toa.core.ui.components.navigation | ||
|
||
/** | ||
* All forms of navigation within the TOA app share the same | ||
* core functionality of showing some [NavigationTab] entities and | ||
* handling their click events. | ||
*/ | ||
data class TOANavigationConfig( | ||
val tabs: List<NavigationTab>, | ||
val selectedTab: NavigationTab?, | ||
val onTabClicked: (NavigationTab) -> Unit, | ||
) |
Oops, something went wrong.