|
| 1 | +import androidx.compose.foundation.background |
| 2 | +import androidx.compose.foundation.layout.Arrangement |
| 3 | +import androidx.compose.foundation.layout.Box |
| 4 | +import androidx.compose.foundation.layout.Column |
| 5 | +import androidx.compose.foundation.layout.Row |
| 6 | +import androidx.compose.foundation.layout.fillMaxSize |
| 7 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 8 | +import androidx.compose.foundation.layout.padding |
| 9 | +import androidx.compose.foundation.layout.widthIn |
| 10 | +import androidx.compose.runtime.Composable |
| 11 | +import androidx.compose.runtime.getValue |
| 12 | +import androidx.compose.runtime.mutableStateOf |
| 13 | +import androidx.compose.runtime.remember |
| 14 | +import androidx.compose.runtime.setValue |
| 15 | +import androidx.compose.ui.Alignment |
| 16 | +import androidx.compose.ui.Modifier |
| 17 | +import androidx.compose.ui.graphics.Brush |
| 18 | +import androidx.compose.ui.graphics.Color |
| 19 | +import androidx.compose.ui.unit.dp |
| 20 | +import top.yukonga.miuix.kmp.basic.FloatingNavigationBar |
| 21 | +import top.yukonga.miuix.kmp.basic.FloatingNavigationBarMode |
| 22 | +import top.yukonga.miuix.kmp.basic.NavigationBar |
| 23 | +import top.yukonga.miuix.kmp.basic.NavigationItem |
| 24 | +import top.yukonga.miuix.kmp.basic.Scaffold |
| 25 | +import top.yukonga.miuix.kmp.basic.Text |
| 26 | +import top.yukonga.miuix.kmp.icon.MiuixIcons |
| 27 | +import top.yukonga.miuix.kmp.icon.icons.useful.NavigatorSwitch |
| 28 | +import top.yukonga.miuix.kmp.icon.icons.useful.Personal |
| 29 | +import top.yukonga.miuix.kmp.icon.icons.useful.Settings |
| 30 | +import top.yukonga.miuix.kmp.theme.MiuixTheme |
| 31 | + |
| 32 | +@Composable |
| 33 | +fun NavigationBarDemo() { |
| 34 | + Box( |
| 35 | + modifier = Modifier |
| 36 | + .fillMaxSize() |
| 37 | + .background(Brush.linearGradient(listOf(Color(0xfff77062), Color(0xfffe5196)))), |
| 38 | + contentAlignment = Alignment.Center |
| 39 | + ) { |
| 40 | + Column( |
| 41 | + Modifier |
| 42 | + .padding(16.dp) |
| 43 | + .widthIn(max = 600.dp) |
| 44 | + .fillMaxWidth(), |
| 45 | + verticalArrangement = Arrangement.spacedBy(16.dp), |
| 46 | + horizontalAlignment = Alignment.CenterHorizontally |
| 47 | + ) { |
| 48 | + Row( |
| 49 | + horizontalArrangement = Arrangement.spacedBy(16.dp) |
| 50 | + ) { |
| 51 | + val pages = listOf("Home", "Profile", "Settings") |
| 52 | + val items = listOf( |
| 53 | + NavigationItem("Home", MiuixIcons.Useful.NavigatorSwitch), |
| 54 | + NavigationItem("Profile", MiuixIcons.Useful.Personal), |
| 55 | + NavigationItem("Settings", MiuixIcons.Useful.Settings) |
| 56 | + ) |
| 57 | + var selectedIndex1 by remember { mutableStateOf(0) } |
| 58 | + var selectedIndex2 by remember { mutableStateOf(0) } |
| 59 | + Scaffold( |
| 60 | + modifier = Modifier.weight(0.5f), |
| 61 | + bottomBar = { |
| 62 | + NavigationBar( |
| 63 | + items = items, |
| 64 | + selected = selectedIndex1, |
| 65 | + onClick = { selectedIndex1 = it } |
| 66 | + ) |
| 67 | + } |
| 68 | + ) { paddingValues -> |
| 69 | + Box( |
| 70 | + modifier = Modifier |
| 71 | + .fillMaxSize() |
| 72 | + .padding(paddingValues), |
| 73 | + contentAlignment = Alignment.Center |
| 74 | + ) { |
| 75 | + Text( |
| 76 | + text = "Current: ${pages[selectedIndex1]}", |
| 77 | + style = MiuixTheme.textStyles.title1 |
| 78 | + ) |
| 79 | + } |
| 80 | + } |
| 81 | + Scaffold( |
| 82 | + modifier = Modifier.weight(0.5f), |
| 83 | + bottomBar = { |
| 84 | + FloatingNavigationBar( |
| 85 | + items = items, |
| 86 | + selected = selectedIndex2, |
| 87 | + onClick = { selectedIndex2 = it }, |
| 88 | + mode = FloatingNavigationBarMode.IconOnly // Show icons only |
| 89 | + ) |
| 90 | + } |
| 91 | + ) { paddingValues -> |
| 92 | + Box( |
| 93 | + modifier = Modifier |
| 94 | + .fillMaxSize() |
| 95 | + .padding(paddingValues), |
| 96 | + contentAlignment = Alignment.Center |
| 97 | + ) { |
| 98 | + Text( |
| 99 | + text = "Current: ${pages[selectedIndex2]}", |
| 100 | + style = MiuixTheme.textStyles.title1 |
| 101 | + ) |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments