Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

Implement Swift GlassPopupMenu liquid morphing transition and upgrade Settings Appearance selector to LiquidButton components

Chethan6163f0ec90a2643
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt
index 1036e77..af095b8 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/HomeScreen.kt
@@ -55,6 +55,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.PathParser
import androidx.compose.ui.platform.LocalContext
@@ -63,6 +64,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.util.lerp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
@@ -117,6 +119,15 @@ fun HomeScreen(
var b3Visible by remember { mutableStateOf(false) }
var b4Visible by remember { mutableStateOf(false) }
+ val morphProgress by androidx.compose.animation.core.animateFloatAsState(
+ targetValue = if (selectedRecent != null) 1f else 0f,
+ animationSpec = spring(
+ dampingRatio = 0.58f,
+ stiffness = 220f
+ ),
+ label = "morphProgress"
+ )
+
androidx.compose.runtime.LaunchedEffect(selectedRecent) {
if (selectedRecent != null) {
b1Visible = false
@@ -462,18 +473,25 @@ fun HomeScreen(
selectedRecent?.let { recent ->
AnimatedVisibility(
visible = true,
- enter = scaleIn(
- animationSpec = spring(
- dampingRatio = Spring.DampingRatioMediumBouncy,
- stiffness = Spring.StiffnessMediumLow
- ),
- initialScale = 0.65f
- ) + fadeIn(animationSpec = spring(stiffness = Spring.StiffnessMediumLow)),
- exit = scaleOut(targetScale = 0.75f) + fadeOut()
+ enter = fadeIn(animationSpec = spring(stiffness = Spring.StiffnessMediumLow)),
+ exit = fadeOut(animationSpec = spring(stiffness = Spring.StiffnessMediumLow))
) {
Column(
Modifier
.padding(horizontal = 24.dp)
+ .graphicsLayer {
+ val scaleXValue = lerp(0.35f, 1.0f, morphProgress)
+ val scaleYValue = lerp(0.20f, 1.0f, morphProgress)
+ val translateYValue = lerp(100f, 0f, morphProgress) * density
+ scaleX = scaleXValue
+ scaleY = scaleYValue
+ translationY = translateYValue
+ alpha = morphProgress.coerceIn(0f, 1f)
+ transformOrigin = TransformOrigin(0.5f, 0.85f)
+ shadowElevation = (18f * morphProgress).dp.toPx()
+ shape = RoundedCornerShape(32.dp)
+ clip = true
+ }
.clip(RoundedCornerShape(32.dp))
.background(if (isLight) Color.White.copy(0.88f) else Color(0xFF1C1E26).copy(0.88f))
.border(
@@ -481,11 +499,6 @@ fun HomeScreen(
if (isLight) Color.White.copy(0.95f) else Color.White.copy(0.18f),
RoundedCornerShape(32.dp)
)
- .graphicsLayer {
- shadowElevation = 16f.dp.toPx()
- shape = RoundedCornerShape(32.dp)
- clip = true
- }
.clickable { /* Consume inner taps */ }
.padding(horizontal = 18.dp, vertical = 16.dp),
verticalArrangement = Arrangement.spacedBy(14.dp),
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
index c936d74..6163955 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt
@@ -242,52 +242,44 @@ fun SettingsScreen(
BasicText("Appearance", style = TextStyle(text, 17.sp, fontWeight = FontWeight.SemiBold))
}
- // Navbar-like segmented theme mode bar
+ // Liquid Glass Theme Mode Selector
Row(
- Modifier
- .fillMaxWidth()
- .clip(RoundedCornerShape(16.dp))
- .background(if (isLight) Color.Black.copy(0.04f) else Color.White.copy(0.06f))
- .padding(4.dp),
- horizontalArrangement = Arrangement.spacedBy(4.dp)
+ Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
- data class ThemeOption(val idx: Int, val label: String, val icon: ImageVector)
+ data class ThemeOption(val idx: Int, val label: String, val icon: ImageVector, val activeColor: Color)
val options = listOf(
- ThemeOption(0, "System", Icons.Rounded.PhoneAndroid),
- ThemeOption(1, "Light", Icons.Rounded.LightMode),
- ThemeOption(2, "Dark", Icons.Rounded.DarkMode)
+ ThemeOption(0, "System", Icons.Rounded.PhoneAndroid, Color(0xFF0088FF)),
+ ThemeOption(1, "Light", Icons.Rounded.LightMode, Color(0xFFFFA726)),
+ ThemeOption(2, "Dark", Icons.Rounded.DarkMode, Color(0xFF7C4DFF))
)
options.forEach { option ->
val isSelected = themeMode == option.idx
- val activeColor = when (option.idx) {
- 1 -> Color(0xFFFFA726)
- 2 -> Color(0xFF7C4DFF)
- else -> Color(0xFF0088FF)
- }
- Row(
- Modifier
- .weight(1f)
- .clip(RoundedCornerShape(12.dp))
- .background(if (isSelected) activeColor else Color.Transparent)
- .clickable { onThemeModeChanged(option.idx) }
- .padding(vertical = 10.dp),
- horizontalArrangement = Arrangement.Center,
- verticalAlignment = Alignment.CenterVertically
+ LiquidButton(
+ onClick = { onThemeModeChanged(option.idx) },
+ backdrop = backdrop,
+ tint = if (isSelected) option.activeColor else Color.Transparent,
+ surfaceColor = if (isSelected) option.activeColor.copy(0.18f) else (if (isLight) Color.Black.copy(0.04f) else Color.White.copy(0.06f)),
+ modifier = Modifier.weight(1f)
) {
- Icon(
- option.icon, null,
- Modifier.size(17.dp),
- if (isSelected) Color.White else sub
- )
- Spacer(Modifier.width(6.dp))
- BasicText(
- option.label,
- style = TextStyle(
- if (isSelected) Color.White else sub,
- 13.sp,
- fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(6.dp)
+ ) {
+ Icon(
+ option.icon, null,
+ Modifier.size(17.dp),
+ if (isSelected) Color.White else label
+ )
+ BasicText(
+ option.label,
+ style = TextStyle(
+ if (isSelected) Color.White else label,
+ 13.sp,
+ fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium
+ )
)
- )
+ }
}
}
}