Loosing attribute state for first time scrolling.
See original GitHub issue data class Model(
private val media: Media,
private val thmPath: String,
private val clickListener: (Model, Media, Boolean) -> Any?,
private val longClickListener: (Model, Media, Boolean) -> Any?
) : EpoxyModel<MediaItemView>(), MediaEpoxyModel {
@EpoxyAttribute private var isSelected: Boolean = false
private var mediaItemView: MediaItemView? = null
override fun getDefaultLayout() = R.layout.media_item_view
override fun shouldSaveViewState(): Boolean = true
override fun bind(view: MediaItemView) {
Timber.d("BIND model: ${this.id()} hash: ${hashCode()} isSelected: $isSelected")
mediaItemView = view
view.bind(media, thmPath)
Somehow isSelected
is getting reset for firsttime scrolling.
Steps:
Select first grid item through long press which set
isSelected
true. Scroll down ~30 items with header Scroll up so bind perform for that selected item, but somehow gettingisSelected=false
This problem happens only first-time selection, else getting a perfect attribute value as true
if selected.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Refresh Page and Keep Scroll Position - Stack Overflow
Very good and simple solution. I made a few changes. Browsers will still store this data even after the browser is closed. I...
Read more >How to fight the <body> scroll. First of all - Medium
First of all — WHY one have to fight the scroll? · You shall not be able to click on it. Not be...
Read more >Smooth Scrolling | CSS-Tricks
Scroll to specific values // scrollTo is the same window.scroll({ ... Yours is the first script that was so clearly layed out that...
Read more >CSS Position Sticky Tutorial With Examples[Complete Guide]
But while scrolling, we lose the image and just the text remains. If the text is describing the image, its meaning or its...
Read more >scroll-behavior - CSS: Cascading Style Sheets - MDN Web Docs
The scroll-behavior CSS property sets the behavior for a scrolling box when scrolling is triggered by the navigation or CSSOM scrolling APIs ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This isn’t the correct way to use models. They should be immutable, you can’t change them once they are added to the EpoxyController. Read more in the wiki https://github.com/airbnb/epoxy/wiki/Epoxy-Controller
the correct way to handle this is to have a callback to your controller to update some state there that keeps a list of all selected items. when you build models you should set the model prop based on that list. When the list is updated models should be rebuilt.
Thank you @elihart,
requestBuildModels
working as expected