forked from microsoft/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathV2TabBarActivity.kt
240 lines (227 loc) · 11.1 KB
/
V2TabBarActivity.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.microsoft.fluentuidemo.demos
import android.os.Bundle
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material.icons.outlined.*
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.lifecycle.MutableLiveData
import com.microsoft.fluentui.theme.FluentTheme
import com.microsoft.fluentui.theme.ThemeMode
import com.microsoft.fluentui.theme.token.FluentAliasTokens
import com.microsoft.fluentui.theme.token.controlTokens.BadgeType
import com.microsoft.fluentui.theme.token.controlTokens.ButtonSize
import com.microsoft.fluentui.theme.token.controlTokens.ButtonStyle
import com.microsoft.fluentui.theme.token.controlTokens.TabTextAlignment
import com.microsoft.fluentui.tokenized.controls.Button
import com.microsoft.fluentui.tokenized.controls.RadioButton
import com.microsoft.fluentui.tokenized.listitem.ListItem
import com.microsoft.fluentui.tokenized.navigation.TabBar
import com.microsoft.fluentui.tokenized.navigation.TabData
import com.microsoft.fluentui.tokenized.notification.Badge
import com.microsoft.fluentuidemo.R
import com.microsoft.fluentuidemo.V2DemoActivity
import com.microsoft.fluentuidemo.util.invokeToast
const val TAB_BAR_VERTICAL_RADIO = "tabBarVerticalRadio"
const val TAB_BAR_HORIZONTAL_RADIO = "tabBarHorizontalRadio"
const val TAB_BAR_NO_TEXT_RADIO = "tabBarItemsNoTextRadio"
const val TAB_BAR_ADD_BUTTON = "tabBarAddButton"
const val TAB_BAR_REMOVE_BUTTON = "tabBarRemoveButton"
const val TAB_BAR = "tabBar"
class V2TabBarActivity : V2DemoActivity() {
init {
setupActivity(this)
}
override val paramsUrl = "https://github.com/microsoft/fluentui-android/wiki/Controls#params-37"
override val controlTokensUrl =
"https://github.com/microsoft/fluentui-android/wiki/Controls#control-tokens-35"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val context = this
val _tabTextAlignment: MutableLiveData<TabTextAlignment> =
MutableLiveData(TabTextAlignment.VERTICAL)
val _tabItemsCount: MutableLiveData<Int> = MutableLiveData(5)
setActivityContent {
val content = listOf(0, 1, 2)
var selectedOption by rememberSaveable { mutableStateOf(content[0]) }
val tabItemsCount = _tabItemsCount.observeAsState(initial = 5)
Column {
ListItem.Header(title = resources.getString(R.string.tabBar_text_alignment))
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
BasicText(
text = resources.getString(R.string.tabBar_vertical),
modifier = Modifier.weight(1F),
style = TextStyle(
color = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground3].value(
themeMode = ThemeMode.Auto
)
)
)
RadioButton(
modifier = Modifier.testTag(TAB_BAR_VERTICAL_RADIO),
selected = (selectedOption == content[0]),
onClick = {
selectedOption = content[0]
_tabTextAlignment.value = TabTextAlignment.VERTICAL
}
)
}
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
BasicText(
text = resources.getString(R.string.tabBar_horizontal),
modifier = Modifier.weight(1F),
style = TextStyle(
color = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground3].value(
themeMode = ThemeMode.Auto
)
)
)
RadioButton(
modifier = Modifier.testTag(TAB_BAR_HORIZONTAL_RADIO),
selected = (selectedOption == content[1]),
onClick = {
selectedOption = content[1]
_tabTextAlignment.value = TabTextAlignment.HORIZONTAL
}
)
}
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
BasicText(
text = resources.getString(R.string.tabBar_no_text),
modifier = Modifier.weight(1F),
style = TextStyle(
color = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground3].value(
themeMode = ThemeMode.Auto
)
)
)
RadioButton(
modifier = Modifier.testTag(TAB_BAR_NO_TEXT_RADIO),
selected = (selectedOption == content[2]),
onClick = {
selectedOption = content[2]
_tabTextAlignment.value = TabTextAlignment.NO_TEXT
}
)
}
}
ListItem.Header(title = resources.getString(R.string.tabBar_tab_items),
trailingAccessoryContent =
{
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Button(
modifier = Modifier.testTag(TAB_BAR_ADD_BUTTON),
style = ButtonStyle.Button,
size = ButtonSize.Medium,
text = "+",
enabled = tabItemsCount.value < 5,
onClick = { _tabItemsCount.value = tabItemsCount.value + 1 })
Button(
modifier = Modifier.testTag(TAB_BAR_REMOVE_BUTTON),
style = ButtonStyle.Button,
size = ButtonSize.Medium,
text = "-",
enabled = tabItemsCount.value > 1,
onClick = { _tabItemsCount.value = tabItemsCount.value - 1 }
)
}
}
)
}
}
setBottomBar {
var selectedIndex by rememberSaveable { mutableStateOf(0) }
var showHomeBadge by rememberSaveable { mutableStateOf(true) }
val tabTextAlignment =
_tabTextAlignment.observeAsState(initial = TabTextAlignment.VERTICAL)
val tabItemsCount = _tabItemsCount.observeAsState(initial = 5)
val tabDataList = arrayListOf(
TabData(
title = resources.getString(R.string.tabBar_home),
icon = Icons.Outlined.Home,
selectedIcon = Icons.Filled.Home,
onClick = {
invokeToast(resources.getString(R.string.tabBar_home), context)
selectedIndex = 0
showHomeBadge = false
},
badge = { if (selectedIndex == 0 && showHomeBadge) Badge() }
),
TabData(
title = resources.getString(R.string.tabBar_mail),
icon = Icons.Outlined.Email,
selectedIcon = Icons.Filled.Email,
onClick = {
invokeToast(resources.getString(R.string.tabBar_mail), context)
selectedIndex = 1
},
badge = { Badge(text = "123+", badgeType = BadgeType.Character) }
),
TabData(
title = resources.getString(R.string.tabBar_settings),
icon = Icons.Outlined.Settings,
selectedIcon = Icons.Filled.Settings,
onClick = {
invokeToast(resources.getString(R.string.tabBar_settings), context)
selectedIndex = 2
}
),
TabData(
title = resources.getString(R.string.tabBar_notification),
icon = Icons.Outlined.Notifications,
selectedIcon = Icons.Filled.Notifications,
onClick = {
invokeToast(resources.getString(R.string.tabBar_notification), context)
selectedIndex = 3
},
badge = { Badge(text = "10", badgeType = BadgeType.Character) }
),
TabData(
title = resources.getString(R.string.tabBar_more),
icon = Icons.Outlined.List,
selectedIcon = Icons.Filled.List,
onClick = {
invokeToast(resources.getString(R.string.tabBar_more), context)
selectedIndex = 4
},
badge = { Badge() },
)
)
TabBar(
modifier = Modifier.testTag(TAB_BAR),
tabDataList = tabDataList.take(tabItemsCount.value),
selectedIndex = selectedIndex,
tabTextAlignment = tabTextAlignment.value
)
}
}
}