@@ -65,8 +65,7 @@ enum class AppDestinations(
65
65
val iconSelected : ImageVector ,
66
66
@StringRes val contentDescription : Int
67
67
) {
68
- HOME (R .string.home, Icons .Outlined .Home , Icons .Filled .Home , R .string.home),
69
- FAVORITES (
68
+ HOME (R .string.home, Icons .Outlined .Home , Icons .Filled .Home , R .string.home), FAVORITES (
70
69
R .string.favorites, Icons .Outlined .Favorite , Icons .Filled .Favorite , R .string.favorites
71
70
),
72
71
SHOPPING (
@@ -92,16 +91,15 @@ class MainActivity : ComponentActivity() {
92
91
@Composable
93
92
fun NavigationSample () {
94
93
var selectedItem by remember { mutableIntStateOf(0 ) }
95
- var verticalArrangement by remember { mutableStateOf<Arrangement .Vertical >(Arrangement .Center ) }
96
- val radioOptions = listOf (
97
- " Top" to Arrangement .Top ,
98
- " Center" to Arrangement .Center ,
99
- " Bottom" to Arrangement .Bottom
94
+ val options = listOf (
95
+ " Top" to Arrangement .Top , " Center" to Arrangement .Center , " Bottom" to Arrangement .Bottom
100
96
)
101
- val (selectedOption, onOptionSelected) = remember { mutableStateOf(radioOptions[1 ].first) }
97
+
98
+ val (verticalArrangement, onOptionSelected) = remember { mutableStateOf(options[1 ]) }
102
99
103
100
NavigationSuiteScaffold (
104
- modifier = Modifier .fillMaxSize(), navigationItems = {
101
+ modifier = Modifier .fillMaxSize(),
102
+ navigationItems = {
105
103
AppDestinations .entries.forEachIndexed { index, item ->
106
104
NavigationSuiteItem (
107
105
icon = {
@@ -118,7 +116,8 @@ fun NavigationSample() {
118
116
selected = index == selectedItem,
119
117
onClick = { selectedItem = index })
120
118
}
121
- }, navigationItemVerticalArrangement = verticalArrangement
119
+ },
120
+ navigationItemVerticalArrangement = verticalArrangement.second
122
121
) {
123
122
Column (
124
123
modifier = Modifier
@@ -127,29 +126,24 @@ fun NavigationSample() {
127
126
verticalArrangement = Arrangement .Center
128
127
) {
129
128
Text (" NavRail icons arrangement" , style = MaterialTheme .typography.headlineSmall)
130
- radioOptions.forEach { item ->
131
- val (text, arrangement) = item
129
+ options.forEach { item ->
132
130
Row (
133
131
Modifier
134
132
.fillMaxWidth()
135
133
.height(56 .dp)
136
134
.selectable(
137
- selected = (text == selectedOption),
138
- onClick = {
139
- onOptionSelected(text);
140
- verticalArrangement = arrangement
141
- },
142
- role = Role .RadioButton
135
+ selected = (item == verticalArrangement), onClick = {
136
+ onOptionSelected(item)
137
+ }, role = Role .RadioButton
143
138
)
144
139
.padding(horizontal = 16 .dp),
145
140
verticalAlignment = Alignment .CenterVertically
146
141
) {
147
142
RadioButton (
148
- selected = (text == selectedOption),
149
- onClick = null
143
+ selected = (item == verticalArrangement), onClick = null
150
144
)
151
145
Text (
152
- text = text ,
146
+ text = item.first ,
153
147
style = MaterialTheme .typography.bodyLarge,
154
148
modifier = Modifier .padding(start = 16 .dp)
155
149
)
0 commit comments