Skip to content

Instantly share code, notes, and snippets.

open class LKLabel : UILabel {
open override class var layerClass: AnyClass {
get {
return LKLabelLayer.self
}
}
/// The underlying attributed string drawn by the label, if set, the label ignores the `font`,
/// `textColor`, `shadowColor`, and `shadowOffset` properties.
/// If `.paragraphStyle` attribute is absent in the attributed string, it is created incorporating
extension LKLabel {
open override func action(for layer: CALayer, forKey event: String) -> CAAction? {
let result = super.action(for: layer, forKey: event)
if event == keyPath(\CALayer.bounds) && result != nil && UIView.inheritedAnimationDuration > 0 {
let textDrawingBoundsAction = LKBoundsDidChangeAction(fromBounds: layer.bounds)
let action = LKCompositeAction(actions:[result!, textDrawingBoundsAction])
return action
}
return result
}
class LKBoundsDidChangeAnimation : CABasicAnimation {
@objc var bounds : CGRect = CGRect.zero
override func copy(with zone: NSZone? = nil) -> Any {
let result = super.copy(with: zone)
if let action = result as? Self {
action.bounds = bounds
return action
}
return result
@edudnyk
edudnyk / TestsApp.swift
Last active November 13, 2024 04:51
SwiftUI Easter Eggs: Performance Benchmarking with _ViewTest and more
import SwiftUI
@main
struct App {
static func main() {
_TestApp().runBenchmarks([Benchmark()])
}
}
extension UIHostingController: _Test where Content == AnyView {}
@edudnyk
edudnyk / SheeInterface-ModalPresentationStyle.swift
Last active October 1, 2021 02:55
The snippet of the public interface provided by SheeKit
public enum ModalPresentationStyle {
/// The default presentation style chosen by the system.
case automatic
/// A presentation style that partially covers the underlying content.
///
/// - Parameters:
/// - properties: properties to assign to ``UISheetPresentationController``
case pageSheet(properties: SheetProperties? = nil)
/// A presentation style that displays the content centered in the screen.
///
@edudnyk
edudnyk / SheeInterface-SheetProperties.swift
Created October 1, 2021 02:52
The snippet of the public interface provided by SheeKit
public struct SheetProperties {
/// Set to true to cause the sheet to layout with an edge-attached appearance in compact height instead of full screen.
/// Default: ``false``
public var prefersEdgeAttachedInCompactHeight: Bool
/// Set to true to allow ``preferredContentSize`` to influence the width of the sheet when edge-attached.
/// When ``false``, the width of the sheet when edge-attached is always equal to the safe area width of the container.
/// The value of this property is not respected in compact width regular height.
/// Default: ``false``
public var widthFollowsPreferredContentSizeWhenEdgeAttached: Bool
@edudnyk
edudnyk / SheeInterface-UIViewControllerProxy.swift
Created October 1, 2021 02:53
The snippet of the public interface provided by SheeKit
public struct UIViewControllerProxy {
public var modalTransitionStyle: UIModalTransitionStyle = .coverVertical
public var modalPresentationCapturesStatusBarAppearance = false
public var disablesAutomaticKeyboardDismissal: Bool?
public var edgesForExtendedLayout: UIRectEdge = .all
public var extendedLayoutIncludesOpaqueBars: Bool = false
public var preferredContentSize: CGSize = .zero
public var preferredStatusBarStyle: UIStatusBarStyle?
public var prefersStatusBarHidden: Bool?
public var preferredStatusBarUpdateAnimation: UIStatusBarAnimation?
@edudnyk
edudnyk / SheeInterface-Modifiers.swift
Last active October 3, 2021 07:09
The snippet of the public interface provided by SheeKit
public struct DismissAction {
public func callAsFunction()
}
extension EnvironmentValues {
public internal(set) var shee_dismiss: DismissAction
public internal(set) var shee_isPresented: Bool
}
extension View {
@edudnyk
edudnyk / SheeImplementation-UIViewControllerRepresentable.swift
Last active October 2, 2021 14:43
Initial sandwich solution implementation in SheeKit
final class AdaptiveDelegate<Item>: NSObject, UIPopoverPresentationControllerDelegate, UISheetPresentationControllerDelegate where Item : Identifiable {
weak var sheetHost: SheetHostingController<Item>?
var dismissedByUserCallback: DismissAction?
var isInteractiveDismissDisabled = false
var selectedDetentIdentifierBinding: Binding<UISheetPresentationController.Detent.Identifier?>?
override init() {
super.init()
}
@edudnyk
edudnyk / SheeImplementation-SheetHostingController.swift
Last active October 1, 2021 04:26
Initial sandwich solution implementation in SheeKit
final class SheetHostingController<Item>: UIHostingController<AnyView> where Item : Identifiable {
var itemId: Item.ID?
var item: Item
var onDismiss: (() -> Void)?
init(rootView: AnyView, item: Item) {
self.itemId = item.id
self.item = item
super.init(rootView: rootView)
}