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

Calendar sometimes scrolls to first month, on visibility change. #190

Closed
slobodanantonijevic opened this issue Jul 24, 2020 · 10 comments
Closed

Comments

@slobodanantonijevic
Copy link

Pretty basic setup, and when I toggle calendar visibility, the calendar sometimes scrolls to first month. It is just random. At first I thought it was some action on my end, and I've debugged it thoroughly, and followed the flow, nothing special apart from visibility change from gone to visible, and calendar just jumps to the first month set instead of staying at currently set month.

@kizitonwose
Copy link
Owner

Kindly try reproducing this with one of the examples so I can look into it.

@hikkidev
Copy link

@kizitonwose
I see a similar problem since version 0.3.4, only when switching calendar modes from month to week and back.

In your example, switching is also reproduced, just try to quickly and for a long time switch calendar modes.
As a result, binding.exOneCalendar.monthScrollListener returns the month of the beginning of the calendar binding.exOneCalendar.setup (startMonth).

@hikkidev
Copy link

In my application, the delay between clicks is 650 ms, and the duration of animation (folding/unfolding) the calendar is 200 ms, so this is not due to the incorrect cancellation of the animation.

@hikkidev
Copy link

hikkidev commented Jul 28, 2020

I looked around the library code a bit and the method findVisibleMonthPosition sometimes returns 0.


private fun findVisibleMonthPosition(isFirst: Boolean): Int {
        val visibleItemPos = if (isFirst) layoutManager.findFirstVisibleItemPosition() else layoutManager.findLastVisibleItemPosition()
        println("findVisibleMonthPosition = $visibleItemPos")
       ...
}

6 - Month mode
26 - Week mode

calendarviewsample I/System.out: findVisibleMonthPosition = 26
calendarviewsample I/System.out: findVisibleMonthPosition = 6
calendarviewsample I/System.out: findVisibleMonthPosition = 26
calendarviewsample I/System.out: findVisibleMonthPosition = 6
calendarviewsample I/System.out: findVisibleMonthPosition = 26
calendarviewsample I/System.out: findVisibleMonthPosition = 0
calendarviewsample I/System.out: findVisibleMonthPosition = 26

@kizitonwose
Copy link
Owner

@hikkidev I think I see how this could happen. Could you try using the new updateMonthConfiguration() method to update all configs at the same time and see if this still happens?

Something like this:

val monthToWeek = monthViewCheckBox.isChecked
if (monthToWeek) { 
    // One row calendar for week mode
    calendarView.updateMonthConfiguration(
        inDateStyle = InDateStyle.ALL_MONTHS,
        maxRowCount = 1,
        hasBoundaries = false
    )
} else {
    // Six row calendar for month mode
    calendarView.updateMonthConfiguration(
        inDateStyle = InDateStyle.FIRST_MONTH,
        maxRowCount = 6,
        hasBoundaries = true
    )
}

@hikkidev
Copy link

hikkidev commented Aug 4, 2020

@kizitonwose i already use it.

    private fun CalendarView.applyWeekMode() {
        updateMonthConfiguration(
                inDateStyle = InDateStyle.FIRST_MONTH,
                maxRowCount = 1,
                hasBoundaries = false
        )
    }

    private fun CalendarView.applyMonthMode() {
        updateMonthConfiguration(
                inDateStyle = InDateStyle.ALL_MONTHS,
                maxRowCount = maxWeekPerPage,
                hasBoundaries = true
        )
    }

@kizitonwose
Copy link
Owner

Interesting, I'll investigate this when I find some time and will report back.

@hikkidev
Copy link

hikkidev commented Aug 6, 2020

@kizitonwose thanks

@kizitonwose
Copy link
Owner

I tried toggling the checkbox in Example 1 repeatedly and the best I could get was an animation-related crash. I think an easy workaround for this would be to disable the checkbox before starting the animation and enabling it afterward.

binding.weekModeCheckBox.setOnCheckedChangeListener { checkBox, monthToWeek ->
    animator.doOnStart {
        checkBox.isEnabled = false
        // Other logic
    }
    animator.doOnEnd {
        checkBox.isEnabled = true 
        // Other logic
    }
}

@kizitonwose
Copy link
Owner

Guess I can close this for now.

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

3 participants