-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem on re-rendering of component, setting a new firstItem index #133
Comments
Hi @KevKo1990, Just a quick thought, but does it work if you add And if it doesn't, can you set up a simple test case so I can easily reproduce the issue? |
@bd-arc I will try to make an easy executable example of my problem! |
I had a look into your Carousel componentWillReceiveProps() function and I think I found the problematic part: I checked in your code the In the following case I will receive a not wished behavior with being stuck on an empty page:
I thought about several solutions, however none of them did work for me:
|
Yep, that's a real head-scratching issue. A while ago, I anticipated this kind of problem and tried to figure out a solution, but didn't come up with anything satisfying (and ended up forgetting it...). Now is the time to tackle it for good! First, after 7 (when you remove the currently selected component), can you confirm that this condition is met? Then, would something along those lines work?
Finally, and I don't mean to insist, but a test case would made things easier for me :-) |
https://github.com/KevKo1990/Snap-Carousel-Fix-Dynamic I created a example repo with not completely our problem but a really close one (if I deselect another component than the selected one, it is in this repo now as well problematic). If this would be fixed, our problem would be as well. ;) Just to show you the problem that I rebuild: Does this help you? (btw thank you for your example, I just used it, hope you do not mind... ;)) |
Concerning your proposed fix, it would not solve our problem. I can confirm, the condition is met as soon as we remove or add a component. |
Hey @KevKo1990, Thanks for the awesome example! This is really going to help me figure out a solution. I'll take a look at it today and keep you posted ;-) By the way, I'm curious about how you created your gif file. I'm always hitting GitHub's 5 Mo limit with mines, with as little as a 4 to 5 seconds duration... |
No worries, I asked for your help ;) I am developing right now on Ubuntu and there I found this tool. I think it is really nice! |
@KevKo1990 Thanks for sharing your tool! It won't work for me, but it's still good to know. Anyway, I finally started working on the issue and, well, the first thing to be noted is that Android and iOS do not behave the same at all: http://www.giphy.com/gifs/l1J9Geez5TJ78POuI Usually all hell breaks loose 2 to 3 minutes after such a revelation... |
@KevKo1990 By the way, it seems that your example is missing an Android version ;-) |
Hey @KevKo1990, So, fixing the main issue (scrolling back to the previous slide on Android) was no big trouble. But now comes another one: displaying the active animation for the previous slide. I might implement a recent PR idea to see if that helps. |
Good news: this commit should solve the issue. It wasn't that easy, but I think I got it :-) Can you try the fix and let me know if it works for you and if you don't find any drawbacks? |
@bd-arc Thank you! Sorry, I am right now a bit busy and saw your replies just now. I will try to check tonight (JST) and let you know if the fix works! |
I just meant that your repo didn't contain the android source code. But adding it wasn't too much trouble ;-) Make sure to test the latest commit on master, because I made a substantial update and then modified the fix accordingly. |
Thank you! Hm, I am facing now a problem. In my provided repo, I solved the carousel entries via the data props, but in my actual problem case, I have the above structure:
I replaced now my existing above solution with data and renderItem which are now required... I think you want to fix above mentioned problem or is this a mistake from my side? PS: Sorry for not uploading the android code... seems to be that I made a mistake with the .gitignore file... |
@KevKo1990 I'm not sure that I totally get what you wrote. What I can tell you is that I've tried the new code with your custom example and everything is working perfectly, both slider and pagination. Here is a quick screencast: |
Forget my comment from above, a colleague of mine implemented the Carousel view, maybe it was still an old implementation... (we had this solution still working https://github.com/archriss/react-native-snap-carousel#migration-from-version-2x). I have to update my code from my app. I think it is fine, I will tell you asap if not. PS: I am quiet busy these days, so, it may take some time until I give you a final confirmation, sorry for that! |
@KevKo1990 Does it work if you use the code from this commit? |
Yes, I can confirm it is fine. I tested it on my example repo and my app. I tested further my app and I recognized now if I rerender my carousel with a reduced set of components because I deselected some of them, that I think it is not intended to call |
@KevKo1990 Im glad you're testing the plugin thoroughly :-) I am triggering Be aware that the commit I made you test is an older one; it was a previous attempt at solving your issue, but I've overridden it because I wasn't happy with using I'll keep you posted as soon as I've updated the code. |
Thank you! @bd-arc I really love your solution, so it is worth! I will probably test it then altogether, take as much time as you need. ;) |
@KevKo1990 I'll let you play with this commit ;-) |
Hm... So actually the onSnapItem is not longer called, but I have now a different problem :/ I rerender my Carousel with a firstItem=0 after removing my actual selected component... But it goes to into index 1... |
Ok, here is a new commit for you to try. This one should address the active state being displayed on the wrong item when using a I if doesn't solve your issue, could you update your example repo with a reproductible test case? |
Hey @KevKo1990, You can either copy/paste the raw code, like you did, or reference the commit in your
and then run Regarding the issue, what you're showing is the expected behavior: if you remove an item, the closest one becomes active. And, as I've previously mentioned, since the callback is not fired the I think that it's a little dangerous to always go back to the first item if the current one is deleted. Imagine a list of hundreds of items; it would result in a pretty bad user experience. What would be the best behavior in your opinion? |
I talked to my team, we are fine with your solution. Your described behavior should resolve our issue, we are totally fine with it. 👍 |
Ok, perfect! Then you can start using version |
I have several
miniComponents
listed in my carousel and a user can select and deselect theseminiComponents
on different screens to be visible in the carousel or not.Removing and adding them works splendidly (the
miniComponents.map
function below).So an actual rerendering is on this page with the Carousel happening.
But if remove one of the
miniComponents
, myactiveMiniCompIndex
might chance as components now move to different positions. I set infirstItem
theactiveMiniCompIndex
, the Carousel stays however on the same position.I checked via console.log output that the
activeMiniCompIndex
is changing and that a rerender is executed in the component containing the carousel, however the carousel is not.I checked your documentation and past issues, unfortunately I couldn't find a solution to this problem.
Thank you in advance for your help!
The text was updated successfully, but these errors were encountered: