ModalBottomSheetLayout我在 Jetpack Compose 中使用。每当它显示为 时modalBottomSheetState.show(),它都会显示HalfExpanded或 ,Expanded具体取决于其内容的高度。这是来自源代码:
val anchors = if (sheetHeight < fullHeight / 2) {
mapOf(
fullHeight to Hidden,
fullHeight - sheetHeight to Expanded
)
} else {
mapOf(
fullHeight to Hidden,
fullHeight / 2 to HalfExpanded,
max(0f, fullHeight - sheetHeight) to Expanded
)
}
Modifier.swipeable(
state = sheetState,
anchors = anchors,
orientation = Orientation.Vertical,
enabled = sheetState.currentValue != Hidden,
resistance = null
)
Run Code Online (Sandbox Code Playgroud)
然后show()像这里一样工作:
internal val isHalfExpandedEnabled: Boolean
get() …Run Code Online (Sandbox Code Playgroud) 我正在尝试迭代List对象,对于每个对象我想显示一个可组合的卡片。问题是您无法从list.forEach{} 括号内调用可组合函数。
代码:
@Composable
fun Greeting(listy : List<SomethingForLater>) {
LazyColumn {
listy.forEach {
//error here
testCard(somethingForLater = it)
}
}
}
@Composable
fun testCard(somethingForLater: SomethingForLater){
val theme = MaterialTheme
Card(shape = theme.shapes.small,backgroundColor = theme.colors.secondary){
Column {
Row {
Text(
text = somethingForLater.task,
modifier = Modifier.padding(start = 5.dp,
top = 3.dp,bottom = 3.dp
),
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
)
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我们的应用程序中有底部导航,我们希望在屏幕中添加滑动行为,这样如果用户向右/向左滑动,那么他/她应该导航到下一个屏幕。
我知道伴奏有HorizontalPager制表符。但我想知道我们是否可以通过底部导航来实现这种行为。
我想在我的生成器代码上放置断点,但我不知道如何在调试模式下运行该命令。
我使用source_gen和编写了生成器build_runner
class MyGenerator extends GeneratorForAnnotation<Todo> {
@override
FutureOr<String> generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
return "// Hey! Annotation found!";
}
}
Run Code Online (Sandbox Code Playgroud) FlatListofReact Native有一个属性viewabilityConfigCallbackPairs,您可以在其中设置:
viewabilityConfig: {
itemVisiblePercentThreshold: 50,
waitForInteraction: true,
}
Run Code Online (Sandbox Code Playgroud)
以 50% 的阈值以及交互或滚动后检测列表的可见项目。
Jetpack Compose 也有类似的东西吗?
有LazyListState一些布局信息。但我想知道这个用例是否有任何内置组件/属性。
编辑
我有一个卡片视图列表,我想检测哪些卡片项目(至少 50% 的卡片可见)在显示屏上可见。但只有当用户单击卡片或滚动列表时才需要检测到它。
android android-jetpack-compose android-jetpack-compose-list android-jetpack-compose-lazy-column
android ×3
android-jetpack-compose-lazy-column ×1
android-jetpack-compose-list ×1
build-runner ×1
dart ×1
flutter ×1