Skip to content

Commit

Permalink
Added status for month function
Browse files Browse the repository at this point in the history
Helps if Devs need mor information about the month in order to adjust its size with an animation.

public func monthStatus(for date: Date) -> Month?
  • Loading branch information
patchthecode committed Jul 22, 2017
1 parent d91fd86 commit 502d53d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
26 changes: 6 additions & 20 deletions Sources/CalendarStructs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct CalendarData {
}

/// Defines a month structure.
struct Month {
public struct Month {

/// Start index day for the month.
/// The start is total number of days of previous months
Expand All @@ -150,22 +150,22 @@ struct Month {
let sections: [Int]

/// Number of inDates for this month
let inDates: Int
public let inDates: Int

/// Number of outDates for this month
let outDates: Int
public let outDates: Int

/// Maps a section to the index in the total number of sections
let sectionIndexMaps: [Int: Int]

/// Number of rows for the month
let rows: Int
public let rows: Int

/// Name of the month
let name: MonthsOfYear
public let name: MonthsOfYear

// Return the total number of days for the represented month
var numberOfDaysInMonth: Int
public let numberOfDaysInMonth: Int

// Return the total number of day cells
// to generate for the represented month
Expand All @@ -176,20 +176,6 @@ struct Month {
var startSection: Int {
return sectionIndexMaps.keys.min()!
}

// func firstIndexPathForExternal(section: Int) -> IndexPath? {
// guard let internalSection = sectionIndexMaps[section] else {
// return nil
// }
// if internalSection == 0 {
// // Then we need to consider predates
// return indexPath(forDay: 1 - inDates)
// } else {
// let startDay = startDayFor(section: internalSection)!
// let path = indexPath(forDay: startDay)
// return path
// }
// }

// Return the section in which a day is contained
func indexPath(forDay number: Int) -> IndexPath? {
Expand Down
5 changes: 0 additions & 5 deletions Sources/JTAppleCalendarLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,6 @@ class JTAppleCalendarLayout: UICollectionViewLayout, JTAppleCalendarLayoutProtoc
}
}

// func sectionFromRectOffset(_ offset: CGPoint) -> Int {
// let theOffet = scrollDirection == .horizontal ? offset.x : offset.y
// return sectionFromOffset(theOffet)
// }

func sectionFromOffset(_ theOffSet: CGFloat) -> Int {
var val: Int = 0
for (index, sectionSizeValue) in sectionSize.enumerated() {
Expand Down
9 changes: 0 additions & 9 deletions Sources/JTAppleCalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ open class JTAppleCalendarView: UICollectionView {
var delayedExecutionClosure: [(() -> Void)] = []
let dateGenerator = JTAppleDateConfigGenerator()


/// Implemented by subclasses to initialize a new object (the receiver) immediately after memory for it has been allocated.
public init() {
super.init(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
Expand Down Expand Up @@ -112,14 +111,6 @@ open class JTAppleCalendarView: UICollectionView {
/// Lays out subviews.
override open func layoutSubviews() {
super.layoutSubviews()

// if (collectionViewLayout as! JTAppleCalendarLayout).lastSetCollectionViewSize != frame {
// // ive seen that layout subview gets called. Calendar is setup, and then it gets called again
// // At this point, it already has generaed cells which needs to be invalidated.
// calendarViewLayout.invalidateLayout()
// layoutIfNeeded()
// }

if !delayedExecutionClosure.isEmpty, isCalendarLayoutLoaded {
executeDelayedTasks()
}
Expand Down
14 changes: 14 additions & 0 deletions Sources/UserInteractionFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ extension JTAppleCalendarView {
return stateOfCell
}

/// Returns the month status for a given date
/// - Parameter: date Date of the cell you want to find
/// - returns:
/// - Month: The state of the found month
public func monthStatus(for date: Date) -> Month? {
guard
let calendar = cachedConfiguration?.calendar,
let startMonth = startOfMonthCache,
let monthIndex = calendar.dateComponents([.month], from: startMonth, to: date).month else {
return nil
}
return monthInfo[monthIndex]
}

/// Returns the cell status for a given point
/// - Parameter: point of the cell you want to find
/// - returns:
Expand Down

0 comments on commit 502d53d

Please sign in to comment.