小编Mar*_*rat的帖子

使 ModalBottomSheetLayout 始终展开

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)

android android-jetpack-compose

17
推荐指数
3
解决办法
6572
查看次数

编写 foreach 循环:@Composable 调用只能在 @Composable 函数的上下文中发生

我正在尝试迭代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)

android android-jetpack-compose

10
推荐指数
2
解决办法
1万
查看次数

如何向屏幕添加滑动行为?

我们的应用程序中有底部导航,我们希望在屏幕中添加滑动行为,这样如果用户向右/向左滑动,那么他/她应该导航到下一个屏幕。

我知道伴奏HorizontalPager制表符。但我想知道我们是否可以通过底部导航来实现这种行为。

android-jetpack-compose

9
推荐指数
1
解决办法
5922
查看次数

如何在 Intellij 想法中使用调试模式运行 flutter 'packages pub run build_runner build'?

我想在我的生成器代码上放置断点,但我不知道如何在调试模式下运行该命令。

我使用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)

intellij-idea dart flutter build-runner

7
推荐指数
1
解决办法
911
查看次数

如何检查 Jetpack Compose 中列表项的可见性

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

3
推荐指数
1
解决办法
7750
查看次数