-
Notifications
You must be signed in to change notification settings - Fork 334
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
[WIP] Custom event views support #274
Draft
RareScrap
wants to merge
4
commits into
richardtop:master
Choose a base branch
from
RareScrap:custom_event_views
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ab30c7d
feat(view): First sketch of support for custom event view
RareScrap 113bb5a
refactor(view): EventView was divided into EventView (as a base class…
RareScrap d3fb0aa
feat(view): Custom EventView support
RareScrap f459f05
bugfix(view): dequeue() no longer delivers views with an zero frame
RareScrap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// MyEvent.swift | ||
// CalendarApp | ||
// | ||
// Created by RareScrap on 22.10.2020. | ||
// Copyright © 2020 Richard Topchii. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CalendarKit | ||
|
||
class MyEvent: EventDescriptor { | ||
public var myVar = "asdasd" | ||
public var startDate = Date() | ||
public var endDate = Date() | ||
public var isAllDay = false | ||
public var text = "" | ||
public var attributedText: NSAttributedString? | ||
public var color = SystemColors.systemBlue { | ||
didSet { | ||
updateColors() | ||
} | ||
} | ||
public var backgroundColor = SystemColors.systemBlue.withAlphaComponent(0.3) | ||
public var textColor = SystemColors.label | ||
public var font = UIFont.boldSystemFont(ofSize: 12) | ||
public var userInfo: Any? | ||
public weak var editedEvent: EventDescriptor? { | ||
didSet { | ||
updateColors() | ||
} | ||
} | ||
|
||
public init() {} | ||
|
||
func makeEditable() -> Self { | ||
let cloned = MyEvent() | ||
cloned.startDate = startDate | ||
cloned.endDate = endDate | ||
cloned.isAllDay = isAllDay | ||
cloned.text = text | ||
cloned.attributedText = attributedText | ||
cloned.color = color | ||
cloned.backgroundColor = backgroundColor | ||
cloned.textColor = textColor | ||
cloned.userInfo = userInfo | ||
cloned.editedEvent = self | ||
return cloned as! Self | ||
} | ||
|
||
public func commitEditing() { | ||
guard let edited = editedEvent else {return} | ||
edited.startDate = startDate | ||
edited.endDate = endDate | ||
} | ||
|
||
private func updateColors() { | ||
(editedEvent != nil) ? applyEditingColors() : applyStandardColors() | ||
} | ||
|
||
private func applyStandardColors() { | ||
backgroundColor = color.withAlphaComponent(0.3) | ||
var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0 | ||
color.getHue(&h, saturation: &s, brightness: &b, alpha: &a) | ||
textColor = UIColor(hue: h, saturation: s, brightness: b * 0.4, alpha: a) | ||
} | ||
|
||
private func applyEditingColors() { | ||
backgroundColor = color | ||
textColor = .white | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these properties should be read-only, as the CalendarKit doesn't modify them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But in this case, we cannot use
EventDescriptor
as a generic type for custom descriptors. I find it quite convenient:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that's not a requirement by the library.
You're free to create own, stricter protocol requirement and use it. Meanwhile, it would inherit from
EventDescriptor
, so it would be perfectly compatible.