1

我是 Kotlin 的新手,我想使用 Facebook 的 litho 库,我找到了创建回收器配置的 java 方法,但我无法在 Kotlin 中做同样的事情。

              RecyclerCollectionComponent.create(c)
                  .disablePTR(true)
                  .recyclerConfiguration(new ListRecyclerConfiguration(LinearLayoutManager.HORIZONTAL, /*reverse layout*/ false, SNAP_TO_CENTER))
                  .section(
                      DataDiffSection.create(c)
                          .data(generateData(32))
                          .renderEventHandler(ListSection.onRender(c))
                          .build())
                  .canMeasureRecycler(true))

那么我将如何在 Kotlin 中做到这一点?到目前为止,我有这个,但它不起作用。

.recyclerConfiguration(
            ListRecyclerConfiguration.create()
                .linearLayoutInfoFactory(LinearLayoutInfoFactory {
                    c, LinearLayoutManager.HORIZONTAL, false
                })
                .build()
        )

好像不太喜欢Linearlayoutinfo工厂的构造函数,我查了github的例子也没找到。如果我对 Java 到 Kotlin 的转换有更多的了解,我可能会理解如何轻松地做到这一点。

编辑:来自 Android Studio 的错误:

意外标记(使用 ';' 在同一行分隔表达式)

我想这是因为语法,但我认为真正的问题是围绕 LinearLayoutInfoFactory 的构造。

4

1 回答 1

0

我设法让这个工作,问题是围绕回收器配置的创建,我试图初始化接口而不是接口的实际实现。

RecyclerCollectionComponent.create(c)
        .recyclerConfiguration(
            ListRecyclerConfiguration.create()
                .orientation(LinearLayoutManager.HORIZONTAL)
                .snapMode(0)
                .build()
        )
        .section(
            DataDiffSection.create<DiscoverListDataModel>(SectionContext(c))
                .data(dataModels)
                .renderEventHandler(DiscoverListComponent.onRender(c))
                .onCheckIsSameItemEventHandler(DiscoverListComponent.isSameItem(c))
                .onCheckIsSameContentEventHandler(DiscoverListComponent.isSameContent(c))
                .build()
        )
        .canMeasureRecycler(true)
        .disablePTR(true)
        .build()
于 2018-12-21T07:36:22.603 回答