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 check value and set image to ImageWidget #257

Closed Diy2210 closed 4 years ago

Diy2210 commented 4 years ago

Hi, how I can check value in override fun createWidget like if/else or something like that and select one or another image.

I use List Widget and Table Units:

My ListWidget: Снимок экрана 2020-07-07 в 12 58 53

Fun Table Units: Снимок экрана 2020-07-07 в 12 59 01

My class Unit Items where I make image: Снимок экрана 2020-07-07 в 12 59 20

Result: Снимок экрана 2020-07-07 в 12 59 39

Alex009 commented 4 years ago

@Diy2210 widget creation called only on create of Table item, but when UITableView/RecyclerView reuse already created item you got notification in data: LiveData<StatusModel>, so you should use not image = const(image) but image = data.map { .... } where in map you convert StatusModel to correct Image

Diy2210 commented 4 years ago

Cool!!! All works! TNX!!!

upd code: Снимок экрана 2020-07-07 в 16 51 54

result: Снимок экрана 2020-07-07 в 16 51 31

Alex009 commented 4 years ago

@Diy2210 instead of data.value use it - already passed into lambda

Diy2210 commented 4 years ago

@Diy2210 instead of data.value use it - already passed into lambda

OK, TNX again!!!