Skip to content

Commit

Permalink
Feature added: Horizontal scrollable Range #29 #31 #32 #36
Browse files Browse the repository at this point in the history
  • Loading branch information
zjfjack authored Dec 18, 2018
2 parents d0bbd35 + 12d4ddf commit 1bb8261
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ class CustomViewController: UIViewController {
visibleTime: time8AM)
calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourGridDivision: selectedData.hourGridDivision))
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

extension CustomViewController: JZBaseViewDelegate {
Expand Down Expand Up @@ -110,11 +105,11 @@ extension CustomViewController: OptionsViewDelegate {
numOfDays: numOfDays,
scrollType: calendarWeekView.scrollType,
firstDayOfWeek: firstDayOfWeek,
hourGridDivision: calendarWeekView.flowLayout.hourGridDivision)
hourGridDivision: calendarWeekView.flowLayout.hourGridDivision,
scrollableRange: calendarWeekView.scrollableRange)
return viewModel.currentSelectedData
}


func finishUpdate(selectedData: OptionsSelectedData) {

// Update numOfDays
Expand All @@ -129,6 +124,8 @@ extension CustomViewController: OptionsViewDelegate {
// Update Scroll Type
if selectedData.scrollType != viewModel.currentSelectedData.scrollType {
calendarWeekView.scrollType = selectedData.scrollType
// If you want to change the scrollType without forceReload, you should call setHorizontalEdgesOffsetX
calendarWeekView.setHorizontalEdgesOffsetX()
}
// Update FirstDayOfWeek
if selectedData.firstDayOfWeek != viewModel.currentSelectedData.firstDayOfWeek {
Expand All @@ -138,6 +135,10 @@ extension CustomViewController: OptionsViewDelegate {
if selectedData.hourGridDivision != viewModel.currentSelectedData.hourGridDivision {
calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourGridDivision: selectedData.hourGridDivision))
}
// Update scrollableRange
if selectedData.scrollableRange != viewModel.currentSelectedData.scrollableRange {
calendarWeekView.scrollableRange = selectedData.scrollableRange
}
}

private func updateNaviBarTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ class DefaultViewController: UIViewController {
firstDayOfWeek: selectedData.firstDayOfWeek)
calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourGridDivision: selectedData.hourGridDivision))
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

extension DefaultViewController: JZBaseViewDelegate {
Expand Down Expand Up @@ -107,7 +102,8 @@ extension DefaultViewController: OptionsViewDelegate {
numOfDays: numOfDays,
scrollType: calendarWeekView.scrollType,
firstDayOfWeek: firstDayOfWeek,
hourGridDivision: calendarWeekView.flowLayout.hourGridDivision)
hourGridDivision: calendarWeekView.flowLayout.hourGridDivision,
scrollableRange: calendarWeekView.scrollableRange)
return viewModel.currentSelectedData
}

Expand All @@ -125,6 +121,8 @@ extension DefaultViewController: OptionsViewDelegate {
// Update Scroll Type
if selectedData.scrollType != viewModel.currentSelectedData.scrollType {
calendarWeekView.scrollType = selectedData.scrollType
// If you want to change the scrollType without forceReload, you should call setHorizontalEdgesOffsetX
calendarWeekView.setHorizontalEdgesOffsetX()
}
// Update FirstDayOfWeek
if selectedData.firstDayOfWeek != viewModel.currentSelectedData.firstDayOfWeek {
Expand All @@ -134,7 +132,10 @@ extension DefaultViewController: OptionsViewDelegate {
if selectedData.hourGridDivision != viewModel.currentSelectedData.hourGridDivision {
calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourGridDivision: selectedData.hourGridDivision))
}

// Update scrollableRange
if selectedData.scrollableRange != viewModel.currentSelectedData.scrollableRange {
calendarWeekView.scrollableRange = selectedData.scrollableRange
}
}

