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

Add event without .move #352

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion Sources/KVKCalendar/Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ public struct TimelineStyle {
public var scale: Scale? = Scale(min: 1, max: 6)
public var useDefaultCorderHeader = false
public var eventPreviewSize: CGSize? = CGSize(width: 150, height: 150)

/// Takes effect when `style.event.states` does not contain `.move`. `true`: create a new event at the long press; `false`: create at the start time.
public var createEventAtTouch = false

public var allLeftOffset: CGFloat {
widthTime + offsetTimeX + offsetLineLeft
}
Expand Down Expand Up @@ -889,6 +891,7 @@ extension TimelineStyle: Equatable {
&& compare(\.timeDividerColor)
&& compare(\.timeDividerFont)
&& compare(\.scale)
&& compare(\.createEventAtTouch)
}

}
Expand Down
5 changes: 5 additions & 0 deletions Sources/KVKCalendar/Timeline+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,12 @@ extension TimelineView {
eventPreviewSize = getEventPreviewSize()
}
var point = gesture.location(in: scrollView)
if style.timeline.createEventAtTouch && !style.event.states.contains(.move) {
let offset = eventPreviewYOffset - style.timeline.offsetEvent - 6
showChangingMinute(pointY: point.y, offset: offset)
}
point.y = (point.y - eventPreviewYOffset) - style.timeline.offsetEvent - 6

let time = movingMinuteLabel.time
var newEvent = Event(ID: Event.idForNewEvent)
newEvent.title = TextEvent(timeline: style.event.textForNewEvent)
Expand Down