Skip to content

Commit

Permalink
Remove double reloading funciton called.
Browse files Browse the repository at this point in the history
  • Loading branch information
patchthecode committed Jun 26, 2017
1 parent af0a251 commit 05c6f51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 10 additions & 7 deletions Sources/JTAppleCalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ open class JTAppleCalendarView: UICollectionView {
}
}

func setupMonthInfoAndMap() {
theData = setupMonthInfoDataForStartAndEndDate()
func setupMonthInfoAndMap(with data: ConfigurationParameters? = nil) {
theData = setupMonthInfoDataForStartAndEndDate(with: data)
}

// Configuration parameters from the dataSource
Expand Down Expand Up @@ -402,8 +402,8 @@ open class JTAppleCalendarView: UICollectionView {
}

// Only reload the dates if the datasource information has changed
func reloadDelegateDataSource() -> Bool {
var retval = false
func reloadDelegateDataSource() -> (shouldReload: Bool, configParameters: ConfigurationParameters?) {
var retval: (Bool, ConfigurationParameters?) = (false, nil)
if let
newDateBoundary = calendarDataSource?.configureCalendar(self) {
// Jt101 do a check in each var to see if
Expand All @@ -424,7 +424,7 @@ open class JTAppleCalendarView: UICollectionView {
lastMonthSize != newLastMonth ||
calendarViewLayout.updatedLayoutCellSize != calendarViewLayout.cellSize {
lastMonthSize = newLastMonth
retval = true
retval = (true, newDateBoundary)
}
}

Expand Down Expand Up @@ -617,12 +617,15 @@ extension JTAppleCalendarView {
return retval
}

func setupMonthInfoDataForStartAndEndDate() -> CalendarData {
func setupMonthInfoDataForStartAndEndDate(with config: ConfigurationParameters? = nil) -> CalendarData {
var months = [Month]()
var monthMap = [Int: Int]()
var totalSections = 0
var totalDays = 0
if let validConfig = calendarDataSource?.configureCalendar(self) {

var validConfig = config
if validConfig == nil { validConfig = calendarDataSource?.configureCalendar(self) }
if let validConfig = validConfig {
let comparison = validConfig.calendar.compare(validConfig.startDate, to: validConfig.endDate, toGranularity: .nanosecond)
if comparison == ComparisonResult.orderedDescending {
assert(false, "Error, your start date cannot be greater than your end date\n")
Expand Down
8 changes: 4 additions & 4 deletions Sources/UserInteractionFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ extension JTAppleCalendarView {
initialScrollDate = date

let selectedDates = self.selectedDates
let layoutNeedsUpdating = reloadDelegateDataSource()
if layoutNeedsUpdating {
let data = reloadDelegateDataSource()
if data.shouldReload {
calendarViewLayout.invalidateLayout()
setupMonthInfoAndMap()
setupMonthInfoAndMap(with: data.configParameters)

self.theSelectedIndexPaths = []
self.theSelectedDates = []
Expand All @@ -192,7 +192,7 @@ extension JTAppleCalendarView {
delayedExecutionClosure.append(validCompletionHandler)
}

if !layoutNeedsUpdating { calendarViewLayout.shouldClearCacheOnInvalidate = false }
if !data.shouldReload { calendarViewLayout.shouldClearCacheOnInvalidate = false }
super.reloadData()
isReloadDataInProgress = false

Expand Down

0 comments on commit 05c6f51

Please sign in to comment.