kiel icon indicating copy to clipboard operation
kiel copied to clipboard

how to define viewTypes with conditions

Open MahmoudMabrok opened this issue 3 years ago • 5 comments

now we can register viewTypes but README has no way to determine which viewType is created at spefici position i.e how to make views has two types Head, Sub

  • Head with odd positions
  • Sub with even positions

MahmoudMabrok avatar Aug 30 '20 11:08 MahmoudMabrok

Hi @MahmoudMabrok,

Thank you for your question.

You specify this while you are defining your RecyclerViewHolder<T>.

You need to define HeadRecyclerViewHolder and SubRecyclerViewHolderfor your Head and Sub.

In the list, which you provide the adapter, you should do that mapping.

val list = listOf("abc", "xyz", "qwe", ...)

...
// mapper
val dataSource = list.mapIndexed{index, item ->
           if (index ÷ 2 == 0) Head(item) else Sub(item) 
}

adapter.submitList(dataSource)

In that way, you can test your mapper.

I hope everything is clear now.

Sincerely Ibrahim

ibrahimyilmaz avatar Aug 30 '20 13:08 ibrahimyilmaz

it will more better if it added with register function

MahmoudMabrok avatar Aug 30 '20 13:08 MahmoudMabrok

Do you mean putting type in the register function?

ibrahimyilmaz avatar Aug 30 '20 13:08 ibrahimyilmaz

yes,or a way to determine type add function like register but it return viewType and with register we can select which type

i think it need brain storm to get right design

MahmoudMabrok avatar Aug 30 '20 14:08 MahmoudMabrok

Actually type is coming by RecyclerViewHolder. As it is reified Kiel could understand which type it is.

I appreciate your support. Any syntax alternatives are welcome. also you may consider putting new syntax alternative under this issue #34.

ibrahimyilmaz avatar Aug 30 '20 14:08 ibrahimyilmaz