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

Intergation custom table view to vc #4

Merged
merged 6 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion Sources/CalendarStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public struct TimelineStyle {
public var verticalDiff: CGFloat = 50
public var verticalInset: CGFloat = 10
public var leadingInset: CGFloat = 53
public var eventGap: CGFloat = 0
public var eventGap: CGFloat = 1
public init() {}
}

Expand Down
10 changes: 8 additions & 2 deletions Sources/DayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class DayView: UIView, TimelinePagerViewDelegate, DayHeaderViewDelegate {
}
}

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

public var horizontalSpacing: CGFloat = 0 {
didSet {
layoutTableView()
Expand Down Expand Up @@ -219,8 +225,8 @@ public class DayView: UIView, TimelinePagerViewDelegate, DayHeaderViewDelegate {
timelinePagerView.scrollToFirstEventIfNeeded(animated: animated)
}

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

public func reloadData() {
Expand Down
11 changes: 11 additions & 0 deletions Sources/Extensions/Date+DateOnly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ extension Date {
func year() -> Int {
return Calendar.current.component(.year, from: self)
}

func timeOnly() -> Float {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

честно сказать, так и не понял, что этот метод возвращает... Float... Time... В каких единицах измерения возвращается timeOnly?

let hour = Double(Calendar.current.component(.hour, from: Date()))
let minute = Double(Calendar.current.component(.minute, from: Date()))
var time = hour
let minutesInPercent = minute / 60.0
if minutesInPercent < 1 {
time = hour + minutesInPercent
}
return Float(time)
}
}
15 changes: 7 additions & 8 deletions Sources/Timeline/TimelineContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,22 @@ public final class TimelineContainer: UIScrollView {
}

public func scroollToCurrentTime(animated: Bool) {
let allDayViewHeight = timeline.allDayViewHeight
let padding = allDayViewHeight + 200
if let yToScroll = timeline.currentTimeYPosition {
setTimelineOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: animated)
}
let timeToScroll = Date().timeOnly() - 4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут еще какие-то магические 4 единицы чего-то отнимаются...

scrollTo(hour24: timeToScroll, animated: animated)
}

public func scrollTo(hour24: Float, animated: Bool = true) {
let percentToScroll = CGFloat(hour24 / 24)
let yToScroll = contentSize.height * percentToScroll
let padding: CGFloat = 8
setTimelineOffset(CGPoint(x: contentOffset.x, y: yToScroll - padding), animated: animated)
if let parent = parent?.parent as? CKPageViewController {
parent.commonOffset?.y = yToScroll
}
setTimelineOffset(CGPoint(x: contentOffset.x, y: yToScroll), animated: animated)
}

private func setTimelineOffset(_ offset: CGPoint, animated: Bool) {
let yToScroll = offset.y
let bottomOfScrollView = contentSize.height - bounds.size.height
let bottomOfScrollView = contentSize.height - bounds.size.height + 30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опять магическая цифра)

let newContentY = (yToScroll < bottomOfScrollView) ? yToScroll : bottomOfScrollView
setContentOffset(CGPoint(x: offset.x, y: newContentY), animated: animated)
}
Expand Down
14 changes: 11 additions & 3 deletions Sources/Timeline/TimelinePagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public final class TimelinePagerView: UIView, UIGestureRecognizerDelegate, UIScr
}

public var autoScrollToFirstEvent = false

public var minDate: Date?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавить бы комментарий с описанием, что это за минимальная дата и для чего она используется


private var pagingViewController = CKPageViewController(transitionStyle: .scroll,
navigationOrientation: .horizontal,
Expand Down Expand Up @@ -212,9 +214,11 @@ public final class TimelinePagerView: UIView, UIGestureRecognizerDelegate, UIScr
}
}

public func scrollToCurrentTime(animated: Bool) {
if let controller = currentTimeline {
controller.container.scroollToCurrentTime(animated: animated)
public func scrollToCurrentTimeIfNeeded(needToScroll: Bool, animated: Bool) {
if needToScroll {
if let controller = currentTimeline {
controller.container.scroollToCurrentTime(animated: animated)
}
}
}

Expand Down Expand Up @@ -456,6 +460,7 @@ public final class TimelinePagerView: UIView, UIGestureRecognizerDelegate, UIScr

self.pagingViewController.viewControllers?.first?.view.setNeedsLayout()
self.scrollToFirstEventIfNeeded(animated: true)
self.scrollToCurrentTimeIfNeeded(needToScroll: false, animated: true)
self.delegate?.timelinePager(timelinePager: self, didMoveTo: newDate)
}
}
Expand Down Expand Up @@ -500,6 +505,9 @@ public final class TimelinePagerView: UIView, UIGestureRecognizerDelegate, UIScr
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let containerController = viewController as? TimelineContainerController else { return nil }
let previousDate = calendar.date(byAdding: .day, value: -1, to: containerController.timeline.date)!
if let minDate = minDate {
guard previousDate >= minDate else { return nil }
}
let timelineContainerController = configureTimelineController(date: previousDate)
let offset = containerController.container.contentOffset
timelineContainerController.pendingContentOffset = offset
Expand Down