Giter VIP home page Giter VIP logo

Comments (8)

rubensousa avatar rubensousa commented on August 18, 2024 1

I manage to reproduce it with this test:

 @Test
    fun testGridRemovalWithSpanLookupDoesNotCrash() {
        onRecyclerView("Change span size") { recyclerView ->
            recyclerView.setSpanSizeLookup(object : DpadSpanSizeLookup() {
                override fun getSpanSize(position: Int): Int {
                    val adapter = recyclerView.adapter as AbstractTestAdapter<*>
                    val item = adapter.getItem(position)
                    return if (item % 9 == 0) {
                        recyclerView.getSpanCount()
                    } else {
                        1
                    }
                }
            })
        }
        KeyEvents.pressDown()
        val oldViewBounds = getRelativeItemViewBounds(position = 1)
        mutateAdapter { adapter ->
            adapter.removeAt(3)
            adapter.removeAt(13)
        }
        assertFocusAndSelection(1)
        assertItemAtPosition(position = 1, item = 1)

        val newViewBounds = getRelativeItemViewBounds(position = 1)
        assertThat(newViewBounds).isEqualTo(oldViewBounds)
    }

Will take care of it for the next release

from dpadrecyclerview.

rubensousa avatar rubensousa commented on August 18, 2024 1

Released in 1.3.0-alpha03 now

from dpadrecyclerview.

rubensousa avatar rubensousa commented on August 18, 2024

@tyrel-carlson is this similar to your setup?
image

I'm not able to reproduce this. Can you give me more details about the contents of your adapter and which position you're removing?

from dpadrecyclerview.

rubensousa avatar rubensousa commented on August 18, 2024

Here's my current test that is passing:

 @Test
    fun testGridRemovalWithSpanLookupDoesNotCrash() {
        onRecyclerView("Change span size") { recyclerView ->
            recyclerView.setSpanSizeLookup(object : DpadSpanSizeLookup() {
                override fun getSpanSize(position: Int): Int {
                    return if (position % 5 == 0) {
                        recyclerView.getSpanCount()
                    } else {
                        1
                    }
                }
            })
        }
        val oldViewBounds = getRelativeItemViewBounds(position = 0)
        mutateAdapter { adapter ->
            adapter.removeAt(adapter.itemCount - 1)
            adapter.removeAt(adapter.itemCount - 1)
            adapter.removeAt(0)
            adapter.removeAt(0)
        }
        assertFocusAndSelection(0)
        assertItemAtPosition(position = 0, item = 2)

        val newViewBounds = getRelativeItemViewBounds(position = 0)
        assertThat(newViewBounds).isEqualTo(oldViewBounds)
    }

I'm trying to replicate your setup, but I need more details

from dpadrecyclerview.

tyrel-carlson avatar tyrel-carlson commented on August 18, 2024

@tyrel-carlson is this similar to your setup? image

I'm not able to reproduce this. Can you give me more details about the contents of your adapter and which position you're removing?

Yeah that looks like my own. My date headers fill the grid but are not focusable themselves.

from dpadrecyclerview.

tyrel-carlson avatar tyrel-carlson commented on August 18, 2024

I manage to reproduce it with this test:

 @Test
    fun testGridRemovalWithSpanLookupDoesNotCrash() {
        onRecyclerView("Change span size") { recyclerView ->
            recyclerView.setSpanSizeLookup(object : DpadSpanSizeLookup() {
                override fun getSpanSize(position: Int): Int {
                    val adapter = recyclerView.adapter as AbstractTestAdapter<*>
                    val item = adapter.getItem(position)
                    return if (item % 9 == 0) {
                        recyclerView.getSpanCount()
                    } else {
                        1
                    }
                }
            })
        }
        KeyEvents.pressDown()
        val oldViewBounds = getRelativeItemViewBounds(position = 1)
        mutateAdapter { adapter ->
            adapter.removeAt(3)
            adapter.removeAt(13)
        }
        assertFocusAndSelection(1)
        assertItemAtPosition(position = 1, item = 1)

        val newViewBounds = getRelativeItemViewBounds(position = 1)
        assertThat(newViewBounds).isEqualTo(oldViewBounds)
    }

Will take care of it for the next release

Thanks for your consideration. By the way, can you tell me how can I manage to fix this until next version is released?

from dpadrecyclerview.

rubensousa avatar rubensousa commented on August 18, 2024

As a workaround, notifyDataSetChanged instead of individual notifyItemRemoved calls should fix it for now. But I plan to release this fix today anyway

from dpadrecyclerview.

tyrel-carlson avatar tyrel-carlson commented on August 18, 2024

Yeah I noticed too that calling notifyDataSetChanged is a fix but it prevents loading of item data in my case, so I prefer to wait for your release, thanks for your great work!

from dpadrecyclerview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.