JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

scrollToDate() does not account for UICollectionView sectionInset property

Open johnuphoff opened this issue 9 years ago • 37 comments

First - thanks for all your hard work on this calendar! I am using JTAppleCalendar 7.02.

Calling calendarView.scrollToDate(Date(), triggerScrollToDateDelegate: true, animateScroll: false) I noticed that the collection view was stopping between April & May. I played around with the extraAddedOffset and realized the issue was related to the Section Inset.

The offset amount I needed to move the view into the correct position was 160pt. This is because the offset for each section increases by 40 so for 4 sections (jan through apr), the offset must be increased by 40 for each month (160). I'm not sure if it was intentional or not but thought I should bring it up.

The solution for now is to either not use section inset or to multiply the Integer month by the total inset amount and set that as the extraAddedOffset.

screenshot 2017-05-17 14 34 43

johnuphoff avatar May 17 '17 22:05 johnuphoff

see https://github.com/patchthecode/JTAppleCalendar/pull/420

johnuphoff avatar May 17 '17 22:05 johnuphoff

OK. Let me know if i understand correctly.

  1. You have a horizontal calendar
  2. You have a horizontal section inset
  3. When you call scrollToDate in this state, the calendar does not properly scroll to the date?

patchthecode avatar May 18 '17 00:05 patchthecode

That is correct - I also tested with a vertical scroll calendar with the same result.

johnuphoff avatar May 18 '17 02:05 johnuphoff

Same issue here. I can post pull request if you want.

bernikowich-cedoni avatar May 25 '17 21:05 bernikowich-cedoni

I have the same problem. These are the images of the problem.

Todays date = 2017/07/18. If I call scrollToDate Today, this is what it happens.

  1. Start date = 2017/06/01 screenshot 2017-07-18 5 40 49
  2. Start date = 2017/05/01 screenshot 2017-07-18 pm 5 42 16
  3. Start date = 2017/04/01 screenshot 2017-07-18 pm 5 43 38

As you can see, further the start dates are from Today, the further the offset gets. When I tried the start date as 1900/01/01 the collection view was showing somewhere in year 2040. I think the "cellCache" height information is not updated properly. Has anyone found a solution to this problem?

jokerham avatar Jul 18 '17 09:07 jokerham

Just realized that it shows correctly if I call the function twice. Wonder why.

jokerham avatar Jul 18 '17 15:07 jokerham

@jokerham i will investigate this today.

patchthecode avatar Jul 18 '17 16:07 patchthecode

Same issue. Hope you will fix it soon @patchthecode

duyklinsi avatar Jul 30 '17 11:07 duyklinsi

I got caught up last week. I'll take a look in 11 hrs today.

patchthecode avatar Jul 30 '17 14:07 patchthecode

Same issue, but I'm using vertical scroll. The date cells appear aligned to the left after the scroll, but pop back into place when manually scrolling. @patchthecode

DominicMDev avatar Nov 21 '17 00:11 DominicMDev

Seems like the same problem comes up when using scrollToSegment. It does not consider the sectionInset, too.

Im using Swift 4.0 with JTAppleCalendar 7.1.3

chauss avatar Nov 21 '17 10:11 chauss

Yes.. this issue is opened, but i never got around to looking at it. My time is to caught up. Let me take a look after work today ok.

patchthecode avatar Nov 21 '17 15:11 patchthecode

Hi, this issue seems to be still here: https://www.dropbox.com/s/1wyab52q7vk6zck/JTAppleCalendar_insetsIssue.mp4?dl=0

Could you please fix? This is really important for me to have insets 🙂

juliensagot avatar Dec 29 '17 13:12 juliensagot

Hey guys, i have finally gotten around to fixing this.

can you put this in your PodFile and run a pod update command?

pod 'JTAppleCalendar', :git => 'https://github.com/patchthecode/JTAppleCalendar.git', :branch => 'Fixes'

If it works well, i will merge this into the next release.

patchthecode avatar Dec 29 '17 18:12 patchthecode

Works in my projet and in the example project 👍 Thank you very much, that was fast!

juliensagot avatar Dec 29 '17 20:12 juliensagot

7.1.5 released

patchthecode avatar Dec 31 '17 16:12 patchthecode

Still have this issue. Pod version 7.1.7. For now removed insets to avoid UI bugs.

yuryks avatar Mar 06 '19 11:03 yuryks

I can confirm, have the same issue on current version

lsmilek1 avatar Mar 08 '19 15:03 lsmilek1

Can you tell me the setup you have? What does your inset look like?

I need know what is your exact setup so that i can re-create the UI bug.

patchthecode avatar Mar 08 '19 19:03 patchthecode

Hi,

I am currently struggling with scrollToDate on viewDidLoad. What I am trying is to have fixed cell height and change calendarView height on scroll (generating cells till end of row to prevent gap between months for vertical scroll direction). The issue I have:

  1. in viewDidLoad I have to set scroll mode to .none, then scroll and set scroll mode .stopAtEachSection, otherwise it stops somewhere in the middle of section
  2. I want to have top and bottom insets on section (place for shadow effect). After scroll in viewDidLoad the insets are ignored - view shows up scrolled, but I have to scroll manually so it snaps correctly with top inset. Also "extraAddedOffset" is ignored during the scroll in viewDidLoad.

I am sorry if the code is confusing, I am working today already for 14hrs, I cant think much straight... Hope it helps!

(code in next comment - answering vie email ruined the format)

lsmilek1 avatar Mar 08 '19 19:03 lsmilek1