question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 getting isSelected=false

This problem happens only first-time selection, else getting a perfect attribute value as true if selected.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
elihartcommented, May 23, 2018

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.

0reactions
gevariya-ajitcommented, May 23, 2018

Thank you @elihart, requestBuildModels working as expected

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found