fix: 恢复折叠动画 Phase 2 下方行偏移,移除 showWeekPager 切换
- 恢复 CalendarMonthPage 中 isBelow 行的 `- phase2 * belowRowsHeight` (2592a5f 误删导致展开时下方行原地淡入而非滑出) - 移除 CalendarMonthView 的 showWeekPager + AnimatedContent 切换 (完全折叠后下拉拖拽时只显示 WeekPager 单周,上下空白) - 回退到始终显示 CalendarPager,由 CalendarMonthPage 处理折叠动画 - 添加详细动画调试日志(Page/WeekRow/View 三层) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2592a5fa55
commit
20425e392c
@ -106,6 +106,17 @@ fun CalendarMonthPage(
|
|||||||
val anchorIndex = remember(year, month, selectedDate) {
|
val anchorIndex = remember(year, month, selectedDate) {
|
||||||
weeks.indexOfFirst { week -> week.any { it.date == selectedDate } }
|
weeks.indexOfFirst { week -> week.any { it.date == selectedDate } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 全局动画参数日志(每次重组)
|
||||||
|
val pageFrameNs = System.nanoTime()
|
||||||
|
Log.d(
|
||||||
|
TAG_CMP,
|
||||||
|
"Page[$year-$month]: anchorIndex=$anchorIndex weeksSize=${weeks.size} " +
|
||||||
|
"phase1End=${if (anchorIndex > 0 && weeks.size > 1) anchorIndex.toFloat() / (weeks.size - 1) else 0f} " +
|
||||||
|
"effectiveWeeks=$effectiveWeeks rowHeightPx=$rowHeightPx " +
|
||||||
|
"collapseProgress=$collapseProgress frameNs=$pageFrameNs"
|
||||||
|
)
|
||||||
|
|
||||||
val totalHeightDp = if (rowHeightPx > 0) {
|
val totalHeightDp = if (rowHeightPx > 0) {
|
||||||
val h = rowHeightPx.toFloat()
|
val h = rowHeightPx.toFloat()
|
||||||
val totalPx = h * (1 + (effectiveWeeks - 1) * (1f - collapseProgress))
|
val totalPx = h * (1 + (effectiveWeeks - 1) * (1f - collapseProgress))
|
||||||
@ -188,7 +199,7 @@ private fun WeekRow(
|
|||||||
!hasAnchor -> weekIndex * h - collapseProgress * weeksSize * h
|
!hasAnchor -> weekIndex * h - collapseProgress * weeksSize * h
|
||||||
isAnchor -> anchorIndex * h * (1f - phase1)
|
isAnchor -> anchorIndex * h * (1f - phase1)
|
||||||
isAbove -> weekIndex * h - phase1 * anchorIndex * h
|
isAbove -> weekIndex * h - phase1 * anchorIndex * h
|
||||||
isBelow -> weekIndex * h - phase1 * anchorIndex * h
|
isBelow -> weekIndex * h - phase1 * anchorIndex * h - phase2 * belowRowsHeight
|
||||||
else -> weekIndex * h
|
else -> weekIndex * h
|
||||||
}
|
}
|
||||||
} else 0f
|
} else 0f
|
||||||
@ -201,9 +212,17 @@ private fun WeekRow(
|
|||||||
else -> 1f
|
else -> 1f
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAnchor || isBelow) {
|
val frameTimeNs = System.nanoTime()
|
||||||
Log.d(TAG_CMP, "WeekRow[$weekIndex]: isAnchor=$isAnchor isAbove=$isAbove isBelow=$isBelow phase1=$phase1 phase2=$phase2 yOffsetPx=$yOffsetPx rowAlpha=$rowAlpha collapseProgress=$collapseProgress")
|
Log.d(
|
||||||
}
|
TAG_CMP,
|
||||||
|
"WeekRow[$weekIndex]: " +
|
||||||
|
"isAnchor=$isAnchor isAbove=$isAbove isBelow=$isBelow " +
|
||||||
|
"phase1=$phase1 phase2=$phase2 phase1End=$phase1End " +
|
||||||
|
"belowRowsHeight=$belowRowsHeight rowHeightPx=$rowHeightPx " +
|
||||||
|
"yOffsetPx=$yOffsetPx rowAlpha=$rowAlpha " +
|
||||||
|
"collapseProgress=$collapseProgress " +
|
||||||
|
"frameNs=$frameTimeNs"
|
||||||
|
)
|
||||||
|
|
||||||
if (rowAlpha > 0.01f) {
|
if (rowAlpha > 0.01f) {
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@ -48,6 +48,7 @@ import androidx.compose.material3.MaterialTheme
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.SideEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
@ -69,7 +70,6 @@ import androidx.compose.ui.platform.LocalDensity
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.datetime.DatePeriod
|
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import kotlinx.datetime.TimeZone
|
import kotlinx.datetime.TimeZone
|
||||||
import kotlinx.datetime.number
|
import kotlinx.datetime.number
|
||||||
@ -82,6 +82,7 @@ import plus.rua.project.composeTraceEndSection
|
|||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.time.Clock
|
import kotlin.time.Clock
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日历主界面,包含月/周视图切换、折叠动画和年视图共享元素转场。
|
* 日历主界面,包含月/周视图切换、折叠动画和年视图共享元素转场。
|
||||||
@ -118,6 +119,9 @@ fun CalendarMonthView(
|
|||||||
animationSpec = spring(stiffness = Spring.StiffnessMedium),
|
animationSpec = spring(stiffness = Spring.StiffnessMedium),
|
||||||
label = "collapseProgress"
|
label = "collapseProgress"
|
||||||
)
|
)
|
||||||
|
SideEffect {
|
||||||
|
Log.d("CalendarExpandAnim", "View: target=$collapseProgress animated=$animatedCollapseProgress isCollapsed=$isCollapsed")
|
||||||
|
}
|
||||||
|
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
@ -238,7 +242,6 @@ fun CalendarMonthView(
|
|||||||
CalendarPagerArea(
|
CalendarPagerArea(
|
||||||
selectedDate = selectedDate,
|
selectedDate = selectedDate,
|
||||||
today = today,
|
today = today,
|
||||||
isCollapsed = isCollapsed,
|
|
||||||
collapseProgress = animatedCollapseProgress,
|
collapseProgress = animatedCollapseProgress,
|
||||||
showLegalHoliday = showLegalHoliday,
|
showLegalHoliday = showLegalHoliday,
|
||||||
rowHeightPx = rowHeightPx,
|
rowHeightPx = rowHeightPx,
|
||||||
@ -463,7 +466,6 @@ private fun MenuIcon(color: Color, modifier: Modifier = Modifier) {
|
|||||||
private fun CalendarPagerArea(
|
private fun CalendarPagerArea(
|
||||||
selectedDate: LocalDate,
|
selectedDate: LocalDate,
|
||||||
today: LocalDate,
|
today: LocalDate,
|
||||||
isCollapsed: Boolean,
|
|
||||||
collapseProgress: Float,
|
collapseProgress: Float,
|
||||||
showLegalHoliday: Boolean,
|
showLegalHoliday: Boolean,
|
||||||
rowHeightPx: Int,
|
rowHeightPx: Int,
|
||||||
@ -520,50 +522,6 @@ private fun CalendarPagerArea(
|
|||||||
modifier
|
modifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// 延迟切换:等折叠 spring 动画完全稳定后再切到 WeekPager,避免视觉跳跃
|
|
||||||
var showWeekPager by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
LaunchedEffect(isCollapsed, collapseProgress) {
|
|
||||||
if (isCollapsed && collapseProgress >= 0.999f) {
|
|
||||||
delay(50)
|
|
||||||
showWeekPager = true
|
|
||||||
} else if (!isCollapsed) {
|
|
||||||
showWeekPager = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimatedContent(
|
|
||||||
targetState = showWeekPager,
|
|
||||||
transitionSpec = { fadeIn(tween(80)) togetherWith fadeOut(tween(80)) },
|
|
||||||
label = "pager_switch",
|
|
||||||
modifier = pagerModifier
|
|
||||||
) { useWeekPager ->
|
|
||||||
if (useWeekPager) {
|
|
||||||
WeekPager(
|
|
||||||
selectedDate = selectedDate,
|
|
||||||
today = today,
|
|
||||||
onDateClick = onDateClick,
|
|
||||||
onWeekChanged = { weekMonday ->
|
|
||||||
val weekSunday = weekMonday.plus(DatePeriod(days = 6))
|
|
||||||
val date = when {
|
|
||||||
today in weekMonday..weekSunday -> today
|
|
||||||
weekMonday.month != weekSunday.month -> {
|
|
||||||
if (weekMonday < selectedDate) {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
LocalDate(weekSunday.year, weekSunday.month.number, 1)
|
|
||||||
} else {
|
|
||||||
weekMonday
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> weekMonday
|
|
||||||
}
|
|
||||||
onDateClick(date)
|
|
||||||
},
|
|
||||||
shiftKindAt = shiftKindAt,
|
|
||||||
showLegalHoliday = showLegalHoliday,
|
|
||||||
modifier = Modifier
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
CalendarPager(
|
CalendarPager(
|
||||||
selectedDate = selectedDate,
|
selectedDate = selectedDate,
|
||||||
today = today,
|
today = today,
|
||||||
@ -576,10 +534,8 @@ private fun CalendarPagerArea(
|
|||||||
showLegalHoliday = showLegalHoliday,
|
showLegalHoliday = showLegalHoliday,
|
||||||
onRowHeightMeasured = onRowHeightMeasured,
|
onRowHeightMeasured = onRowHeightMeasured,
|
||||||
pagerState = pagerState,
|
pagerState = pagerState,
|
||||||
modifier = Modifier
|
modifier = pagerModifier
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user