JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

preferredScrollPosition option in scrollToDate function is not being applied

Open nereski opened this issue 6 years ago • 6 comments

Version Number: 8.0.1

Description

I've tried to use the option preferredScrollPosition on scrollToDate function, regardless of the parameter I send, it does nothing different.

I've checked the code, and it seems the parameter is not sent to the function targetPointForItemAt when calculating the point. I've tried to add it myself in the call of the function, but nothing new happened.

I've checked then targetPointForItemAt function, and it doesn't seem to use the parameter preferredScrollPosition in its calculations.

Maybe I'm missing something... If this is not yet implemented, please let me know.

Steps To Reproduce

Call scrollToDate with parameter preferredScrollPosition different to nil or top.

Expected Behavior

When changing preferredScrollPosition to something different to nil or top, the scroll position of the scrollToDate should change.

Additional Context

nereski avatar Sep 05 '19 13:09 nereski

Sorry for getting to this so late.

This needs some more thought. I am thinking of removing the preferred position.

I do not know of a good use case for this with this library. If you have a screen shot of how you want this property to be applied, then can you show me here? You can drag the screenshot in the chat box.

patchthecode avatar Oct 19 '19 15:10 patchthecode

No worries!

In the end, I decided to implement another interaction that made more sense for the context. So I won't need the option anymore. I'm trying to recall what exactly was the use case, but I don't remember, sorry.

Either way, for me, not having the option is not a big deal. So if you decide to remove the preferred position is ok with me. The confusion started when I saw the parameter on the function.

Thanks for your response and this great library!

nereski avatar Oct 23 '19 13:10 nereski

Thanks. I'll update and remove that function soon.

patchthecode avatar Oct 23 '19 17:10 patchthecode

@patchthecode

I have a use case.

image

This is a UIToolbar housing an instance of the JTAppleCalendarView limited to a single row. The date range is only 7 days and I hide the cells for any days outside of this range. I have disabled scrolling and had imagined that a call to scrollToDate with preferredScrollPosition: .right would position the view as desired.

What happens is that today's cell is seen on the left, the rest remains blank.

wuntunsun avatar Aug 26 '20 10:08 wuntunsun

@patchthecode

I see you respond quickly :-)

I came up with a solution. In my viewDidLoad, I scrollToDate, and from within its completionHandler, I selectDates and then scrollToItem. It would of course be nice if scrollToDate did this for me, without prior selection, if you think this is a reasonable use case to support.

    self.toolbar.calendarView.scrollToDate(self.viewModel.todaysDate
        , triggerScrollToDateDelegate: false
        , animateScroll: false
        , preferredScrollPosition: .right
        , extraAddedOffset: 0) { [weak self] in

        guard let self = self else { return }

        self.toolbar.calendarView.selectDates([self.viewModel.todaysDate]
            , triggerSelectionDelegate: false)

        if let today = self.toolbar.calendarView.indexPathsForSelectedItems?.first {

            self.toolbar.calendarView.scrollToItem(at: today, at: .right, animated: false)
        }
    }

wuntunsun avatar Aug 26 '20 13:08 wuntunsun

I sorta swamped with projects right now, so I'll take a look over the weekend along with some other PRs.

Thanks for the code of possible solutions. This helps me a lot.

patchthecode avatar Aug 26 '20 13:08 patchthecode