private func updateNaviBarTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ class ExampleOptionsViewController: UIViewController {
var firstDayOfWeek: DayOfWeek? = nil
let dataList = viewModel.optionsData
let viewType = dataList[0].selectedValue as! ViewType
let scrollableRange: (Date?, Date?)
if dataList[2].selectedValue as! Int == 7 {
firstDayOfWeek = dataList[3].selectedValue as? DayOfWeek
scrollType = dataList[4].selectedValue as! JZScrollType
hourGridDivision = dataList[5].selectedValue as! JZHourGridDivision
scrollableRange = (dataList[6].selectedValue as? Date, dataList[7].selectedValue as? Date)
} else {
scrollType = dataList[3].selectedValue as! JZScrollType
hourGridDivision = dataList[4].selectedValue as! JZHourGridDivision
scrollableRange = (dataList[5].selectedValue as? Date, dataList[6].selectedValue as? Date)
}

let selectedData = OptionsSelectedData(viewType: viewType,
date: dataList[1].selectedValue as! Date,
numOfDays: dataList[2].selectedValue as! Int,
scrollType: scrollType,
firstDayOfWeek: firstDayOfWeek,
hourGridDivision: hourGridDivision)
hourGridDivision: hourGridDivision,
scrollableRange: scrollableRange)

