Skip to content
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

Month selection triggers multiple times and with invalid data as well #530

Open
frankhardenberg opened this issue Feb 8, 2024 · 6 comments

Comments

@frankhardenberg
Copy link

frankhardenberg commented Feb 8, 2024

Library information:

  • Version: 2.4.0-beta01
  • Compose

Describe the bug**

Whenever I swipe left or right to a new month, the callback gets triggered multiple times. The months passed through are not correct and I have to take the data from the calendar state instead of the lambda value. Because of this I can't even close/re-open the calendar without it resetting to it's original month. Very annoying and hard to deal with since you will have to keep track of multiple variables and since the data is being looped through multiple times (AND changing in the meantime at random) it's pretty much impossible.

To Reproduce (if applicable)

Steps to reproduce the behavior:
Just use the calendar and swipe left/right and put some logging statements in the callback. (I use the monthHeader one)

Expected behavior (if applicable)

Callback only triggered once with the correct data

Screenshots? (if applicable)

If applicable, add screenshots or screen recordings to help explain the problem.

Additional information

Add any other information about the bug here.

@kizitonwose
Copy link
Owner

Are you sure it is the calendar calling those methods multiple times or something in your code triggering recomposition? Also, keep in mind that the months adjacent to the currently visible month can be bound in some cases, this is a normal LazyRow/Column behavior. If you can reproduce this in the sample project, I am happy to take a look.

@junseokseo9306
Copy link

Yeah I got same issue, which the callback called multiple times (may be recomposition) and logs shows different 'month' info rather than what the debugging device shows to me. I used calendarState's -> layoutinfo -> visiblemonthsInfo to find visible month info, instead using monthHeader's lambda 'CalendarMonth'.

@frankhardenberg
Copy link
Author

@junseokseo9306 I ended up doing the same, the new Month = state.firstVisibleMonth.yearMonth, I didn't check for recomposition yet but whenever you add data to the calendar it will recompose anyway so that shouldn't be an issue imo. I guess for now the solution is to track the previous selected month, check it with the 'new month' you get from state.firstVisibleMonth.yearMonth and if they are different set thew previous to the new month and fire a callback with the new month as variable

@frankhardenberg
Copy link
Author

@kizitonwose as I mentioned in my response to junseokseo, should that really be an issue? Because I add a lot of data to the calendar so it will recompose anyway. I have the idea that some sort of pagination gives this bug (loading previous/next month as well). Solution to work around it is what I mentioned above.

@junseokseo9306
Copy link

@frankhardenberg thanks for sharing. yeah i agree with the pagination issue.

@YasserElnagarRobusta
Copy link

Hi @kizitonwose ,
I noticed that this issue is happening when I try to change current month using animateScrollToMonth function ,so for now I only use scrollToMonth function and it is working fine.
I need to mention that issue is not due to recomposition as the data returned in the callaback were different for example when I increase current month "3" to "4" what i get in the callback of month header is "4" then "5"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants