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.

[Question] Avoid redrawing entire carousel but update specific views?

See original GitHub issue

Overall context: I have a PagedListEpoxyController which displays a carousel of filters at the top, and shows the paged list below it.

I attach a listener to my filter models, so that when one is clicked, I set a selectedFilterId on the controller and request a model build. This does work, but the UX isn’t great. It appears when it redraws each item in the carousel, it changes the padding on the ones that are selected/deselected. Gif below.

I’ve been fighting this for a little bit and tinkered with a few ideas, but I’m not sure the best approach. Do you have any suggestions?

Here is some code if that helps:

override fun addModels(models: List<EpoxyModel<*>>) {
    buildFilterCarousel()
    super.addModels(models)
}

// Passed in through databinding, called when a filter is "clicked"
private val filterConsumer: Consumer<Filter?> = Consumer {
    // Setting this field triggers a callback which pulls for the paged list, and when that happens we request a model build.
    selectedFilterId = it?.filterId
}

private fun buildFilterCarousel() {
    val filterModels: List<FilterEpoxyModel> = filters?.map { filter ->
        // ... Get filter ID and selected status

        return@map FilterEpoxyModel()
                // I had to include "selected" as part of the model ID in order for it to actually update when I call `requestModelBuild`.
                .id("Filter: $filterId, selected: $selected")
                .viewModel(viewModel)
                .filterConsumer(filterConsumer)
    }.orEmpty()

    CarouselModel_()
            .numViewsToShowOnScreen(3.0f)
            .hasFixedSize(true)
            .paddingDp(16)
            .id("Filter Carousel")
            .models(filterModels)
            .addTo(this)
}

carouselbug

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
elihartcommented, Oct 18, 2018

I’ve updated the wiki pages a bit for clarity 😃

1reaction
elihartcommented, Oct 10, 2018

the generated databinding class is much smarter about only rebinding the data that changed, your new manual version always rebinds everything

i would guess that your viewModel(viewModel) attribute you are passing does not properly implement equals and hashcode to represent that the selected state changed, so epoxy doesn’t think it needs to rebind it

the general advice is this - id should not change, any data that can change on the model must be represented by attributes that correctly implement equals and hashcode. Epoxy will rebind only the data that changed when models are rebuilt

Read more comments on GitHub >

github_iconTop Results From Across the Web

Efficient Matplotlib Redrawing - python - Stack Overflow
My data is drawn in the background using pcolormesh() , so when I update the canvas using axis.figure.canvas.draw() both the scatter points and...
Read more >
Snapping behaviour in Epoxy Carousel and its pitfalls
The details of the behaviour: There is a selected element — one item, ... items and in a Carousel and redraw the view...
Read more >
Content Jumping (and How To Avoid It) | CSS-Tricks
I would argue that shifting the page layout after the initial render (without relevant user interaction) may be the single most unpleasant user ......
Read more >
Turn 'Map Redraw' off in QGIS print layout - GIS Stack Exchange
Try deactivating the checkbox Live update at the bottom of the layer panel as well. enter image description here. Share.
Read more >
Issues with Safari - Smart Slider Documentation - Help Scout
Text animations are blurry. Affected browser(s), Mac Safari. Affected slider type, All. Official bug report, View. Status ...
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