astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

Wrong selected tab when I rotate my nexus 5 #73

Open Flavien69 opened 10 years ago

Flavien69 commented 10 years ago

I cloned the sample directory from github and I tried the app but I notice the same issue that I had in my app : If I rotate the phone, the selected tabs is shifted on the right. But I don't have this issu on my nexus 7. If someone has an explication.

mdonaj commented 10 years ago

I have tried the sample app on my Nexus 5, no issues during rotation. No issues in my real life app either. It may be something more specific then rotation itself.

Flavien69 commented 10 years ago

Are you sure? I just clone the master branch of the project and import this in android studio then I lunched it on my device and I have the issue. I have it on my nexus 5 and 4 but not on nexus 7. I really don't know why. Maybe it is the version that I cloned was wrong? Moreover in my personnal project I used : compile 'com.astuetz:pagerslidingtabstrip:1.0.1' and I have exactly the same issue.

trentrosenbaum commented 10 years ago

I have experienced the same issue over the weekend. I was able to make it do the same on a Galaxy Nexus and my Nexus 5. In the end I looked at the following Stackoverflow post

http://stackoverflow.com/questions/22061209/astuetz-pagerslidingtabstrip-wrong-selected-tab-when-i-rotate-device

I then modified the PagerSlidingTabStrip with the new line in the questions answer and then it worked. Any thoughts?

trentrosenbaum commented 10 years ago

I just wanted to updated for completeness. I am not totally sure what I was seeing, but in the end I found that my delegate OnPageChnageListener seems to be given the wrong position and so I had to use the pager to get the index of the current item. This only seemed to happen when I was in landscape mode. Could this be what you were seeing?

Tuxdude commented 10 years ago

This change https://github.com/Tuxdude/PagerSlidingTabStrip/commit/8951c8838eab327398a0763c3380607c0bb125bc should fix the issue. It is based off https://github.com/Tuxdude/PagerSlidingTabStrip/commit/4fcc6442827edd3c51656a0c7c0069cf51a104f7

You are right that the OnPageChangeListener sometimes passes a positionOffset as 1, which indicates that the current position should be chosen as position +1 instead.

trentrosenbaum commented 10 years ago

Thanks for the feedback on the issue. Do we think this will make it back into the initial repo? I do not seem to be able to locate the 'org.tuxdude:pagerslidingtabstrip:1.0.1.b' release of the dependency.

Tuxdude commented 10 years ago

I'm not the maintainer of the original repo, so I do not have an answer to your question. I needed a version of psts that I could make changes and hence created the org.tuxdude version. If you want to pull the artifacts, you need to add the following maven repo to your project: https://raw.githubusercontent.com/Tuxdude/maven-artifacts/master

For an example of how to do this in gradle, you can look at this change: https://github.com/Tuxdude/yani/commit/f6b36ba50b793e63aa3f885e127235c4aa8ac429

Same should be possible using maven as well.