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

Wrong date retuned with gesture recognition. #1277

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions JTAppleCalendar.podspec
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
Pod::Spec.new do |s|
s.name = "JTAppleCalendar"
s.version = "8.0.3"
s.name = "JTAppleCalendarGreenRoad"
s.version = "1.0.0"
s.summary = "The Unofficial Swift Apple Calendar Library. View. Control. for iOS & tvOS"
s.description = <<-DESC
A highly configurable Apple calendar control. Contains features like boundary dates, month and week view. Very light weight.
DESC

s.homepage = "https://patchthecode.com"
s.homepage = "https://github.com/alexvaiman/"
# s.screenshots = "https://patchthecode.github.io/"
s.license = 'MIT'
s.author = { "JayT" => "[email protected]" }
s.source = { :git => "https://github.com/patchthecode/JTAppleCalendar.git", :tag => s.version.to_s }
s.source = { :git => "https://github.com/alexvaiman/JTAppleCalendar.git", :tag => s.version.to_s }

s.swift_version = '5'

s.ios.deployment_target = '10.0'
s.tvos.deployment_target = '10.0'

s.source_files = 'Sources/JTAppleCalendar/*.swift'
end

end
36 changes: 33 additions & 3 deletions Sources/JTAppleCalendar/JTACInteractionMonthFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ import UIKit

extension JTACMonthView {

/// Returns the cellStatus of a date that is visible on the screen.
/// If the point does not correspond to existing indexPath cell,
/// then nil is returned
/// Parameter: point of the cell you want to find
/// - returns:
/// - CellState: The state of the found cell
public func cellStatusForDate(at point: CGPoint) -> CellState? {
guard let indexPath = indexPathForItem(at: point) else {
return nil
}

return cellStatusForDate(at: indexPath.item / maxNumberOfDaysInWeek , column: indexPath.item % maxNumberOfDaysInWeek)
}

/// Returns the cellStatus of a date that is visible on the screen.
/// If the row and column for the date cannot be found,
/// then nil is returned
Expand Down Expand Up @@ -104,10 +118,26 @@ extension JTACMonthView {
/// - returns:
/// - CellState: The state of the found cell
public func cellStatus(at point: CGPoint) -> CellState? {
if let indexPath = indexPathForItem(at: point) {
let cell = cellForItem(at: indexPath) as? JTACDayCell
return cellStateFromIndexPath(indexPath, cell: cell)
guard let indexPath = indexPathForItem(at: point) else {
return nil
}

guard let section = currentSection() else {
return nil
}

let i = indexPath.item
let row = i / maxNumberOfDaysInWeek
let column = i % maxNumberOfDaysInWeek
let convertedRow = (row * maxNumberOfDaysInWeek) + column
let indexPathToFind = IndexPath(item: convertedRow, section: section)

if let date = dateOwnerInfoFromPath(indexPathToFind) {
let cell = cellForItem(at: indexPathToFind) as? JTACDayCell
let stateOfCell = cellStateFromIndexPath(indexPathToFind, withDateInfo: date,cell: cell)
return stateOfCell
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/JTAppleCalendar/JTACMonthViewProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public protocol JTACMonthViewDelegate: class {
/// Informs the delegate that the user just lifted their finger from swiping the calendar
func scrollDidEndDecelerating(for calendar: JTACMonthView)

/// Informs the delegate that the scrolling animation concludes
func scrollDidEndScrollingAnimation(for calendar: JTACMonthView)

/// Tells the delegate that a scroll occured
func calendarDidScroll(_ calendar: JTACMonthView)

Expand Down Expand Up @@ -178,4 +181,5 @@ public extension JTACMonthViewDelegate {
func calendarSizeForMonths(_ calendar: JTACMonthView?) -> MonthSize? { return nil }
func sizeOfDecorationView(indexPath: IndexPath) -> CGRect { return .zero }
func scrollDidEndDecelerating(for calendar: JTACMonthView) {}
func scrollDidEndScrollingAnimation(for calendar: JTACMonthView) {}
}
1 change: 1 addition & 0 deletions Sources/JTAppleCalendar/JTACScrollViewDelegates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ extension JTACMonthView: UIScrollViewDelegate {

DispatchQueue.main.async { // https://github.com/patchthecode/JTAppleCalendar/issues/778
self.executeDelayedTasks(.scroll)
self.calendarDelegate?.scrollDidEndScrollingAnimation(for: self)
}
}

Expand Down