fix(ui): 修复切换年月视图动画期间滑动导致的小月历错位 bug
This commit is contained in:
parent
53086f38e0
commit
e663ed5c8e
@ -170,11 +170,6 @@ fun CalendarMonthView(
|
|||||||
var isMenuExpanded by remember { mutableStateOf(false) }
|
var isMenuExpanded by remember { mutableStateOf(false) }
|
||||||
var showDatePicker by remember { mutableStateOf(false) }
|
var showDatePicker by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// 视图切换时自动关闭菜单
|
|
||||||
LaunchedEffect(isYearView) {
|
|
||||||
isMenuExpanded = false
|
|
||||||
}
|
|
||||||
|
|
||||||
val pagerState = rememberPagerState(initialPage = START_PAGE, pageCount = { Int.MAX_VALUE })
|
val pagerState = rememberPagerState(initialPage = START_PAGE, pageCount = { Int.MAX_VALUE })
|
||||||
|
|
||||||
// 年视图分页器
|
// 年视图分页器
|
||||||
@ -183,6 +178,14 @@ fun CalendarMonthView(
|
|||||||
pageCount = { Int.MAX_VALUE }
|
pageCount = { Int.MAX_VALUE }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 视图切换时自动关闭菜单并重置年视图 Pager
|
||||||
|
LaunchedEffect(isYearView) {
|
||||||
|
isMenuExpanded = false
|
||||||
|
if (isYearView && yearPagerState.currentPage != START_PAGE) {
|
||||||
|
yearPagerState.scrollToPage(START_PAGE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 年视图翻页时同步 yearViewYear(跟踪 settled page 差值)
|
// 年视图翻页时同步 yearViewYear(跟踪 settled page 差值)
|
||||||
LaunchedEffect(yearPagerState) {
|
LaunchedEffect(yearPagerState) {
|
||||||
var lastSettledPage = yearPagerState.currentPage
|
var lastSettledPage = yearPagerState.currentPage
|
||||||
@ -299,7 +302,7 @@ fun CalendarMonthView(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clipToBounds()
|
.clipToBounds()
|
||||||
.sharedBounds(
|
.sharedBounds(
|
||||||
sharedContentState = rememberSharedContentState(key = "month_grid_$currentMonth"),
|
sharedContentState = rememberSharedContentState(key = "month_grid_${currentYear}_$currentMonth"),
|
||||||
animatedVisibilityScope = this@AnimatedContent,
|
animatedVisibilityScope = this@AnimatedContent,
|
||||||
boundsTransform = { _, _ ->
|
boundsTransform = { _, _ ->
|
||||||
spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = Spring.DampingRatioNoBouncy)
|
spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = Spring.DampingRatioNoBouncy)
|
||||||
@ -338,6 +341,7 @@ fun CalendarMonthView(
|
|||||||
)
|
)
|
||||||
HorizontalPager(
|
HorizontalPager(
|
||||||
state = yearPagerState,
|
state = yearPagerState,
|
||||||
|
userScrollEnabled = (this@AnimatedContent.transition.currentState == this@AnimatedContent.transition.targetState),
|
||||||
beyondViewportPageCount = 0,
|
beyondViewportPageCount = 0,
|
||||||
flingBehavior = PagerDefaults.flingBehavior(state = yearPagerState),
|
flingBehavior = PagerDefaults.flingBehavior(state = yearPagerState),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -366,7 +370,7 @@ fun CalendarMonthView(
|
|||||||
},
|
},
|
||||||
monthModifier = { month ->
|
monthModifier = { month ->
|
||||||
Modifier.sharedBounds(
|
Modifier.sharedBounds(
|
||||||
sharedContentState = rememberSharedContentState(key = "month_grid_$month"),
|
sharedContentState = rememberSharedContentState(key = "month_grid_${pageYear}_$month"),
|
||||||
animatedVisibilityScope = this@AnimatedContent,
|
animatedVisibilityScope = this@AnimatedContent,
|
||||||
boundsTransform = { _, _ ->
|
boundsTransform = { _, _ ->
|
||||||
spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = Spring.DampingRatioNoBouncy)
|
spring(stiffness = Spring.StiffnessMediumLow, dampingRatio = Spring.DampingRatioNoBouncy)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user