@@ -8,7 +8,6 @@ import androidx.compose.foundation.background
88import androidx.compose.foundation.gestures.detectTapGestures
99import androidx.compose.foundation.layout.Arrangement
1010import androidx.compose.foundation.layout.Column
11- import androidx.compose.foundation.layout.PaddingValues
1211import androidx.compose.foundation.layout.Row
1312import androidx.compose.foundation.layout.Spacer
1413import androidx.compose.foundation.layout.WindowInsets
@@ -111,7 +110,7 @@ fun NavigationBar(
111110 val fontWeight = if (isSelected) FontWeight .Bold else FontWeight .Normal
112111 Column (
113112 modifier = Modifier
114- .height(NavigationBarHeight )
113+ .height(if (platform() != Platform . IOS ) 64 .dp else 48 .dp )
115114 .weight(1f / items.size)
116115 .pointerInput(Unit ) {
117116 detectTapGestures(
@@ -123,7 +122,7 @@ fun NavigationBar(
123122 onTap = { onClick(index) }
124123 )
125124 },
126- horizontalAlignment = Alignment . CenterHorizontally
125+ horizontalAlignment = CenterHorizontally
127126 ) {
128127 Image (
129128 modifier = Modifier .size(32 .dp).padding(top = 6 .dp),
@@ -157,131 +156,125 @@ fun NavigationBar(
157156/* *
158157 * A floating navigation bar that supports 2 to 5 items.
159158 *
160- * @param items The list of items to display in the [NavigationBar ].
161- * @param selected The index of the currently selected item in the [NavigationBar ].
159+ * @param items The list of items to display in the [FloatingNavigationBar ].
160+ * @param selected The index of the currently selected item in the [FloatingNavigationBar ].
162161 * @param onClick A callback function that is invoked when an item is clicked. It receives the selected item's index.
163- * @param modifier A [Modifier] to be applied to the [NavigationBar] for additional customization.
164- * @param color The background color of the [NavigationBar].
165- * @param defaultWindowInsetsPadding Whether to apply default window insets padding (e.g., for status bars or navigation bars).
166- * @param cornerRadius The corner radius of the [NavigationBar], used for rounded corners.
167- * @param outSidePadding The padding applied outside the [NavigationBar].
168- * @param horizontalAlignment The alignment of the [NavigationBar] within its parent, typically used to center it horizontally.
169- * @param showBorder Whether to display a border around the [NavigationBar].
170- * @param showMode The mode for displaying items in the [NavigationBar]. It can show icons, text, or both.
162+ * @param modifier A [Modifier] to be applied to the [FloatingNavigationBar] for additional customization.
163+ * @param color The background color of the [FloatingNavigationBar].
164+ * @param cornerRadius The corner radius of the [FloatingNavigationBar], used for rounded corners.
165+ * @param horizontalAlignment The alignment of the [FloatingNavigationBar] within its parent, typically used to center it horizontally.
166+ * @param showBorder Whether to display a border around the [FloatingNavigationBar].
167+ * @param defaultWindowInsetsPadding whether to apply default window insets padding to the [FloatingNavigationBar].
168+ * @param showMode The mode for displaying items in the [FloatingNavigationBar]. It can show icons, text or both.
171169 */
172170@Composable
173171fun FloatingNavigationBar (
174- cornerRadius : Dp = FloatingToolbarDefaults .CornerRadius ,
172+ items : List <NavigationItem >,
173+ selected : Int ,
174+ onClick : (Int ) -> Unit ,
175175 modifier : Modifier = Modifier ,
176176 color : Color = MiuixTheme .colorScheme.surfaceContainer,
177- outSidePadding : PaddingValues = FloatingToolbarDefaults .OutSidePadding ,
177+ cornerRadius : Dp = FloatingToolbarDefaults .CornerRadius ,
178178 horizontalAlignment : Alignment .Horizontal = CenterHorizontally ,
179179 showBorder : Boolean = true,
180180 defaultWindowInsetsPadding : Boolean = true,
181- items : List <NavigationItem >,
182- selected : Int ,
183- onClick : (Int ) -> Unit ,
184181 showMode : FloatingNavigationBarShowMode = FloatingNavigationBarShowMode .IconOnly
185182) {
186- require(items.size in 2 .. 5 ) { " BottomBar must have between 2 and 5 items" }
187- Surface (
188- color = Color . Transparent
183+ require(items.size in 2 .. 5 ) { " FloatingNavigationBar must have between 2 and 5 items" }
184+ Column (
185+ modifier = Modifier .fillMaxWidth()
189186 ) {
190- Column (
191- modifier = Modifier .fillMaxWidth()
192- ) {
193- Row (
194- modifier = Modifier
195- .padding(outSidePadding)
196- .then(
197- if (defaultWindowInsetsPadding) {
198- Modifier
199- .windowInsetsPadding(WindowInsets .statusBars.only(WindowInsetsSides .Vertical ))
200- .windowInsetsPadding(WindowInsets .captionBar.only(WindowInsetsSides .Vertical ))
201- .windowInsetsPadding(WindowInsets .displayCutout.only(WindowInsetsSides .Horizontal ))
202- .windowInsetsPadding(WindowInsets .navigationBars)
203- } else Modifier
204- )
205- .then(
206- if (showBorder) {
207- Modifier
208- .background(
209- color = MiuixTheme .colorScheme.dividerLine,
210- shape = SmoothRoundedCornerShape (cornerRadius)
211- )
212- .padding(0.75 .dp) // 边框内边距
213- } else Modifier
214- )
215- .clip(SmoothRoundedCornerShape (cornerRadius))
216- .background(color)
217- .then(modifier)
218- .padding(horizontal = 12 .dp)
219- .align(horizontalAlignment),
220- horizontalArrangement = Arrangement .spacedBy(12 .dp),
221- verticalAlignment = Alignment .CenterVertically
222- ) {
223- items.forEachIndexed { index, item ->
224- val isSelected = selected == index
225- var isPressed by remember { mutableStateOf(false ) }
226- val tint by animateColorAsState(
227- targetValue = when {
228- isPressed -> if (isSelected) {
229- MiuixTheme .colorScheme.onSurfaceContainer.copy(alpha = 0.6f )
230- } else {
231- MiuixTheme .colorScheme.onSurfaceContainerVariant.copy(alpha = 0.6f )
232- }
233-
234- isSelected -> MiuixTheme .colorScheme.onSurfaceContainer
235- else -> MiuixTheme .colorScheme.onSurfaceContainerVariant
236- }
237- )
238- val fontWeight = if (isSelected) FontWeight .Bold else FontWeight .Normal
239- Column (
240- modifier = Modifier
241- .pointerInput(Unit ) {
242- detectTapGestures(
243- onPress = {
244- isPressed = true
245- tryAwaitRelease()
246- isPressed = false
247- },
248- onTap = { onClick(index) }
249- )
250- },
251- horizontalAlignment = Alignment .CenterHorizontally
252- ) {
253- if (showMode == FloatingNavigationBarShowMode .IconAndText ) {
254- Image (
255- modifier = Modifier .size(32 .dp).padding(top = 6 .dp),
256- imageVector = item.icon,
257- contentDescription = item.label,
258- colorFilter = ColorFilter .tint(tint)
259- )
260- Text (
261- modifier = Modifier .padding(bottom = if (platform() != Platform .IOS ) 12 .dp else 0 .dp),
262- text = item.label,
263- color = tint,
264- textAlign = TextAlign .Center ,
265- fontSize = 12 .sp,
266- fontWeight = fontWeight
267- )
268- } else if (showMode == FloatingNavigationBarShowMode .TextOnly ) {
269- Text (
270- modifier = Modifier .padding(vertical = 12 .dp),
271- text = item.label,
272- color = tint,
273- textAlign = TextAlign .Center ,
274- fontSize = 14 .sp,
275- fontWeight = fontWeight
187+ Row (
188+ modifier = Modifier
189+ .padding(bottom = if (platform() != Platform .IOS ) 40 .dp else 34 .dp)
190+ .then(
191+ if (defaultWindowInsetsPadding) {
192+ Modifier
193+ .windowInsetsPadding(WindowInsets .statusBars.only(WindowInsetsSides .Bottom ))
194+ .windowInsetsPadding(WindowInsets .captionBar.only(WindowInsetsSides .Bottom ))
195+ .windowInsetsPadding(WindowInsets .displayCutout.only(WindowInsetsSides .Horizontal ))
196+ .windowInsetsPadding(WindowInsets .navigationBars)
197+ } else Modifier
198+ )
199+ .then(
200+ if (showBorder) {
201+ Modifier
202+ .background(
203+ color = MiuixTheme .colorScheme.dividerLine,
204+ shape = SmoothRoundedCornerShape (cornerRadius)
276205 )
206+ .padding(0.75 .dp)
207+ } else Modifier
208+ )
209+ .clip(SmoothRoundedCornerShape (cornerRadius))
210+ .background(color)
211+ .then(modifier)
212+ .padding(horizontal = 12 .dp)
213+ .align(horizontalAlignment),
214+ horizontalArrangement = Arrangement .spacedBy(12 .dp),
215+ verticalAlignment = Alignment .CenterVertically
216+ ) {
217+ items.forEachIndexed { index, item ->
218+ val isSelected = selected == index
219+ var isPressed by remember { mutableStateOf(false ) }
220+ val tint by animateColorAsState(
221+ targetValue = when {
222+ isPressed -> if (isSelected) {
223+ MiuixTheme .colorScheme.onSurfaceContainer.copy(alpha = 0.6f )
277224 } else {
278- Image (
279- modifier = Modifier .padding(vertical = 8 .dp).size(32 .dp),
280- imageVector = item.icon,
281- contentDescription = item.label,
282- colorFilter = ColorFilter .tint(tint)
283- )
225+ MiuixTheme .colorScheme.onSurfaceContainerVariant.copy(alpha = 0.6f )
284226 }
227+
228+ isSelected -> MiuixTheme .colorScheme.onSurfaceContainer
229+ else -> MiuixTheme .colorScheme.onSurfaceContainerVariant
230+ }
231+ )
232+ val fontWeight = if (isSelected) FontWeight .Bold else FontWeight .Normal
233+ Column (
234+ modifier = Modifier
235+ .pointerInput(Unit ) {
236+ detectTapGestures(
237+ onPress = {
238+ isPressed = true
239+ tryAwaitRelease()
240+ isPressed = false
241+ },
242+ onTap = { onClick(index) }
243+ )
244+ },
245+ horizontalAlignment = CenterHorizontally
246+ ) {
247+ if (showMode == FloatingNavigationBarShowMode .IconAndText ) {
248+ Image (
249+ modifier = Modifier .padding(top = 6 .dp).size(24 .dp),
250+ imageVector = item.icon,
251+ contentDescription = item.label,
252+ colorFilter = ColorFilter .tint(tint)
253+ )
254+ Text (
255+ modifier = Modifier .padding(bottom = 6 .dp),
256+ text = item.label,
257+ color = tint,
258+ textAlign = TextAlign .Center ,
259+ fontSize = 12 .sp,
260+ fontWeight = fontWeight
261+ )
262+ } else if (showMode == FloatingNavigationBarShowMode .TextOnly ) {
263+ Text (
264+ modifier = Modifier .padding(vertical = 16 .dp, horizontal = 2 .dp),
265+ text = item.label,
266+ color = tint,
267+ textAlign = TextAlign .Center ,
268+ fontSize = 14 .sp,
269+ fontWeight = fontWeight
270+ )
271+ } else {
272+ Image (
273+ modifier = Modifier .padding(vertical = 12 .dp, horizontal = 12 .dp).size(28 .dp),
274+ imageVector = item.icon,
275+ contentDescription = item.label,
276+ colorFilter = ColorFilter .tint(tint)
277+ )
285278 }
286279 }
287280 }
@@ -305,9 +298,6 @@ enum class FloatingNavigationBarShowMode {
305298 TextOnly
306299}
307300
308- /* * The default expanded height of a [NavigationBar]. */
309- val NavigationBarHeight : Dp = if (platform() != Platform .IOS ) 64 .dp else 48 .dp
310-
311301/* *
312302 * The data class for [NavigationBar].
313303 *
0 commit comments