Skip to content

Commit

Permalink
Renaming + updated compose-bom
Browse files Browse the repository at this point in the history
  • Loading branch information
Aashay Gaikwad committed Oct 26, 2023
1 parent bb1ceb6 commit 9158555
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.material.icons.Icons.Filled
import androidx.compose.material.icons.Icons.Outlined
import androidx.compose.material.icons.filled.Cake
import androidx.compose.material.icons.filled.Extension
import androidx.compose.material.icons.filled.Style
import androidx.compose.material.icons.filled.ViewCarousel
import androidx.compose.material.icons.outlined.Cake
import androidx.compose.material.icons.outlined.Extension
Expand Down Expand Up @@ -34,7 +33,7 @@ enum class MainNavItem : Parcelable {
text = "Cards",
unselectedIcon = Outlined.Cake,
selectedIcon = Filled.Cake,
iconModifier = Modifier.rotate(180f),
modifier = Modifier.rotate(180f),
node = { node(it) { DatingCards() } }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum class MainNavItem : Parcelable {
text = "Back stack",
unselectedIcon = Outlined.WebStories,
selectedIcon = Filled.WebStories,
iconModifier = Modifier.rotate(180f),
modifier = Modifier.rotate(180f),
node = { BackStackExamplesNode(it) }
)

Expand All @@ -43,7 +43,7 @@ enum class MainNavItem : Parcelable {
text = "Promoter",
unselectedIcon = Outlined.GridView,
selectedIcon = Filled.GridViewCustom,
iconModifier = Modifier.rotate(45f),
modifier = Modifier.rotate(45f),
node = { PromoterNode(it) }
)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ androidx-lifecycle = "2.6.1"
androidx-navigation-compose = "2.5.1"
coil = "2.2.1"
composePlugin = "1.5.3"
composeBom = "2023.05.01"
composeBom = "2023.10.01"
composeCompiler = "1.5.3"
coroutines = "1.6.4"
dependencyAnalysis = "1.13.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ class AppyxNavItem(
val icon: @Composable (isSelected: Boolean) -> Unit,
val node: (buildContext: BuildContext) -> Node
) {
@OptIn(ExperimentalMaterial3Api::class)
constructor(
text: String,
unselectedIcon: ImageVector,
selectedIcon: ImageVector,
badgeText: Flow<String?> = MutableStateFlow(null),
iconModifier: Modifier = Modifier,
modifier: Modifier = Modifier,
hasScaleAnimation: Boolean = true,
node: (buildContext: BuildContext) -> Node
) : this(
Expand All @@ -46,41 +45,63 @@ class AppyxNavItem(
)
},
icon = { isSelected ->
BadgedBox(
badge = {
val badgeCurrentText = badgeText.collectAsState(null).value
val scale = if (hasScaleAnimation) {
var animated by remember { mutableStateOf(false) }
DisposableEffect(badgeCurrentText) {
animated = true
onDispose { animated = false }
}
animateFloatAsState(
targetValue = if (animated) 1.2f else 1f,
finishedListener = { animated = false },
).value
} else {
1f
}

if (badgeCurrentText != null) {
Badge(Modifier.scale(scale)) {
Text(
text = badgeCurrentText,
color = MaterialTheme.colorScheme.primaryContainer,
)
}
}
}
) {
Icon(
imageVector = if (isSelected) selectedIcon else unselectedIcon,
contentDescription = text,
modifier = iconModifier,
tint = MaterialTheme.colorScheme.onPrimaryContainer
)
}
BadgedIcon(
badgeText = badgeText,
hasScaleAnimation = hasScaleAnimation,
isSelected = isSelected,
selectedIcon = selectedIcon,
unselectedIcon = unselectedIcon,
text = text,
modifier = modifier
)
},
node = node
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BadgedIcon(
badgeText: Flow<String?>,
hasScaleAnimation: Boolean,
isSelected: Boolean,
selectedIcon: ImageVector,
unselectedIcon: ImageVector,
text: String,
modifier: Modifier = Modifier,
) {
BadgedBox(
modifier = modifier,
badge = {
val badgeCurrentText = badgeText.collectAsState(null).value
val scale = if (hasScaleAnimation) {
var animated by remember { mutableStateOf(false) }
DisposableEffect(badgeCurrentText) {
animated = true
onDispose { animated = false }
}
animateFloatAsState(
targetValue = if (animated) 1.2f else 1f,
finishedListener = { animated = false },
).value
} else {
1f
}

if (badgeCurrentText != null) {
Badge(Modifier.scale(scale)) {
Text(
text = badgeCurrentText,
color = MaterialTheme.colorScheme.primaryContainer,
)
}
}
}
) {
Icon(
imageVector = if (isSelected) selectedIcon else unselectedIcon,
contentDescription = text,
tint = MaterialTheme.colorScheme.onPrimaryContainer
)
}
}

0 comments on commit 9158555

Please sign in to comment.