[英]Jetpack Compose - Lazy loading of data in Accompanist HorizontalPager
[英]Jetpack compose Accompanist HorizontalPager doesn't detect swipes
我的屏幕上有一个HorizontalPager()
,它没有检测到滑动。 只是为了测试我通过文档创建了默认的HorizontalPager()
刚刚粘贴在我的屏幕上
HorizontalPager(count = 10) { page ->
Text(
text = "Page: $page",
modifier = Modifier.fillMaxWidth()
)
}
而且它也不会滑动。 我检查了HorizontalPager()
是否有任何屏幕输入并添加了
Modifier
.pointerInput(Unit) {
detectTapGestures { Log.d("Screen Input", "Pager tap") }
}
所以检测到选项卡,这意味着寻呼机没有被另一个 UI 元素阻止。 但是默认滑动是行不通的。 元素大小是硬编码的。 库版本 — 0.23.1
更新
部分真实代码
Column(
modifier = Modifier
.fillMaxSize()
.background(Colors.Background.light)
.verticalScroll(scrollState)
) {
val itemWidth = LocalConfiguration.current.screenWidthDp
val itemHeight = itemWidth * 1.42
val imageCornerRadiusInPx =
with(LocalDensity.current) { (itemWidth / 2f).dp.toPx() }
HorizontalPager(
count = currentProfile.photos.size
) { page ->
currentProfile?.photos?.get(page)?.url.let { url ->
Box(
contentAlignment = Alignment.TopEnd
) {
Image(
modifier = Modifier
.fillMaxWidth()
.height(itemHeight.dp),
painter = rememberImagePainter(
data = url,
builder = {
transformations(
RoundedCornersTransformation(
bottomLeft = imageCornerRadiusInPx,
bottomRight = imageCornerRadiusInPx,
)
)
}
),
contentDescription = null,
)
}
}
}
currentProfile.photos
不是 null 并且大小 > 1
存在不明显的问题。 我们嵌套了 HorizontalPager,如“Pager in Pager”+ TabLayout。 所以我的同事在顶级 HorizontalPager 中禁用了水平滚动输入,这就是为什么所有嵌套的 HorizontalPager 也被禁用的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.