From ac7464871654f45da9854e0a92bac68e86e459cf Mon Sep 17 00:00:00 2001 From: cp-megh Date: Fri, 7 Jun 2024 15:37:23 +0530 Subject: [PATCH] Update dependencies and format code --- .idea/.name | 1 + .idea/deploymentTargetSelector.xml | 18 ++ .idea/gradle.xml | 5 +- .idea/migrations.xml | 10 + app/build.gradle.kts | 14 +- .../ExampleInstrumentedTest.kt | 2 +- .../animatedbottombarcompose/MainActivity.kt | 18 +- .../composables/Screen1.kt | 117 ++++---- .../composables/Screen2.kt | 77 ++--- .../composables/Screen3.kt | 36 +-- .../model/MainNavigation.kt | 12 +- .../ui/theme/Color.kt | 2 +- .../ui/theme/Theme.kt | 48 +-- .../animatedbottombarcompose/ui/theme/Type.kt | 22 +- .../ExampleUnitTest.kt | 2 +- bottombar/build.gradle.kts | 14 +- .../bottombar/ExampleInstrumentedTest.kt | 2 +- .../example/bottombar/AnimatedBottomBar.kt | 80 ++--- .../bottombar/components/BottomBarItem.kt | 27 +- .../bottombar/components/Indicators.kt | 76 ++--- .../bottombar/components/NavigationBarItem.kt | 284 ++++++++++-------- .../example/bottombar/model/AnimationState.kt | 3 +- .../bottombar/model/IndicatorDirection.kt | 2 +- .../example/bottombar/model/IndicatorStyle.kt | 4 +- .../com/example/bottombar/model/ItemStyle.kt | 4 +- .../example/bottombar/model/VisibleItem.kt | 4 +- .../com/example/bottombar/utils/Constants.kt | 2 +- .../bottombar/utils/ModifierExtensions.kt | 31 +- .../com/example/bottombar/ExampleUnitTest.kt | 2 +- build.gradle.kts | 12 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 31 files changed, 511 insertions(+), 422 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/deploymentTargetSelector.xml create mode 100644 .idea/migrations.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..b49d622 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +AnimatedBottomBarCompose \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..94be4a8 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4c320ed..eba88b5 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,10 +4,8 @@ diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 73a0ade..9734d6d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -24,7 +24,7 @@ android { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" + "proguard-rules.pro", ) } } @@ -50,22 +50,22 @@ android { dependencies { - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") - implementation("androidx.activity:activity-compose:1.8.2") - implementation(platform("androidx.compose:compose-bom:2023.09.00")) + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.1") + implementation("androidx.activity:activity-compose:1.9.0") + implementation(platform("androidx.compose:compose-bom:2024.05.00")) implementation("androidx.compose.ui:ui") implementation("androidx.compose.ui:ui-graphics") - implementation("androidx.navigation:navigation-compose:2.7.6") + implementation("androidx.navigation:navigation-compose:2.7.7") implementation("androidx.compose.ui:ui-tooling-preview") implementation("androidx.compose.material3:material3") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") - androidTestImplementation(platform("androidx.compose:compose-bom:2023.09.00")) + androidTestImplementation(platform("androidx.compose:compose-bom:2024.05.00")) androidTestImplementation("androidx.compose.ui:ui-test-junit4") debugImplementation("androidx.compose.ui:ui-tooling") debugImplementation("androidx.compose.ui:ui-test-manifest") implementation(project(":bottombar")) implementation(kotlin("reflect")) -} \ No newline at end of file +} diff --git a/app/src/androidTest/java/com/example/animatedbottombarcompose/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/animatedbottombarcompose/ExampleInstrumentedTest.kt index 6ebc3fa..89dc908 100644 --- a/app/src/androidTest/java/com/example/animatedbottombarcompose/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/example/animatedbottombarcompose/ExampleInstrumentedTest.kt @@ -19,4 +19,4 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.animatedbottombarcompose", appContext.packageName) } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/animatedbottombarcompose/MainActivity.kt b/app/src/main/java/com/example/animatedbottombarcompose/MainActivity.kt index de9abd5..54800e1 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/MainActivity.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/MainActivity.kt @@ -29,13 +29,13 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) setContent { AnimatedBottomBarComposeTheme { - val navController = rememberNavController() val navBackStackEntry by navController.currentBackStackEntryAsState() val currentRoute = navBackStackEntry?.destination?.route - val navigationItems = MainNavigation::class.nestedClasses.map { - it.objectInstance as MainNavigation - } + val navigationItems = + MainNavigation::class.nestedClasses.map { + it.objectInstance as MainNavigation + } var selectedItem by remember { mutableIntStateOf(0) } Scaffold( @@ -44,7 +44,7 @@ class MainActivity : ComponentActivity() { selectedItem = selectedItem, itemSize = navigationItems.take(3).size, containerColor = Color.LightGray, - indicatorStyle = IndicatorStyle.DOT + indicatorStyle = IndicatorStyle.DOT, ) { navigationItems.take(3).forEachIndexed { index, navigationItem -> BottomBarItem( @@ -66,15 +66,15 @@ class MainActivity : ComponentActivity() { }, imageVector = navigationItem.icon, label = navigationItem.title, - containerColor = Color.Transparent + containerColor = Color.Transparent, ) } } - } + }, ) { NavHost( navController = navController, - startDestination = MainNavigation.ScreenA.route + startDestination = MainNavigation.ScreenA.route, ) { composable(MainNavigation.ScreenA.route) { Screen1(navigationItems) @@ -90,4 +90,4 @@ class MainActivity : ComponentActivity() { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen1.kt b/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen1.kt index aa5cf89..9196df4 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen1.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen1.kt @@ -32,22 +32,23 @@ import com.example.bottombar.model.VisibleItem @Composable fun Screen1(navigationItems: List) { - var selectedItem by remember { mutableIntStateOf(0) } Column( - modifier = Modifier - .fillMaxSize() - .verticalScroll(rememberScrollState()), - verticalArrangement = Arrangement.Top + modifier = + Modifier + .fillMaxSize() + .verticalScroll(rememberScrollState()), + verticalArrangement = Arrangement.Top, ) { Text( text = "**Checkout INDICATORS with different STYLES(animations)**", style = MaterialTheme.typography.titleMedium, - modifier = Modifier - .fillMaxWidth() - .padding(top = 20.dp), - textAlign = TextAlign.Center + modifier = + Modifier + .fillMaxWidth() + .padding(top = 20.dp), + textAlign = TextAlign.Center, ) Spacer(modifier = Modifier.height(50.dp)) @@ -55,7 +56,7 @@ fun Screen1(navigationItems: List) { text = "LINE INDICATOR", style = MaterialTheme.typography.headlineSmall, modifier = Modifier.fillMaxWidth(), - textAlign = TextAlign.Center + textAlign = TextAlign.Center, ) Spacer(modifier = Modifier.height(25.dp)) AnimatedBottomBar( @@ -63,7 +64,7 @@ fun Screen1(navigationItems: List) { itemSize = navigationItems.size, indicatorStyle = IndicatorStyle.LINE, containerShape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), - containerColor = MaterialTheme.colorScheme.secondaryContainer + containerColor = MaterialTheme.colorScheme.secondaryContainer, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -75,12 +76,11 @@ fun Screen1(navigationItems: List) { imageVector = navigationItem.icon, label = navigationItem.title, visibleItem = VisibleItem.ICON, - itemStyle = ItemStyle.STYLE1 + itemStyle = ItemStyle.STYLE1, ) } } - Spacer(modifier = Modifier.height(25.dp)) AnimatedBottomBar( @@ -88,7 +88,7 @@ fun Screen1(navigationItems: List) { itemSize = navigationItems.size, indicatorStyle = IndicatorStyle.LINE, containerShape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), - containerColor = MaterialTheme.colorScheme.secondaryContainer + containerColor = MaterialTheme.colorScheme.secondaryContainer, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -100,7 +100,7 @@ fun Screen1(navigationItems: List) { imageVector = navigationItem.icon, label = navigationItem.title, visibleItem = VisibleItem.LABEL, - itemStyle = ItemStyle.STYLE1 + itemStyle = ItemStyle.STYLE1, ) } } @@ -112,7 +112,7 @@ fun Screen1(navigationItems: List) { itemSize = navigationItems.size, indicatorStyle = IndicatorStyle.LINE, containerShape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), - containerColor = MaterialTheme.colorScheme.secondaryContainer + containerColor = MaterialTheme.colorScheme.secondaryContainer, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -124,7 +124,7 @@ fun Screen1(navigationItems: List) { imageVector = navigationItem.icon, label = navigationItem.title, visibleItem = VisibleItem.BOTH, - itemStyle = ItemStyle.STYLE1 + itemStyle = ItemStyle.STYLE1, ) } } @@ -136,7 +136,7 @@ fun Screen1(navigationItems: List) { indicatorStyle = IndicatorStyle.LINE, containerShape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), indicatorDirection = IndicatorDirection.BOTTOM, - containerColor = MaterialTheme.colorScheme.secondaryContainer + containerColor = MaterialTheme.colorScheme.secondaryContainer, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -148,7 +148,7 @@ fun Screen1(navigationItems: List) { imageVector = navigationItem.icon, label = navigationItem.title, visibleItem = VisibleItem.ICON, - itemStyle = ItemStyle.STYLE3 + itemStyle = ItemStyle.STYLE3, ) } } @@ -161,7 +161,7 @@ fun Screen1(navigationItems: List) { indicatorStyle = IndicatorStyle.LINE, containerShape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), indicatorDirection = IndicatorDirection.BOTTOM, - containerColor = MaterialTheme.colorScheme.secondaryContainer + containerColor = MaterialTheme.colorScheme.secondaryContainer, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -173,7 +173,7 @@ fun Screen1(navigationItems: List) { imageVector = navigationItem.icon, label = navigationItem.title, visibleItem = VisibleItem.LABEL, - itemStyle = ItemStyle.STYLE4 + itemStyle = ItemStyle.STYLE4, ) } } @@ -186,7 +186,7 @@ fun Screen1(navigationItems: List) { indicatorStyle = IndicatorStyle.LINE, containerShape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp), indicatorDirection = IndicatorDirection.BOTTOM, - containerColor = MaterialTheme.colorScheme.secondaryContainer + containerColor = MaterialTheme.colorScheme.secondaryContainer, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -198,7 +198,7 @@ fun Screen1(navigationItems: List) { imageVector = navigationItem.icon, label = navigationItem.title, visibleItem = VisibleItem.BOTH, - itemStyle = ItemStyle.STYLE5 + itemStyle = ItemStyle.STYLE5, ) } } @@ -209,14 +209,14 @@ fun Screen1(navigationItems: List) { text = "DOT INDICATOR", style = MaterialTheme.typography.headlineSmall, modifier = Modifier.fillMaxWidth(), - textAlign = TextAlign.Center + textAlign = TextAlign.Center, ) Spacer(modifier = Modifier.height(25.dp)) AnimatedBottomBar( selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.errorContainer, - indicatorStyle = IndicatorStyle.DOT + indicatorStyle = IndicatorStyle.DOT, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -227,7 +227,7 @@ fun Screen1(navigationItems: List) { }, imageVector = navigationItem.icon, label = navigationItem.title, - itemStyle = ItemStyle.STYLE1 + itemStyle = ItemStyle.STYLE1, ) } } @@ -237,7 +237,7 @@ fun Screen1(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.errorContainer, - indicatorStyle = IndicatorStyle.DOT + indicatorStyle = IndicatorStyle.DOT, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -250,7 +250,7 @@ fun Screen1(navigationItems: List) { label = navigationItem.title, iconColor = if (selected) Color.Black else Color.Black.copy(0.8f), textColor = if (selected) Color.Black else Color.Black.copy(0.8f), - itemStyle = ItemStyle.STYLE3 + itemStyle = ItemStyle.STYLE3, ) } } @@ -260,7 +260,7 @@ fun Screen1(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.errorContainer, - indicatorStyle = IndicatorStyle.DOT + indicatorStyle = IndicatorStyle.DOT, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -274,7 +274,7 @@ fun Screen1(navigationItems: List) { iconColor = if (selected) Color.Black else Color.Black.copy(0.8f), textColor = if (selected) Color.Black else Color.Black.copy(0.8f), itemStyle = ItemStyle.STYLE4, - activeIndicatorColor = Color.White + activeIndicatorColor = Color.White, ) } } @@ -284,7 +284,7 @@ fun Screen1(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.errorContainer, - indicatorStyle = IndicatorStyle.DOT + indicatorStyle = IndicatorStyle.DOT, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -298,7 +298,7 @@ fun Screen1(navigationItems: List) { iconColor = if (selected) Color.Black else Color.Black.copy(0.8f), textColor = if (selected) Color.Black else Color.Black.copy(0.8f), itemStyle = ItemStyle.STYLE5, - activeIndicatorColor = Color.White + activeIndicatorColor = Color.White, ) } } @@ -309,14 +309,14 @@ fun Screen1(navigationItems: List) { text = "WORM INDICATOR", style = MaterialTheme.typography.headlineSmall, modifier = Modifier.fillMaxWidth(), - textAlign = TextAlign.Center + textAlign = TextAlign.Center, ) Spacer(modifier = Modifier.height(25.dp)) AnimatedBottomBar( selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.tertiaryContainer, - indicatorStyle = IndicatorStyle.WORM + indicatorStyle = IndicatorStyle.WORM, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -329,7 +329,7 @@ fun Screen1(navigationItems: List) { label = navigationItem.title, iconColor = if (selected) Color.Black else Color.Black.copy(0.8f), textColor = if (selected) Color.Black else Color.Black.copy(0.8f), - itemStyle = ItemStyle.STYLE1 + itemStyle = ItemStyle.STYLE1, ) } } @@ -339,7 +339,7 @@ fun Screen1(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.tertiaryContainer, - indicatorStyle = IndicatorStyle.WORM + indicatorStyle = IndicatorStyle.WORM, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -352,7 +352,7 @@ fun Screen1(navigationItems: List) { label = navigationItem.title, iconColor = if (selected) Color.Black else Color.Black.copy(0.8f), textColor = if (selected) Color.Black else Color.Black.copy(0.8f), - itemStyle = ItemStyle.STYLE3 + itemStyle = ItemStyle.STYLE3, ) } } @@ -362,7 +362,7 @@ fun Screen1(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.tertiaryContainer, - indicatorStyle = IndicatorStyle.WORM + indicatorStyle = IndicatorStyle.WORM, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -375,7 +375,7 @@ fun Screen1(navigationItems: List) { label = navigationItem.title, iconColor = if (selected) Color.Black else Color.Black.copy(0.8f), textColor = if (selected) Color.Black else Color.Black.copy(0.8f), - itemStyle = ItemStyle.STYLE4 + itemStyle = ItemStyle.STYLE4, ) } } @@ -385,7 +385,7 @@ fun Screen1(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.tertiaryContainer, - indicatorStyle = IndicatorStyle.WORM + indicatorStyle = IndicatorStyle.WORM, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -399,7 +399,7 @@ fun Screen1(navigationItems: List) { iconColor = if (selected) Color.Black else Color.Black.copy(0.8f), textColor = if (selected) Color.Black else Color.Black.copy(0.8f), itemStyle = ItemStyle.STYLE5, - activeIndicatorColor = Color.White + activeIndicatorColor = Color.White, ) } } @@ -410,7 +410,7 @@ fun Screen1(navigationItems: List) { text = "FILLED INDICATOR", style = MaterialTheme.typography.headlineSmall, modifier = Modifier.fillMaxWidth(), - textAlign = TextAlign.Center + textAlign = TextAlign.Center, ) Spacer(modifier = Modifier.height(25.dp)) AnimatedBottomBar( @@ -418,7 +418,7 @@ fun Screen1(navigationItems: List) { itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.secondaryContainer, indicatorStyle = IndicatorStyle.FILLED, - indicatorColor = MaterialTheme.colorScheme.background + indicatorColor = MaterialTheme.colorScheme.background, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -429,7 +429,7 @@ fun Screen1(navigationItems: List) { }, imageVector = navigationItem.icon, label = navigationItem.title, - itemStyle = ItemStyle.STYLE1 + itemStyle = ItemStyle.STYLE1, ) } } @@ -440,7 +440,7 @@ fun Screen1(navigationItems: List) { itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.secondaryContainer, indicatorStyle = IndicatorStyle.FILLED, - indicatorColor = MaterialTheme.colorScheme.background + indicatorColor = MaterialTheme.colorScheme.background, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -451,7 +451,7 @@ fun Screen1(navigationItems: List) { }, imageVector = navigationItem.icon, label = navigationItem.title, - itemStyle = ItemStyle.STYLE3 + itemStyle = ItemStyle.STYLE3, ) } } @@ -462,7 +462,7 @@ fun Screen1(navigationItems: List) { itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.secondaryContainer, indicatorStyle = IndicatorStyle.FILLED, - indicatorColor = MaterialTheme.colorScheme.background + indicatorColor = MaterialTheme.colorScheme.background, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -473,7 +473,7 @@ fun Screen1(navigationItems: List) { }, imageVector = navigationItem.icon, label = navigationItem.title, - itemStyle = ItemStyle.STYLE4 + itemStyle = ItemStyle.STYLE4, ) } } @@ -484,7 +484,7 @@ fun Screen1(navigationItems: List) { itemSize = navigationItems.size, containerColor = MaterialTheme.colorScheme.secondaryContainer, indicatorStyle = IndicatorStyle.FILLED, - indicatorColor = MaterialTheme.colorScheme.background + indicatorColor = MaterialTheme.colorScheme.background, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -497,13 +497,14 @@ fun Screen1(navigationItems: List) { label = navigationItem.title, itemStyle = ItemStyle.STYLE5, iconColor = if (selected) Color.White else Color.Black, - glowingBackground = Brush.radialGradient( - listOf( - Color.Black, - Color.Transparent, - Color.Transparent - ) - ) + glowingBackground = + Brush.radialGradient( + listOf( + Color.Black, + Color.Transparent, + Color.Transparent, + ), + ), ) } } @@ -512,7 +513,7 @@ fun Screen1(navigationItems: List) { AnimatedBottomBar( selectedItem = selectedItem, itemSize = navigationItems.size, - containerColor = MaterialTheme.colorScheme.secondaryContainer + containerColor = MaterialTheme.colorScheme.secondaryContainer, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -526,7 +527,7 @@ fun Screen1(navigationItems: List) { itemStyle = ItemStyle.STYLE2, iconColor = if (selected) Color.Black else Color.White, textColor = if (selected) Color.Black else Color.White, - activeIndicatorColor = Color.White + activeIndicatorColor = Color.White, ) } } diff --git a/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen2.kt b/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen2.kt index 7189105..c64f22d 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen2.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen2.kt @@ -38,37 +38,39 @@ fun Screen2(navigationItems: List) { var indicatorStyle: IndicatorStyle by remember { mutableStateOf(IndicatorStyle.WORM) } - val itemStyles = listOf( - ItemStyle.STYLE1, - ItemStyle.STYLE2, - ItemStyle.STYLE3, - ItemStyle.STYLE4, - ItemStyle.STYLE5 - ) + val itemStyles = + listOf( + ItemStyle.STYLE1, + ItemStyle.STYLE2, + ItemStyle.STYLE3, + ItemStyle.STYLE4, + ItemStyle.STYLE5, + ) val indicatorStyles = listOf( IndicatorStyle.NONE, IndicatorStyle.LINE, IndicatorStyle.DOT, - IndicatorStyle.WORM + IndicatorStyle.WORM, ) Column( - modifier = Modifier - .fillMaxSize() - .verticalScroll(rememberScrollState()) + modifier = + Modifier + .fillMaxSize() + .verticalScroll(rememberScrollState()), ) { - Spacer(modifier = Modifier.height(50.dp)) Text( text = "Item Style:", style = MaterialTheme.typography.titleMedium, - modifier = Modifier.padding(horizontal = 8.dp) + modifier = Modifier.padding(horizontal = 8.dp), ) Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 8.dp) + modifier = + Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp), ) { Row(verticalAlignment = Alignment.CenterVertically) { itemStyles.take(3).forEach { @@ -91,12 +93,13 @@ fun Screen2(navigationItems: List) { Text( text = "Indicator Style:", style = MaterialTheme.typography.titleMedium, - modifier = Modifier.padding(horizontal = 8.dp) + modifier = Modifier.padding(horizontal = 8.dp), ) Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 8.dp) + modifier = + Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp), ) { Row(verticalAlignment = Alignment.CenterVertically) { indicatorStyles.take(2).forEach { @@ -123,7 +126,7 @@ fun Screen2(navigationItems: List) { itemSize = navigationItems.size, indicatorStyle = if (itemStyle != ItemStyle.STYLE2) indicatorStyle else IndicatorStyle.NONE, containerColor = Color.Transparent, - indicatorColor = Color.Red + indicatorColor = Color.Red, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -137,13 +140,14 @@ fun Screen2(navigationItems: List) { iconColor = if (selected) Color.Red else Color.Black, textColor = if (selected) Color.Red else Color.Black, itemStyle = itemStyle, - glowingBackground = Brush.radialGradient( - listOf( - Color.Red.copy(0.5f), - Color.Transparent, - Color.Transparent - ) - ) + glowingBackground = + Brush.radialGradient( + listOf( + Color.Red.copy(0.5f), + Color.Transparent, + Color.Transparent, + ), + ), ) } } @@ -154,7 +158,7 @@ fun Screen2(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, indicatorStyle = if (itemStyle != ItemStyle.STYLE2) indicatorStyle else IndicatorStyle.NONE, - indicatorColor = Color.White + indicatorColor = Color.White, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -168,13 +172,14 @@ fun Screen2(navigationItems: List) { iconColor = if (selected) Color.White else Color.Black, textColor = if (selected) Color.White else Color.Black, itemStyle = itemStyle, - glowingBackground = Brush.radialGradient( - listOf( - Color.Black, - Color.Transparent, - Color.Transparent - ) - ) + glowingBackground = + Brush.radialGradient( + listOf( + Color.Black, + Color.Transparent, + Color.Transparent, + ), + ), ) } } diff --git a/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen3.kt b/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen3.kt index 3ca2463..c2520a9 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen3.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/composables/Screen3.kt @@ -34,30 +34,32 @@ fun Screen3(navigationItems: List) { var itemStyle: ItemStyle by remember { mutableStateOf(ItemStyle.STYLE3) } - val itemStyles = listOf( - ItemStyle.STYLE1, - ItemStyle.STYLE2, - ItemStyle.STYLE3, - ItemStyle.STYLE4, - ItemStyle.STYLE5 - ) + val itemStyles = + listOf( + ItemStyle.STYLE1, + ItemStyle.STYLE2, + ItemStyle.STYLE3, + ItemStyle.STYLE4, + ItemStyle.STYLE5, + ) Column( - modifier = Modifier - .fillMaxSize() - .verticalScroll(rememberScrollState()) + modifier = + Modifier + .fillMaxSize() + .verticalScroll(rememberScrollState()), ) { - Spacer(modifier = Modifier.height(50.dp)) Text( text = "Item Style:", style = MaterialTheme.typography.titleMedium, - modifier = Modifier.padding(horizontal = 8.dp) + modifier = Modifier.padding(horizontal = 8.dp), ) Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 8.dp) + modifier = + Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp), ) { Row(verticalAlignment = Alignment.CenterVertically) { itemStyles.take(3).forEach { @@ -84,7 +86,7 @@ fun Screen3(navigationItems: List) { itemSize = navigationItems.size, indicatorStyle = if (itemStyle != ItemStyle.STYLE2) IndicatorStyle.FILLED else IndicatorStyle.NONE, containerColor = Color.Transparent, - indicatorColor = Color.Red.copy(0.5f) + indicatorColor = Color.Red.copy(0.5f), ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem @@ -109,7 +111,7 @@ fun Screen3(navigationItems: List) { selectedItem = selectedItem, itemSize = navigationItems.size, indicatorStyle = if (itemStyle != ItemStyle.STYLE2) IndicatorStyle.FILLED else IndicatorStyle.NONE, - indicatorColor = Color.White + indicatorColor = Color.White, ) { navigationItems.forEachIndexed { index, navigationItem -> val selected = index == selectedItem diff --git a/app/src/main/java/com/example/animatedbottombarcompose/model/MainNavigation.kt b/app/src/main/java/com/example/animatedbottombarcompose/model/MainNavigation.kt index 7392267..17adf5e 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/model/MainNavigation.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/model/MainNavigation.kt @@ -10,29 +10,29 @@ import androidx.compose.ui.graphics.vector.ImageVector sealed class MainNavigation( val title: String, val route: String, - val icon: ImageVector + val icon: ImageVector, ) { data object ScreenA : MainNavigation( title = "Screen1", route = "Screen1", - icon = Icons.Outlined.Home + icon = Icons.Outlined.Home, ) data object ScreenB : MainNavigation( title = "Screen2", route = "Screen2", - icon = Icons.Outlined.Notifications + icon = Icons.Outlined.Notifications, ) data object ScreenC : MainNavigation( title = "Screen3", route = "Screen3", - icon = Icons.Outlined.FavoriteBorder + icon = Icons.Outlined.FavoriteBorder, ) data object ScreenD : MainNavigation( title = "Screen4", route = "Screen4", - icon = Icons.Outlined.Email + icon = Icons.Outlined.Email, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Color.kt b/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Color.kt index c544177..fcf43ad 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Color.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Color.kt @@ -8,4 +8,4 @@ val Pink80 = Color(0xFFEFB8C8) val Purple40 = Color(0xFF6650a4) val PurpleGrey40 = Color(0xFF625b71) -val Pink40 = Color(0xFF7D5260) \ No newline at end of file +val Pink40 = Color(0xFF7D5260) diff --git a/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Theme.kt b/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Theme.kt index 0d26027..80f0821 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Theme.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Theme.kt @@ -15,17 +15,18 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalView import androidx.core.view.WindowCompat -private val DarkColorScheme = darkColorScheme( - primary = Purple80, - secondary = PurpleGrey80, - tertiary = Pink80 -) - -private val LightColorScheme = lightColorScheme( - primary = Purple40, - secondary = PurpleGrey40, - tertiary = Pink40 +private val DarkColorScheme = + darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80, + ) +private val LightColorScheme = + lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40, /* Other default colors to override background = Color(0xFFFFFBFE), surface = Color(0xFFFFFBFE), @@ -34,25 +35,26 @@ private val LightColorScheme = lightColorScheme( onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), - */ -) + */ + ) @Composable fun AnimatedBottomBarComposeTheme( darkTheme: Boolean = isSystemInDarkTheme(), // Dynamic color is available on Android 12+ dynamicColor: Boolean = true, - content: @Composable () -> Unit + content: @Composable () -> Unit, ) { - val colorScheme = when { - dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { - val context = LocalContext.current - if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) - } + val colorScheme = + when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } - darkTheme -> DarkColorScheme - else -> LightColorScheme - } + darkTheme -> DarkColorScheme + else -> LightColorScheme + } val view = LocalView.current if (!view.isInEditMode) { SideEffect { @@ -65,6 +67,6 @@ fun AnimatedBottomBarComposeTheme( MaterialTheme( colorScheme = colorScheme, typography = Typography, - content = content + content = content, ) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Type.kt b/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Type.kt index b55b9ef..6dfdbd7 100644 --- a/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Type.kt +++ b/app/src/main/java/com/example/animatedbottombarcompose/ui/theme/Type.kt @@ -7,14 +7,16 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp // Set of Material typography styles to start with -val Typography = Typography( - bodyLarge = TextStyle( - fontFamily = FontFamily.Default, - fontWeight = FontWeight.Normal, - fontSize = 16.sp, - lineHeight = 24.sp, - letterSpacing = 0.5.sp - ) +val Typography = + Typography( + bodyLarge = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp, + ), /* Other default text styles to override titleLarge = TextStyle( fontFamily = FontFamily.Default, @@ -30,5 +32,5 @@ val Typography = Typography( lineHeight = 16.sp, letterSpacing = 0.5.sp ) - */ -) \ No newline at end of file + */ + ) diff --git a/app/src/test/java/com/example/animatedbottombarcompose/ExampleUnitTest.kt b/app/src/test/java/com/example/animatedbottombarcompose/ExampleUnitTest.kt index 310b968..fce3e90 100644 --- a/app/src/test/java/com/example/animatedbottombarcompose/ExampleUnitTest.kt +++ b/app/src/test/java/com/example/animatedbottombarcompose/ExampleUnitTest.kt @@ -13,4 +13,4 @@ class ExampleUnitTest { fun addition_isCorrect() { assertEquals(4, 2 + 2) } -} \ No newline at end of file +} diff --git a/bottombar/build.gradle.kts b/bottombar/build.gradle.kts index f7bf469..eb863b2 100644 --- a/bottombar/build.gradle.kts +++ b/bottombar/build.gradle.kts @@ -8,8 +8,8 @@ ext { set("PUBLISH_ARTIFACT_ID", "bottombar") } -apply{ - from("${rootDir}/scripts/publish-module.gradle") +apply { + from("$rootDir/scripts/publish-module.gradle") } android { @@ -32,7 +32,7 @@ android { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" + "proguard-rules.pro", ) } } @@ -64,9 +64,9 @@ android { dependencies { - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") - implementation("androidx.activity:activity-compose:1.8.2") - implementation(platform("androidx.compose:compose-bom:2023.09.00")) + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.1") + implementation("androidx.activity:activity-compose:1.9.0") + implementation(platform("androidx.compose:compose-bom:2024.05.00")) implementation("androidx.compose.ui:ui") implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-tooling-preview") @@ -74,4 +74,4 @@ dependencies { testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") -} \ No newline at end of file +} diff --git a/bottombar/src/androidTest/java/com/example/bottombar/ExampleInstrumentedTest.kt b/bottombar/src/androidTest/java/com/example/bottombar/ExampleInstrumentedTest.kt index cee9273..67db3f6 100644 --- a/bottombar/src/androidTest/java/com/example/bottombar/ExampleInstrumentedTest.kt +++ b/bottombar/src/androidTest/java/com/example/bottombar/ExampleInstrumentedTest.kt @@ -19,4 +19,4 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.example.bottombar.test", appContext.packageName) } -} \ No newline at end of file +} diff --git a/bottombar/src/main/java/com/example/bottombar/AnimatedBottomBar.kt b/bottombar/src/main/java/com/example/bottombar/AnimatedBottomBar.kt index 752038c..d769953 100644 --- a/bottombar/src/main/java/com/example/bottombar/AnimatedBottomBar.kt +++ b/bottombar/src/main/java/com/example/bottombar/AnimatedBottomBar.kt @@ -64,33 +64,40 @@ fun AnimatedBottomBar( indicatorStyle: IndicatorStyle = IndicatorStyle.NONE, indicatorColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, indicatorHeight: Dp = DEFAULT_INDICATOR_HEIGHT, - animationSpec: AnimationSpec = spring( - dampingRatio = 1f, - stiffness = Spring.StiffnessMediumLow - ), + animationSpec: AnimationSpec = + spring( + dampingRatio = 1f, + stiffness = Spring.StiffnessMediumLow, + ), indicatorDirection: IndicatorDirection = IndicatorDirection.TOP, indicatorShape: RoundedCornerShape = RoundedCornerShape(25.dp), - content: @Composable RowScope.() -> Unit + content: @Composable RowScope.() -> Unit, ) { Surface( color = containerColor, contentColor = contentColor, modifier = modifier, - shape = containerShape + shape = containerShape, ) { BoxWithConstraints( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = Dp(bottomBarHeight / (bottomBarHeight / 16))) + modifier = + Modifier + .fillMaxWidth() + .padding(horizontal = Dp(bottomBarHeight / (bottomBarHeight / 16))), ) { selectedItem?.let { itemSize?.let { val maxWidth = this.maxWidth val indicatorOffset: Dp by animateDpAsState( - targetValue = (maxWidth / (itemSize.takeIf { it != 0 } - ?: 1)) * selectedItem, + targetValue = + ( + maxWidth / ( + itemSize.takeIf { it != 0 } + ?: 1 + ) + ) * selectedItem, animationSpec = animationSpec, - label = "indicator" + label = "indicator", ) when (indicatorStyle) { @@ -100,8 +107,9 @@ fun AnimatedBottomBar( indicatorOffset = indicatorOffset, arraySize = itemSize.takeIf { it != 0 } ?: 1, indicatorColor = indicatorColor, - modifier = Modifier - .height(bottomBarHeight) + modifier = + Modifier + .height(bottomBarHeight), ) } @@ -109,9 +117,10 @@ fun AnimatedBottomBar( WormIndicator( indicatorOffset = indicatorOffset, indicatorColor = indicatorColor, - modifier = Modifier - .height(bottomBarHeight), - itemWidth = maxWidth / (itemSize.takeIf { it != 0 } ?: 1) + modifier = + Modifier + .height(bottomBarHeight), + itemWidth = maxWidth / (itemSize.takeIf { it != 0 } ?: 1), ) } @@ -121,14 +130,15 @@ fun AnimatedBottomBar( arraySize = itemSize.takeIf { it != 0 } ?: 1, indicatorHeight = indicatorHeight, indicatorColor = indicatorColor, - modifier = Modifier - .conditional(indicatorDirection == IndicatorDirection.TOP) { - align(Alignment.TopStart) - } - .conditional(indicatorDirection == IndicatorDirection.BOTTOM) { - align(Alignment.BottomStart) - }, - indicatorShape = indicatorShape + modifier = + Modifier + .conditional(indicatorDirection == IndicatorDirection.TOP) { + align(Alignment.TopStart) + } + .conditional(indicatorDirection == IndicatorDirection.BOTTOM) { + align(Alignment.BottomStart) + }, + indicatorShape = indicatorShape, ) } @@ -137,9 +147,10 @@ fun AnimatedBottomBar( indicatorOffset = indicatorOffset, arraySize = itemSize.takeIf { it != 0 } ?: 1, indicatorColor = indicatorColor, - modifier = Modifier - .height(bottomBarHeight), - indicatorShape = indicatorShape + modifier = + Modifier + .height(bottomBarHeight), + indicatorShape = indicatorShape, ) } } @@ -147,13 +158,14 @@ fun AnimatedBottomBar( } Row( - modifier = Modifier - .fillMaxWidth() - .height(bottomBarHeight) - .selectableGroup(), + modifier = + Modifier + .fillMaxWidth() + .height(bottomBarHeight) + .selectableGroup(), horizontalArrangement = Arrangement.SpaceBetween, - content = content + content = content, ) } } -} \ No newline at end of file +} diff --git a/bottombar/src/main/java/com/example/bottombar/components/BottomBarItem.kt b/bottombar/src/main/java/com/example/bottombar/components/BottomBarItem.kt index d02444d..a31d18a 100644 --- a/bottombar/src/main/java/com/example/bottombar/components/BottomBarItem.kt +++ b/bottombar/src/main/java/com/example/bottombar/components/BottomBarItem.kt @@ -40,16 +40,17 @@ fun RowScope.BottomBarItem( textColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, activeIndicatorColor: Color = MaterialTheme.colorScheme.onPrimaryContainer.copy(0.2f), inactiveIndicatorColor: Color = Color.Transparent, - glowingBackground: Brush = Brush.radialGradient( - listOf( - Color.White, - Color.Transparent, - Color.Transparent - ) - ), + glowingBackground: Brush = + Brush.radialGradient( + listOf( + Color.White, + Color.Transparent, + Color.Transparent, + ), + ), label: String, visibleItem: VisibleItem = VisibleItem.ICON, - itemStyle: ItemStyle = ItemStyle.STYLE1 + itemStyle: ItemStyle = ItemStyle.STYLE1, ) { when (itemStyle) { ItemStyle.STYLE1 -> { @@ -63,7 +64,7 @@ fun RowScope.BottomBarItem( iconColor, textColor, label, - visibleItem + visibleItem, ) } @@ -78,7 +79,7 @@ fun RowScope.BottomBarItem( textColor, label, activeIndicatorColor, - inactiveIndicatorColor + inactiveIndicatorColor, ) } @@ -92,7 +93,7 @@ fun RowScope.BottomBarItem( contentColor, iconColor, textColor, - label + label, ) } @@ -104,7 +105,7 @@ fun RowScope.BottomBarItem( rememberVectorPainter(image = imageVector), containerColor, contentColor, - iconColor + iconColor, ) } @@ -117,7 +118,7 @@ fun RowScope.BottomBarItem( containerColor, contentColor, iconColor, - glowingBackground = glowingBackground + glowingBackground = glowingBackground, ) } } diff --git a/bottombar/src/main/java/com/example/bottombar/components/Indicators.kt b/bottombar/src/main/java/com/example/bottombar/components/Indicators.kt index 99f3883..54e7630 100644 --- a/bottombar/src/main/java/com/example/bottombar/components/Indicators.kt +++ b/bottombar/src/main/java/com/example/bottombar/components/Indicators.kt @@ -30,17 +30,18 @@ internal fun LineIndicator( indicatorColor: Color, indicatorHeight: Dp, modifier: Modifier, - indicatorShape: RoundedCornerShape + indicatorShape: RoundedCornerShape, ) { Box( - modifier = modifier - .height(indicatorHeight) - .fillMaxWidth(1f / arraySize) - .offset( - x = indicatorOffset - ) - .clip(shape = indicatorShape) - .background(indicatorColor, shape = indicatorShape) + modifier = + modifier + .height(indicatorHeight) + .fillMaxWidth(1f / arraySize) + .offset( + x = indicatorOffset, + ) + .clip(shape = indicatorShape) + .background(indicatorColor, shape = indicatorShape), ) } @@ -49,22 +50,24 @@ internal fun DotIndicator( indicatorOffset: Dp, arraySize: Int, indicatorColor: Color, - modifier: Modifier + modifier: Modifier, ) { Box( - modifier = modifier - .fillMaxWidth(1f / arraySize) - .offset( - x = indicatorOffset - ) + modifier = + modifier + .fillMaxWidth(1f / arraySize) + .offset( + x = indicatorOffset, + ), ) { Column(modifier = Modifier.align(Alignment.BottomCenter)) { Icon( painter = painterResource(id = R.drawable.ic_dot_indicator), contentDescription = "", tint = indicatorColor, - modifier = Modifier - .size(8.dp) + modifier = + Modifier + .size(8.dp), ) Spacer(modifier = Modifier.height(4.dp)) } @@ -76,18 +79,20 @@ internal fun WormIndicator( indicatorOffset: Dp, indicatorColor: Color, modifier: Modifier, - itemWidth: Dp + itemWidth: Dp, ) { Box( - modifier = modifier - .width(itemWidth) + modifier = + modifier + .width(itemWidth), ) { Box( - modifier = Modifier - .align(Alignment.BottomCenter) - .padding(bottom = 4.dp) - .customWormTransition(indicatorOffset, indicatorColor, itemWidth) - .size(8.dp) + modifier = + Modifier + .align(Alignment.BottomCenter) + .padding(bottom = 4.dp) + .customWormTransition(indicatorOffset, indicatorColor, itemWidth) + .size(8.dp), ) } } @@ -98,16 +103,17 @@ internal fun FilledIndicator( arraySize: Int, indicatorColor: Color, modifier: Modifier, - indicatorShape: RoundedCornerShape + indicatorShape: RoundedCornerShape, ) { Box( - modifier = modifier - .fillMaxWidth(1f / arraySize) - .offset( - x = indicatorOffset - ) - .padding(vertical = 8.dp) - .clip(indicatorShape) - .background(indicatorColor, shape = indicatorShape) + modifier = + modifier + .fillMaxWidth(1f / arraySize) + .offset( + x = indicatorOffset, + ) + .padding(vertical = 8.dp) + .clip(indicatorShape) + .background(indicatorColor, shape = indicatorShape), ) -} \ No newline at end of file +} diff --git a/bottombar/src/main/java/com/example/bottombar/components/NavigationBarItem.kt b/bottombar/src/main/java/com/example/bottombar/components/NavigationBarItem.kt index e47e010..bf866a1 100644 --- a/bottombar/src/main/java/com/example/bottombar/components/NavigationBarItem.kt +++ b/bottombar/src/main/java/com/example/bottombar/components/NavigationBarItem.kt @@ -72,13 +72,13 @@ internal fun RowScope.NavigationBarItem( iconColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, textColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, label: String, - visibleItem: VisibleItem = VisibleItem.LABEL + visibleItem: VisibleItem = VisibleItem.LABEL, ) { var animationState by remember { mutableStateOf(AnimationState.Start) } val scaleAnimation: Float by animateFloatAsState( if (animationState == AnimationState.Start) DefaultScale else SmallScale, tween(easing = LinearEasing), - label = "" + label = "", ) LaunchedEffect(key1 = selected, key2 = Unit, block = { @@ -89,53 +89,61 @@ internal fun RowScope.NavigationBarItem( Surface( color = containerColor, contentColor = contentColor, - modifier = Modifier - .weight(1f) - .clickable( - onClick = { - onClick() - }, - interactionSource = MutableInteractionSource(), - indication = rememberRipple(bounded = false, radius = 30.dp) - ) + modifier = + Modifier + .weight(1f) + .clickable( + onClick = { + onClick() + }, + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(bounded = false, radius = 30.dp), + ), ) { Column( - modifier = modifier - .fillMaxHeight() - .scale(scaleAnimation), + modifier = + modifier + .fillMaxHeight() + .scale(scaleAnimation), horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center + verticalArrangement = Arrangement.Center, ) { AnimatedVisibility( visible = (visibleItem == VisibleItem.BOTH && !selected), - enter = fadeIn() + slideInVertically( - tween(easing = LinearEasing) - ) { fullHeight -> -fullHeight }, - exit = slideOutVertically( - tween(easing = LinearEasing) - ) { fullHeight -> -fullHeight } + fadeOut() + enter = + fadeIn() + + slideInVertically( + tween(easing = LinearEasing), + ) { fullHeight -> -fullHeight }, + exit = + slideOutVertically( + tween(easing = LinearEasing), + ) { fullHeight -> -fullHeight } + fadeOut(), ) { Icon( painter = iconPainter, contentDescription = null, - tint = iconColor + tint = iconColor, ) } AnimatedVisibility( visible = (visibleItem == VisibleItem.BOTH && selected), - enter = fadeIn() + slideInVertically( - tween(easing = LinearEasing) - ) { fullHeight -> fullHeight }, - exit = slideOutVertically( - tween(easing = LinearEasing) - ) { fullHeight -> fullHeight } + fadeOut() + enter = + fadeIn() + + slideInVertically( + tween(easing = LinearEasing), + ) { fullHeight -> fullHeight }, + exit = + slideOutVertically( + tween(easing = LinearEasing), + ) { fullHeight -> fullHeight } + fadeOut(), ) { Column(horizontalAlignment = Alignment.CenterHorizontally) { Icon( painter = iconPainter, contentDescription = null, - tint = iconColor + tint = iconColor, ) Text( @@ -144,7 +152,7 @@ internal fun RowScope.NavigationBarItem( style = MaterialTheme.typography.labelMedium, maxLines = 1, softWrap = false, - overflow = TextOverflow.Clip + overflow = TextOverflow.Clip, ) } } @@ -153,36 +161,42 @@ internal fun RowScope.NavigationBarItem( AnimatedVisibility( visible = if (visibleItem == VisibleItem.LABEL) !selected else selected, - enter = fadeIn() + slideInVertically( - tween( - easing = LinearEasing - ) - ) { fullHeight -> -fullHeight }, - exit = slideOutVertically( - tween( - easing = LinearEasing - ) - ) { fullHeight -> -fullHeight } + fadeOut() + enter = + fadeIn() + + slideInVertically( + tween( + easing = LinearEasing, + ), + ) { fullHeight -> -fullHeight }, + exit = + slideOutVertically( + tween( + easing = LinearEasing, + ), + ) { fullHeight -> -fullHeight } + fadeOut(), ) { Icon( painter = iconPainter, contentDescription = null, - tint = iconColor + tint = iconColor, ) } AnimatedVisibility( visible = if (visibleItem == VisibleItem.LABEL) selected else !selected, - enter = fadeIn() + slideInVertically( - tween( - easing = LinearEasing - ) - ) { fullHeight -> fullHeight }, - exit = slideOutVertically( - tween( - easing = LinearEasing - ) - ) { fullHeight -> fullHeight } + fadeOut() + enter = + fadeIn() + + slideInVertically( + tween( + easing = LinearEasing, + ), + ) { fullHeight -> fullHeight }, + exit = + slideOutVertically( + tween( + easing = LinearEasing, + ), + ) { fullHeight -> fullHeight } + fadeOut(), ) { Text( text = label, @@ -190,7 +204,7 @@ internal fun RowScope.NavigationBarItem( style = MaterialTheme.typography.labelMedium, maxLines = 1, softWrap = false, - overflow = TextOverflow.Clip + overflow = TextOverflow.Clip, ) } } @@ -212,45 +226,48 @@ internal fun NavigationBarItem( textColor: Color, label: String, activeIndicatorColor: Color, - inactiveIndicatorColor: Color + inactiveIndicatorColor: Color, ) { val color by animateColorAsState( targetValue = if (selected) activeIndicatorColor else inactiveIndicatorColor, animationSpec = tween(easing = LinearEasing), - label = "" + label = "", ) BoxWithConstraints( - modifier = modifier - .fillMaxHeight(), - contentAlignment = Alignment.Center + modifier = + modifier + .fillMaxHeight(), + contentAlignment = Alignment.Center, ) { Surface( color = color, contentColor = contentColor, shape = RoundedCornerShape(maxHeight / 2), - modifier = Modifier.clickable( - interactionSource = MutableInteractionSource(), - indication = rememberRipple(bounded = false, radius = 30.dp) - ) { onClick() } + modifier = + Modifier.clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(bounded = false, radius = 30.dp), + ) { onClick() }, ) { Row( - modifier = Modifier - .padding( - vertical = maxHeight / 12, - horizontal = maxHeight / 4 - ), + modifier = + Modifier + .padding( + vertical = maxHeight / 12, + horizontal = maxHeight / 4, + ), horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { Icon( modifier = Modifier.height(this@BoxWithConstraints.maxHeight / 2), painter = iconPainter, contentDescription = null, - tint = iconColor + tint = iconColor, ) AnimatedVisibility( - visible = selected + visible = selected, ) { Text( text = label, @@ -259,7 +276,7 @@ internal fun NavigationBarItem( maxLines = 1, softWrap = false, overflow = TextOverflow.Clip, - modifier = Modifier.padding(horizontal = 4.dp) + modifier = Modifier.padding(horizontal = 4.dp), ) } } @@ -281,27 +298,27 @@ internal fun RowScope.NavigationBarItem( contentColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, iconColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, textColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, - label: String + label: String, ) { var animationState by remember { mutableStateOf(AnimationState.Start) } val scaleAnimation: Float by animateFloatAsState( if (animationState == AnimationState.Start) DefaultScale else SmallScale, tween(durationMillis = LongDuration, delayMillis = ShortDuration, easing = LinearEasing), - label = "" + label = "", ) val alphaAnimation: Float by animateFloatAsState( if (animationState == AnimationState.Start) LowestAlpha else DefaultAlpha, tween( durationMillis = if (animationState == AnimationState.Start) MediumDuration else LongDuration, delayMillis = if (animationState == AnimationState.Start) 0 else ShortDuration, - easing = LinearEasing + easing = LinearEasing, ), - label = "" + label = "", ) val paddingAnimation: Dp by animateDpAsState( if (animationState == AnimationState.Start) 20.dp else 16.dp, tween(durationMillis = LongDuration, delayMillis = ShortDuration, easing = LinearEasing), - label = "" + label = "", ) LaunchedEffect(key1 = selected, key2 = Unit, block = { animationState = if (selected) AnimationState.Finish else AnimationState.Start @@ -310,28 +327,31 @@ internal fun RowScope.NavigationBarItem( Surface( color = containerColor, contentColor = contentColor, - modifier = Modifier - .clickable( - onClick = { - onClick() - }, - interactionSource = MutableInteractionSource(), - indication = rememberRipple(bounded = false, radius = 30.dp) - ) - .weight(1f) + modifier = + Modifier + .clickable( + onClick = { + onClick() + }, + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(bounded = false, radius = 30.dp), + ) + .weight(1f), ) { Box( - modifier = modifier - .fillMaxHeight(), - contentAlignment = Alignment.TopCenter + modifier = + modifier + .fillMaxHeight(), + contentAlignment = Alignment.TopCenter, ) { Icon( painter = iconPainter, contentDescription = null, tint = iconColor, - modifier = Modifier - .scale(scaleAnimation) - .padding(top = paddingAnimation) + modifier = + Modifier + .scale(scaleAnimation) + .padding(top = paddingAnimation), ) Text( @@ -341,16 +361,16 @@ internal fun RowScope.NavigationBarItem( maxLines = 1, softWrap = false, overflow = TextOverflow.Clip, - modifier = Modifier - .align(Alignment.BottomCenter) - .alpha(alphaAnimation) - .padding(bottom = 16.dp) + modifier = + Modifier + .align(Alignment.BottomCenter) + .alpha(alphaAnimation) + .padding(bottom = 12.dp), ) } } } - /** * A composable function that creates view for **STYLE4** where selected item will * have active color and rest all will be grayed out. @@ -369,13 +389,13 @@ internal fun RowScope.NavigationBarItem( val scaleAnimation: Float by animateFloatAsState( if (animationState == AnimationState.Start) DefaultScale else LargeScale, tween(durationMillis = MediumDuration, delayMillis = ShortDuration, easing = LinearEasing), - label = "" + label = "", ) val color by animateColorAsState( targetValue = if (selected) iconColor else iconColor.copy(0.5f), animationSpec = tween(easing = LinearEasing), - label = "" + label = "", ) LaunchedEffect(key1 = selected, key2 = Unit, block = { @@ -385,26 +405,28 @@ internal fun RowScope.NavigationBarItem( Surface( color = containerColor, contentColor = contentColor, - modifier = Modifier - .clickable( - onClick = { - onClick() - }, - interactionSource = MutableInteractionSource(), - indication = rememberRipple(bounded = false, radius = 30.dp) - ) - .weight(1f) + modifier = + Modifier + .clickable( + onClick = { + onClick() + }, + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(bounded = false, radius = 30.dp), + ) + .weight(1f), ) { Box( - modifier = modifier - .fillMaxHeight() - .scale(scaleAnimation), - contentAlignment = Alignment.Center + modifier = + modifier + .fillMaxHeight() + .scale(scaleAnimation), + contentAlignment = Alignment.Center, ) { Icon( painter = iconPainter, contentDescription = null, - tint = color + tint = color, ) } } @@ -429,7 +451,7 @@ internal fun RowScope.NavigationBarItem( val scaleAnimation: Float by animateFloatAsState( if (animationState == AnimationState.Start) LowestAlpha else DefaultAlpha, tween(durationMillis = MediumDuration, delayMillis = ShortDuration, easing = LinearEasing), - label = "" + label = "", ) LaunchedEffect(key1 = selected, key2 = Unit, block = { @@ -439,35 +461,37 @@ internal fun RowScope.NavigationBarItem( Surface( color = containerColor, contentColor = contentColor, - modifier = Modifier - .clickable( - onClick = { - onClick() - }, - interactionSource = MutableInteractionSource(), - indication = rememberRipple(bounded = false, radius = 30.dp) - ) - .weight(1f) + modifier = + Modifier + .clickable( + onClick = { + onClick() + }, + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(bounded = false, radius = 30.dp), + ) + .weight(1f), ) { Box( - modifier = modifier - .fillMaxHeight(), - contentAlignment = Alignment.Center + modifier = + modifier + .fillMaxHeight(), + contentAlignment = Alignment.Center, ) { - if (selected) { Box( - modifier = Modifier - .fillMaxSize() - .scale(scaleAnimation) - .background(glowingBackground) + modifier = + Modifier + .fillMaxSize() + .scale(scaleAnimation) + .background(glowingBackground), ) } Icon( painter = iconPainter, contentDescription = null, - tint = iconColor + tint = iconColor, ) } } diff --git a/bottombar/src/main/java/com/example/bottombar/model/AnimationState.kt b/bottombar/src/main/java/com/example/bottombar/model/AnimationState.kt index 9948a3f..55c0db8 100644 --- a/bottombar/src/main/java/com/example/bottombar/model/AnimationState.kt +++ b/bottombar/src/main/java/com/example/bottombar/model/AnimationState.kt @@ -1,5 +1,6 @@ package com.example.bottombar.model internal enum class AnimationState { - Start, Finish + Start, + Finish, } diff --git a/bottombar/src/main/java/com/example/bottombar/model/IndicatorDirection.kt b/bottombar/src/main/java/com/example/bottombar/model/IndicatorDirection.kt index 0ba0afc..aad9ced 100644 --- a/bottombar/src/main/java/com/example/bottombar/model/IndicatorDirection.kt +++ b/bottombar/src/main/java/com/example/bottombar/model/IndicatorDirection.kt @@ -10,5 +10,5 @@ package com.example.bottombar.model */ enum class IndicatorDirection { TOP, - BOTTOM + BOTTOM, } diff --git a/bottombar/src/main/java/com/example/bottombar/model/IndicatorStyle.kt b/bottombar/src/main/java/com/example/bottombar/model/IndicatorStyle.kt index ba67b57..a319306 100644 --- a/bottombar/src/main/java/com/example/bottombar/model/IndicatorStyle.kt +++ b/bottombar/src/main/java/com/example/bottombar/model/IndicatorStyle.kt @@ -18,5 +18,5 @@ enum class IndicatorStyle { DOT, WORM, LINE, - FILLED -} \ No newline at end of file + FILLED, +} diff --git a/bottombar/src/main/java/com/example/bottombar/model/ItemStyle.kt b/bottombar/src/main/java/com/example/bottombar/model/ItemStyle.kt index 22cfe7b..ab98214 100644 --- a/bottombar/src/main/java/com/example/bottombar/model/ItemStyle.kt +++ b/bottombar/src/main/java/com/example/bottombar/model/ItemStyle.kt @@ -22,5 +22,5 @@ enum class ItemStyle { STYLE2, STYLE3, STYLE4, - STYLE5 -} \ No newline at end of file + STYLE5, +} diff --git a/bottombar/src/main/java/com/example/bottombar/model/VisibleItem.kt b/bottombar/src/main/java/com/example/bottombar/model/VisibleItem.kt index e91e7ca..e363d86 100644 --- a/bottombar/src/main/java/com/example/bottombar/model/VisibleItem.kt +++ b/bottombar/src/main/java/com/example/bottombar/model/VisibleItem.kt @@ -14,5 +14,5 @@ package com.example.bottombar.model enum class VisibleItem { ICON, LABEL, - BOTH -} \ No newline at end of file + BOTH, +} diff --git a/bottombar/src/main/java/com/example/bottombar/utils/Constants.kt b/bottombar/src/main/java/com/example/bottombar/utils/Constants.kt index 21cce8d..5b7bc3a 100644 --- a/bottombar/src/main/java/com/example/bottombar/utils/Constants.kt +++ b/bottombar/src/main/java/com/example/bottombar/utils/Constants.kt @@ -12,4 +12,4 @@ const val LowestAlpha = 0f // For Animation Durations const val LongDuration = 600 const val MediumDuration = 300 -const val ShortDuration = 100 \ No newline at end of file +const val ShortDuration = 100 diff --git a/bottombar/src/main/java/com/example/bottombar/utils/ModifierExtensions.kt b/bottombar/src/main/java/com/example/bottombar/utils/ModifierExtensions.kt index 21d5d87..5ea765b 100644 --- a/bottombar/src/main/java/com/example/bottombar/utils/ModifierExtensions.kt +++ b/bottombar/src/main/java/com/example/bottombar/utils/ModifierExtensions.kt @@ -13,19 +13,20 @@ import androidx.compose.ui.unit.Dp internal fun Modifier.conditional( condition: Boolean, orElse: (@Composable Modifier.() -> Modifier)? = null, - modifier: @Composable Modifier.() -> Modifier -): Modifier = composed { - if (condition) { - modifier.invoke(this) - } else { - orElse?.invoke(this) ?: this + modifier: @Composable Modifier.() -> Modifier, +): Modifier = + composed { + if (condition) { + modifier.invoke(this) + } else { + orElse?.invoke(this) ?: this + } } -} internal fun Modifier.customWormTransition( offset: Dp, indicatorColor: Color, - itemWidth: Dp + itemWidth: Dp, ) = composed { drawWithContent { val distance = itemWidth.roundToPx() @@ -36,14 +37,18 @@ internal fun Modifier.customWormTransition( val head = xPos + distance * 0f.coerceAtLeast(wormOffset - 1) val tail = xPos + size.width + distance * 1f.coerceAtMost(wormOffset) - val worm = RoundRect( - head, 0f, tail, size.height, - CornerRadius(50f) - ) + val worm = + RoundRect( + head, + 0f, + tail, + size.height, + CornerRadius(50f), + ) val path = Path().apply { addRoundRect(worm) } // Draw the worm shape on top of the content drawPath(path = path, color = indicatorColor) } -} \ No newline at end of file +} diff --git a/bottombar/src/test/java/com/example/bottombar/ExampleUnitTest.kt b/bottombar/src/test/java/com/example/bottombar/ExampleUnitTest.kt index a5d49ca..c3ddec5 100644 --- a/bottombar/src/test/java/com/example/bottombar/ExampleUnitTest.kt +++ b/bottombar/src/test/java/com/example/bottombar/ExampleUnitTest.kt @@ -13,4 +13,4 @@ class ExampleUnitTest { fun addition_isCorrect() { assertEquals(4, 2 + 2) } -} \ No newline at end of file +} diff --git a/build.gradle.kts b/build.gradle.kts index 3146f48..69a70dc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,11 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id("com.android.application") version "8.1.1" apply false + id("com.android.application") version "8.4.1" apply false id("org.jetbrains.kotlin.android") version "1.9.10" apply false - id("com.android.library") version "8.1.1" apply false - id ("io.github.gradle-nexus.publish-plugin") version "1.3.0" + id("com.android.library") version "8.4.1" apply false + id("io.github.gradle-nexus.publish-plugin") version "1.3.0" } -apply{ - from("${rootDir}/scripts/publish-root.gradle") -} \ No newline at end of file +apply { + from("$rootDir/scripts/publish-root.gradle") +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 339bc56..0fe4415 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Sep 27 17:49:33 IST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists