forked from anthonysidesap/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathV2SideRailActivity.kt
More file actions
285 lines (274 loc) · 13.2 KB
/
Copy pathV2SideRailActivity.kt
File metadata and controls
285 lines (274 loc) · 13.2 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package com.microsoft.fluentuidemo.demos
import android.os.Bundle
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.outlined.Email
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.MoreVert
import androidx.compose.material.icons.outlined.Settings
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.AvatarStatus
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.tokenized.controls.Button
import com.microsoft.fluentui.tokenized.controls.FloatingActionButton
import com.microsoft.fluentui.tokenized.controls.RadioButton
import com.microsoft.fluentui.tokenized.listitem.ListItem
import com.microsoft.fluentui.tokenized.navigation.SideRail
import com.microsoft.fluentui.tokenized.navigation.TabData
import com.microsoft.fluentui.tokenized.notification.Badge
import com.microsoft.fluentui.tokenized.persona.Avatar
import com.microsoft.fluentui.tokenized.persona.Person
import com.microsoft.fluentuidemo.R
import com.microsoft.fluentuidemo.V2DemoActivity
import com.microsoft.fluentuidemo.util.invokeToast
class V2SideRailActivity : V2DemoActivity() {
init {
setupActivity(this)
}
override val paramsUrl = "https://github.com/microsoft/fluentui-android/wiki/Controls#params-35"
override val controlTokensUrl =
"https://github.com/microsoft/fluentui-android/wiki/Controls#control-tokens-33"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val context = this
val _topTabItemsCount: MutableLiveData<Int> = MutableLiveData(4)
val _bottomTabItemsCount: MutableLiveData<Int> = MutableLiveData(3)
val _enableText: MutableLiveData<Boolean> = MutableLiveData(true)
setActivityContent {
val topTabItemsCount = _topTabItemsCount.observeAsState(initial = 3)
val bottomTabItemsCount = _bottomTabItemsCount.observeAsState(initial = 2)
var selected by rememberSaveable { mutableStateOf(true) }
Column {
ListItem.Header(title = "SideRail Style")
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 = "Icon Only",
modifier = Modifier.weight(1F),
style = TextStyle(
color = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground1].value(
themeMode = ThemeMode.Auto
)
)
)
RadioButton(
modifier = Modifier.testTag(TAB_BAR_VERTICAL_RADIO),
selected = !selected,
onClick = {
selected = false
_enableText.value = false
}
)
}
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
BasicText(
text = "With Text",
modifier = Modifier.weight(1F),
style = TextStyle(
color = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground1].value(
themeMode = ThemeMode.Auto
)
)
)
RadioButton(
modifier = Modifier.testTag(TAB_BAR_VERTICAL_RADIO),
selected = selected,
onClick = {
selected = true
_enableText.value = true
}
)
}
}
ListItem.Header(title = "Top 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 = topTabItemsCount.value < 4,
onClick = { _topTabItemsCount.value = topTabItemsCount.value + 1 })
Button(
modifier = Modifier.testTag(TAB_BAR_REMOVE_BUTTON),
style = ButtonStyle.Button,
size = ButtonSize.Medium,
text = "-",
enabled = topTabItemsCount.value > 1,
onClick = { _topTabItemsCount.value = topTabItemsCount.value - 1 }
)
}
}
)
ListItem.Header(title = "Bottom 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 = bottomTabItemsCount.value < 3,
onClick = {
_bottomTabItemsCount.value = bottomTabItemsCount.value + 1
})
Button(
modifier = Modifier.testTag(TAB_BAR_REMOVE_BUTTON),
style = ButtonStyle.Button,
size = ButtonSize.Medium,
text = "-",
enabled = bottomTabItemsCount.value > 1,
onClick = {
_bottomTabItemsCount.value = bottomTabItemsCount.value - 1
}
)
}
}
)
}
}
setSideBar {
var topSelectedIndex by rememberSaveable { mutableStateOf(0) }
var bottomSelectedIndex by rememberSaveable { mutableStateOf(0) }
var showHomeBadge by rememberSaveable { mutableStateOf(true) }
val topTabItemsCount = _topTabItemsCount.observeAsState(initial = 3)
val bottomTabItemsCount = _bottomTabItemsCount.observeAsState(initial = 2)
val enableText = _enableText.observeAsState(initial = false)
val topTabDataList = 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)
topSelectedIndex = 0
showHomeBadge = false
},
badge = { if (topSelectedIndex == 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)
topSelectedIndex = 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)
topSelectedIndex = 2
}
),
TabData(
title = resources.getString(R.string.tabBar_more),
icon = Icons.Outlined.MoreVert,
selectedIcon = Icons.Filled.MoreVert,
onClick = {
invokeToast(resources.getString(R.string.tabBar_more), context)
topSelectedIndex = 3
},
badge = { Badge(text = "10", badgeType = BadgeType.Character) }
)
)
val bottomTabDataList = 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)
bottomSelectedIndex = 0
showHomeBadge = false
},
badge = { if (topSelectedIndex == 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)
bottomSelectedIndex = 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)
bottomSelectedIndex = 2
}
)
)
SideRail(
modifier = Modifier.testTag(TAB_BAR),
header = {
Avatar(
person = Person(
"Amanda", "Brady",
image = R.drawable.avatar_amanda_brady,
status = AvatarStatus.Available
)
)
},
topTabDataList = topTabDataList.take(topTabItemsCount.value),
bottomTabDataList = bottomTabDataList.take(bottomTabItemsCount.value),
topTabSelectedIndex = topSelectedIndex,
bottomTabSelectedIndex = bottomSelectedIndex,
showIconText = enableText.value,
)
}
}
}