fix: Center text alignment in CollapsingProfileHeader for consistent layout
This commit is contained in:
@@ -449,11 +449,9 @@ private fun CollapsingProfileHeader(
|
||||
val avatarFontSize = androidx.compose.ui.unit.lerp(40.sp, 0.sp, collapseProgress)
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 📝 TEXT - moves from center to left corner
|
||||
// 📝 TEXT - always centered
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
val textExpandedX = screenWidthDp / 2
|
||||
val textCollapsedX = 48.dp + 12.dp // After back button + gap (left aligned)
|
||||
val textX = androidx.compose.ui.unit.lerp(textExpandedX, textCollapsedX, collapseProgress)
|
||||
val textX = screenWidthDp / 2 // Always center
|
||||
|
||||
val textExpandedY = statusBarHeight + 32.dp + AVATAR_SIZE_EXPANDED + 48.dp
|
||||
val textCollapsedY = statusBarHeight + COLLAPSED_HEADER_HEIGHT / 2
|
||||
@@ -463,9 +461,6 @@ private fun CollapsingProfileHeader(
|
||||
val nameFontSize = androidx.compose.ui.unit.lerp(24.sp, 18.sp, collapseProgress)
|
||||
val onlineFontSize = androidx.compose.ui.unit.lerp(14.sp, 13.sp, collapseProgress)
|
||||
|
||||
// Text alignment interpolation (0 = center, 1 = left)
|
||||
val textCenterOffset = androidx.compose.ui.unit.lerp(80.dp, 0.dp, collapseProgress)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -562,18 +557,19 @@ private fun CollapsingProfileHeader(
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// 📝 TEXT BLOCK - Name + Online, moves to corner, left-aligned when collapsed
|
||||
// 📝 TEXT BLOCK - Name + Online, always centered
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.offset(x = textX - textCenterOffset, y = textY)
|
||||
.align(Alignment.TopCenter)
|
||||
.offset(y = textY)
|
||||
.graphicsLayer {
|
||||
val centerOffsetY = with(density) {
|
||||
androidx.compose.ui.unit.lerp(24.dp, 18.dp, collapseProgress).toPx()
|
||||
}
|
||||
translationY = -centerOffsetY
|
||||
},
|
||||
horizontalAlignment = Alignment.Start
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = name,
|
||||
@@ -582,18 +578,17 @@ private fun CollapsingProfileHeader(
|
||||
color = Color.White,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.widthIn(max = 220.dp)
|
||||
modifier = Modifier.widthIn(max = 220.dp),
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
|
||||
// Online text - centered in expanded, left in collapsed
|
||||
val onlineCenterOffset = androidx.compose.ui.unit.lerp(65.dp, 0.dp, collapseProgress)
|
||||
// Online text - always centered
|
||||
Text(
|
||||
text = "online",
|
||||
fontSize = onlineFontSize,
|
||||
color = Color(0xFF4CAF50),
|
||||
modifier = Modifier.offset(x = onlineCenterOffset)
|
||||
color = Color(0xFF4CAF50)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user