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 2 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
4 changes: 2 additions & 2 deletions Sources/DayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,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
9 changes: 6 additions & 3 deletions Sources/Timeline/TimelinePagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,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 +458,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