-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accordion component to display generic credentials (#22)
- Loading branch information
Showing
4 changed files
with
181 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
example/src/main/java/com/spruceid/mobilesdkexample/utils/Accordion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.spruceid.mobilesdkexample.utils | ||
|
||
import androidx.compose.animation.AnimatedVisibility | ||
import androidx.compose.animation.expandVertically | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.compose.animation.shrinkVertically | ||
import androidx.compose.animation.slideInVertically | ||
import androidx.compose.animation.slideOutVertically | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.ColumnScope | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.rotate | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.spruceid.mobilesdkexample.R | ||
import com.spruceid.mobilesdkexample.ui.theme.ColorStone500 | ||
import com.spruceid.mobilesdkexample.ui.theme.ColorStone600 | ||
import com.spruceid.mobilesdkexample.ui.theme.Inter | ||
|
||
@Composable | ||
fun Accordion( | ||
title: String, | ||
startExpanded: Boolean, | ||
modifier: Modifier = Modifier, | ||
content: @Composable ColumnScope.() -> Unit | ||
) { | ||
var expanded by remember { mutableStateOf(startExpanded) } | ||
val density = LocalDensity.current | ||
|
||
AccordionHeader(title = title, isExpanded = expanded) { | ||
expanded = !expanded | ||
} | ||
AnimatedVisibility(visible = expanded, | ||
enter = slideInVertically { | ||
with(density) { -40.dp.roundToPx() } | ||
} + expandVertically( | ||
expandFrom = Alignment.Top | ||
) + fadeIn( | ||
initialAlpha = 0.3f | ||
), | ||
exit = slideOutVertically() + shrinkVertically() + fadeOut() | ||
|
||
) { | ||
Column(content = content, modifier = modifier) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun AccordionHeader( | ||
title: String, | ||
isExpanded: Boolean = false, | ||
onTapped: () -> Unit = {} | ||
) { | ||
val degrees = if (!isExpanded) 90f else 270f | ||
|
||
Row( | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 6.dp) | ||
.clickable { onTapped() }, | ||
) { | ||
Text( | ||
title, | ||
fontFamily = Inter, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 16.sp, | ||
color = ColorStone500, | ||
) | ||
Icon( | ||
painter = painterResource(id = R.drawable.chevron), | ||
contentDescription = "Collapse menu button", | ||
tint = ColorStone600, | ||
modifier = Modifier | ||
.rotate(degrees) | ||
.height(12.dp) | ||
) | ||
} | ||
} |
Oops, something went wrong.