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

Before sync 2024 03 #366

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions Sources/Timeline/EventDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public protocol EventDescriptor: AnyObject {
var textColor: UIColor {get}
var backgroundColor: UIColor {get}
var editedEvent: EventDescriptor? {get set}
var border: CAShapeLayer? {get}
func makeEditable() -> Self
func commitEditing()
}
18 changes: 14 additions & 4 deletions Sources/Timeline/EventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import UIKit
open class EventView: UIView {
public var descriptor: EventDescriptor?
public var color = SystemColors.label
public var border: CAShapeLayer?

public var contentHeight: CGFloat {
textView.frame.height
Expand Down Expand Up @@ -118,6 +119,7 @@ open class EventView: UIView {
private var drawsShadow = false

override open func layoutSubviews() {
self.border?.removeFromSuperlayer()
super.layoutSubviews()
textView.frame = {
if UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft {
Expand All @@ -143,10 +145,10 @@ open class EventView: UIView {
size: size)
last?.frame = CGRect(origin: CGPoint(x: layoutMargins.left, y: height - yPad - radius),
size: size)

if drawsShadow {
applySketchShadow(alpha: 0.13,
blur: 10)
if let border = descriptor?.border {
applyBorder(border: border)
} else if drawsShadow {
applySketchShadow(alpha: 0.13, blur: 10)
}
}

Expand All @@ -170,4 +172,12 @@ open class EventView: UIView {
layer.shadowPath = UIBezierPath(rect: rect).cgPath
}
}

private func applyBorder(border: CAShapeLayer) {
let borderOffset = 3.0
let path = CGRect(x: borderOffset, y: borderOffset, width: bounds.width - 2.0 * borderOffset, height: bounds.height - 2.0 * borderOffset)
border.path = UIBezierPath(rect: path).cgPath
self.border = border
layer.addSublayer(border)
}
}