guard viewType == viewModel.perviousSelectedData.viewType else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class OptionsTableViewCell: UITableViewCell {
setupNormalPickerView()
setupDatePicker()

if data.subject == .currentDate {
let noIndexData: [OptionSectionType] = [.currentDate, .scrollableRangeStart, .scrollableRangeEnd]
if noIndexData.contains(data.subject) {
pickerView.isHidden = true
datePicker.isHidden = false
datePicker.setDate(pickerData.selectedValue as! Date, animated: false)
datePicker.setDate(pickerData.selectedValue as? Date ?? Date(), animated: false)
} else {
pickerView.isHidden = false
datePicker.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ enum OptionSectionType: String {
case scrollType = "Scroll Type"
case firstDayOfWeek = "First Day Of Week"
case hourGridDivision = "Hour Grid Division"
case scrollableRangeStart = "Scrollable Range Start Date"
case scrollableRangeEnd = "Scrollable Range End Date"
}

struct OptionsSelectedData {
Expand All @@ -74,14 +76,16 @@ struct OptionsSelectedData {
var scrollType: JZScrollType
var firstDayOfWeek: DayOfWeek?
var hourGridDivision: JZHourGridDivision
var scrollableRange: (startDate: Date?, endDate: Date?)

init(viewType: ViewType, date: Date, numOfDays: Int, scrollType: JZScrollType, firstDayOfWeek: DayOfWeek?, hourGridDivision: JZHourGridDivision) {
init(viewType: ViewType, date: Date, numOfDays: Int, scrollType: JZScrollType, firstDayOfWeek: DayOfWeek?, hourGridDivision: JZHourGridDivision, scrollableRange: (Date?, Date?)) {
self.viewType = viewType
self.date = date
self.numOfDays = numOfDays
self.scrollType = scrollType
self.firstDayOfWeek = firstDayOfWeek
self.hourGridDivision = hourGridDivision
self.scrollableRange = scrollableRange
}
}

Expand All @@ -96,7 +100,9 @@ class OptionsViewModel: NSObject {
ExpandableData(subject: .currentDate),
ExpandableData(subject: .numOfDays, categories: Array(1...10)),
ExpandableData(subject: .scrollType, categories: [JZScrollType.pageScroll, JZScrollType.sectionScroll]),
ExpandableData(subject: .hourGridDivision, categories: hourDivisionCategories)
ExpandableData(subject: .hourGridDivision, categories: hourDivisionCategories),
ExpandableData(subject: .scrollableRangeStart),
ExpandableData(subject: .scrollableRangeEnd)
]
}()
let perviousSelectedData: OptionsSelectedData
Expand All @@ -110,6 +116,8 @@ class OptionsViewModel: NSObject {
optionsData[2].selectedValue = selectedData.numOfDays
optionsData[3].selectedValue = selectedData.scrollType
optionsData[4].selectedValue = selectedData.hourGridDivision
optionsData[5].selectedValue = selectedData.scrollableRange.startDate
optionsData[6].selectedValue = selectedData.scrollableRange.endDate
if let selectedDayOfWeek = selectedData.firstDayOfWeek {
self.insertDayOfWeekToData(firstDayOfWeek: selectedDayOfWeek)
}
Expand All @@ -132,9 +140,21 @@ class OptionsViewModel: NSObject {
return (data.selectedValue! as! DayOfWeek).dayName
case .hourGridDivision:
return (data.selectedValue! as! JZHourGridDivision).displayText
case .scrollableRangeStart:
return getScrollableRangeSubTitle(data.selectedValue as? Date)
case .scrollableRangeEnd:
return getScrollableRangeSubTitle(data.selectedValue as? Date)
}
}

func getScrollableRangeSubTitle(_ date: Date?) -> String {
var str = "nil"
if let date = date {
str = dateFormatter.string(from: date)
}
return str
}

func insertDayOfWeekToData(firstDayOfWeek: DayOfWeek) {
let dayOfWeekData = ExpandableData(subject: .firstDayOfWeek, categories: DayOfWeek.dayOfWeekList)
dayOfWeekData.selectedValue = firstDayOfWeek
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class LongPressViewController: UIViewController {
calendarWeekView.setupCalendar(numOfDays: 3,
setDate: Date(),
allEvents: viewModel.eventsByDate,
scrollType: .pageScroll)
scrollType: .pageScroll,
scrollableRange: (nil, nil))
}

// LongPress delegate, datasorce and type setup
Expand All @@ -60,11 +61,6 @@ class LongPressViewController: UIViewController {
firstDayOfWeek: selectedData.firstDayOfWeek)
calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourGridDivision: selectedData.hourGridDivision))
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

extension LongPressViewController: JZBaseViewDelegate {
Expand Down Expand Up @@ -144,16 +140,17 @@ extension LongPressViewController: OptionsViewDelegate {
numOfDays: numOfDays,
scrollType: calendarWeekView.scrollType,
firstDayOfWeek: firstDayOfWeek,
hourGridDivision: calendarWeekView.flowLayout.hourGridDivision)
hourGridDivision: calendarWeekView.flowLayout.hourGridDivision,
scrollableRange: calendarWeekView.scrollableRange)
return viewModel.currentSelectedData
}

func finishUpdate(selectedData: OptionsSelectedData) {

// Update numOfDays
if selectedData.numOfDays != viewModel.currentSelectedData.numOfDays {
calendarWeekView.numOfDays = selectedData.numOfDays
calendarWeekView.refreshWeekView()
updateNaviBarTitle()
}
// Update Date
if selectedData.date != viewModel.currentSelectedData.date {
Expand All @@ -162,6 +159,8 @@ extension LongPressViewController: OptionsViewDelegate {
// Update Scroll Type
if selectedData.scrollType != viewModel.currentSelectedData.scrollType {
calendarWeekView.scrollType = selectedData.scrollType
// If you want to change the scrollType without forceReload, you should call setHorizontalEdgesOffsetX
calendarWeekView.setHorizontalEdgesOffsetX()
}
// Update FirstDayOfWeek
if selectedData.firstDayOfWeek != viewModel.currentSelectedData.firstDayOfWeek {
Expand All @@ -171,6 +170,10 @@ extension LongPressViewController: OptionsViewDelegate {
if selectedData.hourGridDivision != viewModel.currentSelectedData.hourGridDivision {
calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourGridDivision: selectedData.hourGridDivision))
}
// Update scrollableRange
if selectedData.scrollableRange != viewModel.currentSelectedData.scrollableRange {
calendarWeekView.scrollableRange = selectedData.scrollableRange
}
}

private func updateNaviBarTitle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension UIView {
}
}

//bottomAnchor & trailingAnchor should be negative
// bottomAnchor & trailingAnchor should be negative
func setAnchorConstraintsEqualTo(widthAnchor: CGFloat?=nil, heightAnchor: CGFloat?=nil, topAnchor: (NSLayoutYAxisAnchor,CGFloat)?=nil, bottomAnchor: (NSLayoutYAxisAnchor,CGFloat)?=nil, leadingAnchor: (NSLayoutXAxisAnchor,CGFloat)?=nil, trailingAnchor: (NSLayoutXAxisAnchor,CGFloat)?=nil) {

self.translatesAutoresizingMaskIntoConstraints = false
Expand Down
4 changes: 2 additions & 2 deletions Example/JZCalendarWeekViewExample/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.5.7</string>
<string>0.6.0</string>
<key>CFBundleVersion</key>
<string>18121401</string>
<string>18121801</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
2 changes: 1 addition & 1 deletion JZCalendarWeekView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JZCalendarWeekView"
s.version = "0.5.7"
s.version = "0.6.0"
s.summary = "Calendar Week & Day View in iOS Swift"
s.homepage = "https://github.com/zjfjack/JZCalendarWeekView"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion JZCalendarWeekView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.5.7</string>
<string>0.6.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
Loading

0 comments on commit 1bb8261

Please sign in to comment.