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

. #360

Closed
Closed

. #360

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2ffdcec
Injection tableView to CalendarKit supporting
igover Sep 26, 2022
307f4be
Added delegate methods to check calendar date did set after scroll
igover Sep 27, 2022
6671fcc
Added horizontal table spacing
igover Sep 27, 2022
7aaf305
Адаптация панели дат под iPad (поведение аналогичное iPhone)
igover Sep 28, 2022
4de3494
Add selected date
igover Sep 29, 2022
f92656d
Remove unnecessary code for layoutSubviews
igover Sep 29, 2022
61e0ad4
Fix layout for custom tableView
igover Sep 30, 2022
c0e1064
Code cleaning
igover Oct 3, 2022
5cd2c6a
Supporting switch between custom TableView and TimeLineView
igover Oct 3, 2022
a061cbe
Remove DayViewController
igover Oct 3, 2022
4db0d08
Add TODO for renaming
igover Oct 3, 2022
915e71b
Added UIStackView to show event info
igover Oct 5, 2022
658294e
Fixed switching calendar view mode
igover Oct 5, 2022
83c2c40
Color palette changed
igover Oct 6, 2022
ca57275
Renaming EventView to AppointmentView
igover Oct 6, 2022
78a018c
Added date label for dayMode (initial commit)
igover Oct 6, 2022
919f8f1
Added date label for dayMode (implemented layout)
igover Oct 6, 2022
20168b9
Added date formatter for date view
igover Oct 6, 2022
f5aeeaa
Add separator for swipeLabelView
igover Oct 7, 2022
b424960
Code cleaning
igover Oct 10, 2022
f9e3ed0
Fix header size
igover Oct 10, 2022
0998473
Merge pull request #1 from igover/intergation-custom-table-view-to-VC
igover Oct 10, 2022
9d4a0f4
Save calendar mode if needed
igover Oct 10, 2022
f0edfd7
Change alpha for background AppointmentView
igover Oct 10, 2022
b67ae7f
Merge pull request #2 from igover/intergation-custom-table-view-to-VC
igover Oct 10, 2022
5641f7c
Save current time position after swipe to next/previous day
igover Oct 24, 2022
c5de699
Save current time position (intermediate commit)
igover Oct 24, 2022
2aad6ab
Save current time for next/previous day (implemented)
igover Oct 25, 2022
ae0d17e
Layout optimization fix
igover Oct 26, 2022
be8b6b3
Merge pull request #3 from igover/intergation-custom-table-view-to-VC
igover Oct 26, 2022
c6442c0
Scroll to current time minus 4 hours
igover Oct 31, 2022
91eca48
Scroll to current time minus 4 hours (implemented)
igover Nov 1, 2022
f710bbd
Change events gap (in case if second event starts in the end time of …
igover Nov 1, 2022
1dcac2c
Added min date for Public API
igover Nov 2, 2022
5af918a
Fix logic for min date
igover Nov 2, 2022
4d4c923
Fix scroll to current time method
igover Nov 3, 2022
d08e1e1
Merge pull request #4 from igover/intergation-custom-table-view-to-VC
igover Nov 3, 2022
b842cf2
Fix layout for subject and location
igover Nov 7, 2022
3d996f4
Merge pull request #5 from igover/intergation-custom-table-view-to-VC
igover Nov 8, 2022
be69b9f
Appointment view. Alpha Color fix
igover Mar 15, 2023
09ffc8b
Merge pull request #6 from Workspad/master
firuz1844 Mar 15, 2023
d46b8c9
Merge pull request #1 from igover/master
firuz1844 Mar 15, 2023
53e2f03
Add icon for private events.
igover May 24, 2023
1508c16
Added display event with zero duration.
igover May 26, 2023
890459d
Merge pull request #7 from Workspad/master
firuz1844 May 29, 2023
043eae0
Feature #11135 - Displaying events
Jun 9, 2023
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let package = Package(
name: "CalendarKit",
defaultLocalization: "en",
platforms: [
.iOS(.v10),
.iOS(.v13),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand Down
21 changes: 11 additions & 10 deletions Sources/CalendarStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ public struct DayHeaderStyle {
public var daySymbols = DaySymbolsStyle()
public var daySelector = DaySelectorStyle()
public var swipeLabel = SwipeLabelStyle()
public var backgroundColor = SystemColors.systemBackground
public var backgroundColor = SystemColors.tertiarySystemBackground
public var separatorColor = SystemColors.systemSeparator
public init() {}
}

public struct DaySelectorStyle {
public var activeTextColor = SystemColors.systemBackground
public var selectedBackgroundColor = SystemColors.label

public var activeTextColor = UIColor.white
public var selectedBackgroundColor = UIColor.systemBlue
public var borderColor = UIColor.systemBlue

public var weekendTextColor = SystemColors.secondaryLabel
public var inactiveTextColor = SystemColors.label
public var inactiveBackgroundColor = UIColor.clear

public var todayInactiveTextColor = SystemColors.systemRed
public var todayInactiveTextColor = SystemColors.label
public var todayActiveTextColor = UIColor.white
public var todayActiveBackgroundColor = SystemColors.systemRed
public var todayActiveBackgroundColor = SystemColors.systemBlue

public var font = UIFont.systemFont(ofSize: 18)
public var todayFont = UIFont.boldSystemFont(ofSize: 18)
Expand All @@ -54,7 +55,7 @@ public struct DaySymbolsStyle {

public struct SwipeLabelStyle {
public var textColor = SystemColors.label
public var font = UIFont.systemFont(ofSize: 15)
public var font = UIFont.systemFont(ofSize: 16, weight: .medium)
public init() {}
}

Expand All @@ -63,16 +64,16 @@ public struct TimelineStyle {
public var timeIndicator = CurrentTimeIndicatorStyle()
public var timeColor = SystemColors.secondaryLabel
public var separatorColor = SystemColors.systemSeparator
public var backgroundColor = SystemColors.systemBackground
public var backgroundColor = SystemColors.tertiarySystemBackground
public var font = UIFont.boldSystemFont(ofSize: 11)
public var dateStyle : DateStyle = .system
public var eventsWillOverlap: Bool = false
public var minimumEventDurationInMinutesWhileEditing: Int = 30
public var splitMinuteInterval: Int = 15
public var verticalDiff: CGFloat = 50
public var verticalDiff: CGFloat = 60
public var verticalInset: CGFloat = 10
public var leadingInset: CGFloat = 53
public var eventGap: CGFloat = 0
public var eventGap: CGFloat = 1
public init() {}
}

Expand Down
165 changes: 128 additions & 37 deletions Sources/DayView.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import UIKit

public protocol DayViewDelegate: AnyObject {
func dayViewDidSelectEventView(_ eventView: EventView)
func dayViewDidLongPressEventView(_ eventView: EventView)
func dayViewDidSelectEventView(_ eventView: AppointmentView)
func dayViewDidLongPressEventView(_ eventView: AppointmentView)
func dayView(dayView: DayView, didTapTimelineAt date: Date)
func dayView(dayView: DayView, didLongPressTimelineAt date: Date)
func dayViewDidBeginDragging(dayView: DayView)
func dayViewDidTransitionCancel(dayView: DayView)
func dayView(dayView: DayView, willMoveTo date: Date)
func dayView(dayView: DayView, didMoveTo date: Date)
func dayView(dayView: DayView, didUpdate event: EventDescriptor)
func didTapOnDate(date: Date)
func didMoveHeaderViewToDate(date: Date)
}

public class DayView: UIView, TimelinePagerViewDelegate {
public enum CalendarMode {
case agenda
case day
}

public class DayView: UIView, TimelinePagerViewDelegate, DayHeaderViewDelegate {
public weak var dataSource: EventDataSource? {
get {
timelinePagerView.dataSource
Expand All @@ -23,6 +30,12 @@ public class DayView: UIView, TimelinePagerViewDelegate {
}

public weak var delegate: DayViewDelegate?

public var calendarMode: CalendarMode? {
didSet {
switchModeTo(calendarMode: calendarMode!)
}
}

/// Hides or shows header view
public var isHeaderViewVisible = true {
Expand All @@ -33,12 +46,29 @@ public class DayView: UIView, TimelinePagerViewDelegate {
configureLayout()
}
}

public var minDate: Date? {
didSet {
timelinePagerView.minDate = minDate
}
}

public var horizontalSpacing: CGFloat = 0 {
didSet {
layoutTableView()
layoutTimelinePagerView()
switchModeTo(calendarMode: calendarMode ?? .agenda)
}
}

public var timelineScrollOffset: CGPoint {
timelinePagerView.timelineScrollOffset
}

private static let headerVisibleHeight: CGFloat = 88

var agendaHeightConstraint: NSLayoutConstraint!
var dayHeightConstraint: NSLayoutConstraint!

private static let headerVisibleHeight: CGFloat = 68
public var headerHeight: CGFloat = headerVisibleHeight

public var autoScrollToFirstEvent: Bool {
Expand All @@ -49,9 +79,23 @@ public class DayView: UIView, TimelinePagerViewDelegate {
timelinePagerView.autoScrollToFirstEvent = value
}
}

public var timeIntervalBefore: Float {
get {
timelinePagerView.timeIntervalBefore
}
set (value) {
timelinePagerView.timeIntervalBefore = value
}
}

public let dayHeaderView: DayHeaderView
public let timelinePagerView: TimelinePagerView
public var tableView: UITableView? {
didSet {
addTableView()
}
}

public var state: DayViewState? {
didSet {
Expand All @@ -61,7 +105,7 @@ public class DayView: UIView, TimelinePagerViewDelegate {
}

public var calendar: Calendar = Calendar.autoupdatingCurrent

public var eventEditingSnappingBehavior: EventEditingSnappingBehavior {
get {
timelinePagerView.eventEditingSnappingBehavior
Expand Down Expand Up @@ -94,39 +138,84 @@ public class DayView: UIView, TimelinePagerViewDelegate {
super.init(coder: aDecoder)
configure()
}

private func addTableView() {
guard let tableView = tableView else { return }
addSubview(tableView)
}

private func configure() {
addSubview(timelinePagerView)
addSubview(dayHeaderView)

agendaHeightConstraint = dayHeaderView.heightAnchor.constraint(equalToConstant: 68)
dayHeightConstraint = dayHeaderView.heightAnchor.constraint(equalToConstant: 98)

configureLayout()
timelinePagerView.delegate = self
dayHeaderView.delegate = self

if state == nil {
let newState = DayViewState(date: Date(), calendar: calendar)
newState.move(to: Date())
state = newState
}

if calendarMode == nil {
switchModeTo(calendarMode: .agenda)
}
}

private func configureLayout() {
if #available(iOS 11.0, *) {
dayHeaderView.translatesAutoresizingMaskIntoConstraints = false
timelinePagerView.translatesAutoresizingMaskIntoConstraints = false

dayHeaderView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor).isActive = true
dayHeaderView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor).isActive = true
dayHeaderView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor).isActive = true
let heightConstraint = dayHeaderView.heightAnchor.constraint(equalToConstant: headerHeight)
heightConstraint.priority = .defaultLow
heightConstraint.isActive = true

timelinePagerView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor).isActive = true
timelinePagerView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor).isActive = true
timelinePagerView.topAnchor.constraint(equalTo: dayHeaderView.bottomAnchor).isActive = true
timelinePagerView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
private func switchModeTo(calendarMode: CalendarMode) {
dayHeaderView.switchModeTo(calendarMode: calendarMode)
switch calendarMode {
case .agenda:
tableView?.isHidden = false
timelinePagerView.isHidden = true
NSLayoutConstraint.deactivate([dayHeightConstraint])
NSLayoutConstraint.activate([agendaHeightConstraint])
case .day:
tableView?.isHidden = true
timelinePagerView.isHidden = false
NSLayoutConstraint.deactivate([agendaHeightConstraint])
NSLayoutConstraint.activate([dayHeightConstraint])
}
}
}


private func configureLayout() {
dayHeaderView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
dayHeaderView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
dayHeaderView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
dayHeaderView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
agendaHeightConstraint
])
}

private func layoutTableView() {
guard let tableView = tableView else { return }
tableView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: dayHeaderView.bottomAnchor),
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor, constant: horizontalSpacing),
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor, constant: -horizontalSpacing),
tableView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
}

private func layoutTimelinePagerView() {
timelinePagerView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
timelinePagerView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor, constant: horizontalSpacing),
timelinePagerView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor, constant: -horizontalSpacing),
timelinePagerView.topAnchor.constraint(equalTo: dayHeaderView.bottomAnchor),
timelinePagerView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
}

public func updateStyle(_ newStyle: CalendarStyle) {
style = newStyle
dayHeaderView.updateStyle(style.header)
Expand All @@ -144,6 +233,10 @@ public class DayView: UIView, TimelinePagerViewDelegate {
public func scrollToFirstEventIfNeeded(animated: Bool = true) {
timelinePagerView.scrollToFirstEventIfNeeded(animated: animated)
}

public func scrollToCurrentTime(animated: Bool = true) {
timelinePagerView.scrollToCurrentTime(animated: animated)
}

public func reloadData() {
timelinePagerView.reloadData()
Expand All @@ -153,17 +246,6 @@ public class DayView: UIView, TimelinePagerViewDelegate {
state?.move(to: date)
}

override public func layoutSubviews() {
super.layoutSubviews()
if #available(iOS 11, *) {} else {
dayHeaderView.frame = CGRect(origin: CGPoint(x: 0, y: layoutMargins.top),
size: CGSize(width: bounds.width, height: headerHeight))
let timelinePagerHeight = bounds.height - dayHeaderView.frame.maxY
timelinePagerView.frame = CGRect(origin: CGPoint(x: 0, y: dayHeaderView.frame.maxY),
size: CGSize(width: bounds.width, height: timelinePagerHeight))
}
}

public func transitionToHorizontalSizeClass(_ sizeClass: UIUserInterfaceSizeClass) {
dayHeaderView.transitionToHorizontalSizeClass(sizeClass)
updateStyle(style)
Expand All @@ -183,10 +265,10 @@ public class DayView: UIView, TimelinePagerViewDelegate {

// MARK: TimelinePagerViewDelegate

public func timelinePagerDidSelectEventView(_ eventView: EventView) {
public func timelinePagerDidSelectEventView(_ eventView: AppointmentView) {
delegate?.dayViewDidSelectEventView(eventView)
}
public func timelinePagerDidLongPressEventView(_ eventView: EventView) {
public func timelinePagerDidLongPressEventView(_ eventView: AppointmentView) {
delegate?.dayViewDidLongPressEventView(eventView)
}
public func timelinePagerDidBeginDragging(timelinePager: TimelinePagerView) {
Expand All @@ -210,4 +292,13 @@ public class DayView: UIView, TimelinePagerViewDelegate {
public func timelinePager(timelinePager: TimelinePagerView, didUpdate event: EventDescriptor) {
delegate?.dayView(dayView: self, didUpdate: event)
}

// MARK: - DayViewDelegate
public func didTapOpDate(date: Date) {
delegate?.didTapOnDate(date: date)
}

public func didMoveHeaderViewToDate(date: Date) {
delegate?.didMoveHeaderViewToDate(date: date)
}
}
Loading