Git Product home page Git Product logo

Comments (4)

nikhilwynk avatar nikhilwynk commented on June 14, 2024

@samardzija I am also facing this issue please share the resolution if you find one

from scrollingpagerindicator.

samardzija avatar samardzija commented on June 14, 2024

@nikhilwynk The problem is that viewpager current position has been remembered. That's why a crash occurs.
I've added a listener to the adapter, to notify me when adapter data is changed and in that case, I set viewPager current position to 0.
So, first extend constructor for adapter and add listener:
ViewPagerAdapter(val onDataChange: Runnable)

Then, when listener triggers, set:
yourViewPager.currentItem = 0

from scrollingpagerindicator.

nikhilwynk avatar nikhilwynk commented on June 14, 2024

@samardzija Thanks for the inputs but I don't think this is actually what causes the crash as adapter data does not change in my case and it always remains the same. Moreover how often do you get the crash ? I am getting like 15 crashes a day out of 5.5M Daily Active users . Also can you reproduce this issue manually ? I am not able to reproduce this manually.

from scrollingpagerindicator.

samardzija avatar samardzija commented on June 14, 2024

Wow, that's nasty. Yes, I can reproduce it. My use case is that I have view pager with adapter attached. Adapter data is changed, based on some things that happen behind. I can reproduce it by:

  • adapter size is bigger than one, swipe to the second position, or third position, whatever
  • trigger adapter change so that it will have only one element
  • view pager remembers that it should be in the second position and when data is changed, it crashes.

It is strange that adapter data is not changing in your case, I can't think of the way how you could reproduce the issue.
Maybe is something happening with the data, try to set don't keep activity in Settings.

Anyway, I don't think library should crash at this moment, anyway. It should just ignore.

        if (position != 0 && (position < 0 || position >= itemCount)) {
            throw new IndexOutOfBoundsException("Position must be [0, adapter.getItemCount()]");
        }
        if (itemCount == 0) {
            return;
        }
        adjustFramePosition(0, position);
        updateScaleInIdleState(position);
    }    

this is the method that crash. Maybe, if (itemCount == 0) should be before throwing exception.

from scrollingpagerindicator.

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.