Skip to content

Instantly share code, notes, and snippets.

View Besong's full-sized avatar
💭
I may be slow to respond.

Besong-Anong Ernest Egbenchong II Besong

💭
I may be slow to respond.
View GitHub Profile
@Besong
Besong / BottomNavigationComponent.kt
Created March 11, 2025 02:39
Manage the selectedItem value with rememberSaveable
@Composable
private fun BottomNavigationComponent(
modifier: Modifier = Modifier
) {
// // Keep track of selected NavigationItem during recomposition and configuration changes
val selectedItem = rememberSaveable { mutableStateOf(0) }
val items = listOf(
NavigationItem(0, navigationIcon = NavigationIcon(unselectedVectorResourceId = R.drawable.nav_home, selectedVectorResourceId = R.drawable.nav_home_2),
@Composable
private fun RowScope.BottomNavigationItem(
selected: Boolean,
@DrawableRes vectorResourceId: Int,
onNavItemClicked: () -> Unit = {}
) {
NavigationBarItem(
icon = {
Icon(
imageVector = ImageVector.vectorResource(id = vectorResourceId),
@Besong
Besong / BottomNavigationComponent.kt
Last active March 8, 2025 18:44
Manage the selectedItem value with remember & mutableStateOf
@Composable
private fun BottomNavigationComponent(
modifier: Modifier = Modifier
) {
// Keep track of selected NavigationItem during recomposition
val selectedItem = remember { mutableStateOf(0) }
val items = listOf(
NavigationItem(0, navigationIcon = NavigationIcon(unselectedVectorResourceId = R.drawable.nav_home, selectedVectorResourceId = R.drawable.nav_home_2),
@Besong
Besong / BottomNavigationComponent.kt
Last active March 8, 2025 18:44
No state management for selectedItem value
@Composable
private fun BottomNavigationComponent(
modifier: Modifier = Modifier
) {
var selectedItem = 0 // Value to keep track of the selected NavigationItem
val items = listOf(
NavigationItem(0, navigationIcon = NavigationIcon(unselectedVectorResourceId = R.drawable.nav_home, selectedVectorResourceId = R.drawable.nav_home_2),
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
GoogleFontsIntoM3Theme { // GoogleFontsIntoM3Theme is my project's theme
Greeting("World")
}
}
Text(
text = "Hello, $name!",
modifier = modifier,
style = MaterialTheme.typography.displayLarge
)
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Column(modifier = modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = "Hello, $name!",
modifier = modifier
)
val Typography = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
),
displayLarge = TextStyle(
displayLarge = TextStyle(
fontFamily = FontFamily(Font(R.font.montserrat_semibold)),
fontWeight = FontWeight.SemiBold,
lineHeight = 23.sp,
fontSize = 30.sp,
letterSpacing = 2.sp
)
val Typography = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
)
/* Other default text styles to override