icerockdev / moko-widgets

Multiplatform UI DSL with screen management in common code for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev
Apache License 2.0
387 stars 32 forks source link

Help add items to ListWidget #256

Closed Diy2210 closed 4 years ago

Diy2210 commented 4 years ago

Hi, I try add items to ListWidget, type arrayOf. How can I do this?

My Array: Снимок экрана 2020-07-06 в 15 55 35

My Live Data: Снимок экрана 2020-07-06 в 15 57 10

My ListWidget: Снимок экрана 2020-07-06 в 15 56 52

Alex009 commented 4 years ago

just change arrayOf to listOf and use List instead of Array. or do viewModel.diskInfoArray.map { it.toList() } to convert Array into List

Diy2210 commented 4 years ago

I try convert Array to List, but my MutableLiveData type Model and ListWidget work only with TableUnitItem. I need convert MutableLiveData to TableUnitItem?

Снимок экрана 2020-07-06 в 16 58 29

Снимок экрана 2020-07-06 в 16 58 15

Alex009 commented 4 years ago

oh, yes. you should map your model into TableUnitItem. For example you can use standard unit items - https://github.com/icerockdev/moko-units/blob/master/units-basic/src/commonMain/kotlin/dev/icerock/moko/units/basic/table/BasicTableUnitItem.kt or you can create WidgetTableUnitItem just like here - https://github.com/icerockdev/moko-widgets/blob/master/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/units/UserUnitWidget.kt#L94

Diy2210 commented 4 years ago

Thanks, I got it. All works!