-
Notifications
You must be signed in to change notification settings - Fork 5
/
AnimatedBottomNavigationBar.kt
140 lines (115 loc) · 4.76 KB
/
AnimatedBottomNavigationBar.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.example.myapplication
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import com.example.myapplication.ui.theme.MyApplicationTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
ContentListingDemo()
}
}
}
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@Preview(
showBackground = true, device = "id:pixel_7_pro", showSystemUi = true, name = "First View"
)
@Composable
private fun ContentListingDemo() {
val mContext = LocalContext.current
var selectedItem by remember {
mutableStateOf(0)
}
val manuIcons = listOf(
R.drawable.baseline_home_24,
R.drawable.baseline_favorite_24,
R.drawable.baseline_trending_up_24,
R.drawable.baseline_account_circle_24
)
val menuTitle = listOf(
"Home",
"Favorite",
"Explore",
"Profile"
)
Scaffold(
topBar = {
BasicTopAppBar(title = "Listing Demo")
},
content = { innerpadding ->
Column(modifier = Modifier.padding(innerpadding)) {
LazyColumn {
val listingData = IncludeContent.getListHomeData(mContext)
items(listingData.size) {
val items = listingData[it]
//ui
Row(
Modifier
.padding(vertical = 10.dp, horizontal = 8.dp)
.clickable { }, verticalAlignment = Alignment.CenterVertically
) {
Spacer(modifier = Modifier.width(10.dp))
Image(
painter = painterResource(id = items.image),
contentDescription = "",
contentScale = ContentScale.Crop,
modifier = Modifier.size(50.dp)
)
Spacer(modifier = Modifier.width(18.dp))
Text(
text = items.title,
style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.W500)
)
Spacer(modifier = Modifier.weight(1f))
IconButton(onClick = { /*TODO*/ }) {
Icon(Icons.Default.MoreVert, contentDescription = "menu")
}
}
Divider(color = MaterialTheme.colorScheme.outlineVariant)
}
}
}
},
bottomBar = {
NavigationBar {
manuIcons.forEachIndexed { index, icon ->
NavigationBarItem(selected = selectedItem == index,
onClick = { selectedItem = index },
icon = {
Icon(
imageVector = ImageVector.vectorResource(icon),
contentDescription = ""
)
},
label = if (selectedItem == index) {
{ Text(text = menuTitle[index]) }
} else {
null
}
)
}
}
}
)
}
}