Skip to content

Commit ec93ef1

Browse files
Merge pull request #3 from 0xberkay/master
Adding Support for Image Vectors as Icons
2 parents 9e38332 + 644d7ce commit ec93ef1

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ Declare the dependencies in the module-level `build.gradle` file 🍀 [![](https
4747
### How to use 🚀
4848

4949
Create list of bottom navigation Item with `SmoothAnimationBottomBarScreens`
50+
5051
```kotlin
5152
val bottomNavigationItems = listOf(
5253
SmoothAnimationBottomBarScreens(
5354
Screens.HomeScreen.route,
5455
stringResource(id = R.string.home),
55-
R.drawable.baseline_home_24
56+
Icons.Default.Home
5657
), SmoothAnimationBottomBarScreens(
5758
Screens.TrendingScreen.route,
5859
stringResource(id = R.string.trending),
@@ -70,7 +71,7 @@ val currentIndex = rememberSaveable {
7071
}
7172

7273
Scaffold(bottomBar = {
73-
SmoothAnimationBottomBar(navController,
74+
SmoothAnimationBottomBar(navController,
7475
bottomNavigationItems,
7576
initialIndex = currentIndex,
7677
bottomBarProperties = BottomBarProperties(),
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.PratikFagadiya.smoothanimationbottombar.model
22

3+
import androidx.compose.ui.graphics.vector.ImageVector
4+
35
data class SmoothAnimationBottomBarScreens(
46
val route: String,
57
val name: String,
6-
val icon: Int
7-
)
8+
val icon: Int,
9+
val imageVector: ImageVector? = null
10+
) {
11+
constructor(route: String, name: String, icon: Int) : this(route, name, icon, null)
12+
constructor(route: String, name: String, imageVector: ImageVector) : this(route, name, 0,imageVector)
13+
}

SmoothAnimationBottomBar/src/main/java/com/PratikFagadiya/smoothanimationbottombar/ui/SmoothAnimationBottomBar.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,20 @@ fun SmoothAnimationBottomBar(
135135
verticalAlignment = Alignment.CenterVertically,
136136
horizontalArrangement = Arrangement.Center) {
137137

138-
Icon(
139-
painter = painterResource(id = smoothAnimationBottomBarScreens.icon),
140-
contentDescription = "",
141-
tint = if (initialIndex.value == index) bottomBarProperties.iconTintActiveColor else bottomBarProperties.iconTintColor
142-
)
138+
val tint = if (index == initialIndex.value) bottomBarProperties.iconTintActiveColor else bottomBarProperties.iconTintColor
139+
if (smoothAnimationBottomBarScreens.imageVector != null) {
140+
Icon(
141+
imageVector = smoothAnimationBottomBarScreens.imageVector,
142+
contentDescription = smoothAnimationBottomBarScreens.name,
143+
tint = tint
144+
)
145+
} else {
146+
Icon(
147+
painter = painterResource(id = smoothAnimationBottomBarScreens.icon),
148+
contentDescription = smoothAnimationBottomBarScreens.name,
149+
tint = tint
150+
)
151+
}
143152

144153
AnimatedVisibility(visible = index == initialIndex.value) {
145154

0 commit comments

Comments
 (0)