airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.5k stars 733 forks source link

hot to override getItemViewType in carousel #1171

Closed miami22 closed 3 years ago

miami22 commented 3 years ago

hi guys and thank you for this awesome library. i am changing my app's main page using epoxy and epoxy has perfect futures. so in regular recyclerview adapter i usually override this method to have fix item ids : override fun getItemViewType(position: Int): Int { return position } i dont know how to have epoxy carousel act the same way . im in emergency situation please help. thanks .

elihart commented 3 years ago

item id and item viewtype are two very different things. To set the id you use the id functions on the model. if you want to override the view type you can subclass you model and override getViewType to return whatever you want - but generally with epoxy that should not be necessary

miami22 commented 3 years ago

consider i want to show or hide part of element using item id inside EpoxyModelWithHolder if (id==0 || id ==1)holder.seenright.visibility=View.GONE this works at first load of carousel but when i scroll to end of carousel and come back to first , views have changed and items with specified ids havent specified properties. how can i handle this?

elihart commented 3 years ago

you should not be using item ids to control item visibility. instead models should be rebuilt and updated appropriately

miami22 commented 3 years ago

solved with overriding getViewType and returning unique id. thank you