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
// import https://gist.github.com/JadenGeller/2cdcc441f936b4b0a7b331ccf13a78ac#file-monitorevents-swift | |
import SwiftUI | |
enum ScrollPhase: Hashable, Sendable { | |
case interactive | |
case momentum | |
case ended | |
} | |
struct ScrollAreaModifier: ViewModifier { |
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
struct HFold3DEffectModifier: ViewModifier { | |
var angle: Angle | |
var perspective: Double | |
var anchor: UnitPoint { | |
angle.radians >= 0 ? .leading : .trailing | |
} | |
func visualWidth(width: CGFloat) -> CGFloat { | |
width * cos(angle.radians) / (perspective * sin(abs(angle.radians)) + 1) |
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
import SwiftUI | |
// FIXME: Is there value to defining this DynamicProperty vs. inlining all this into LazyBindingView? | |
@propertyWrapper | |
struct LazyBinding<Value>: DynamicProperty { | |
var initialValue: Value | |
var makeBinding: () -> Binding<Value> | |
@State var binding: Binding<Value>? |
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
struct DynamicWidthTextEditor: View { | |
@Binding var text: String | |
// add spacing after each line to prevent flexible width text editor from reflowing before SwiftUI rerenders | |
var textWithTrailingBlocks: String { | |
text | |
.split(separator: "\n") | |
.map({ $0 + "█." }) | |
.joined(separator: "\n") | |
} |
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
extension NSEvent { | |
static func keyPress(_ keyPress: KeyPress) -> NSEvent? { | |
guard let eventType = EventType(keyPress.phase) else { return nil } | |
return .keyEvent( | |
with: eventType, | |
location: .zero, | |
modifierFlags: .init(keyPress.modifiers), | |
timestamp: ProcessInfo.processInfo.systemUptime, | |
windowNumber: 0, // TODO: Does it matter that this isn't accurate? | |
context: nil, |
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
import SwiftUI | |
struct BoundsLayout: Layout { | |
var bounds: (ProposedViewSize, LayoutSubview) -> CGRect | |
func makeCache(subviews: Subviews) -> CGRect { | |
.zero | |
} | |
func sizeThatFits( |
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
struct AsyncIteratorSequence<AsyncIterator: AsyncIteratorProtocol>: AsyncSequence { | |
typealias Element = AsyncIterator.Element | |
var iterator: AsyncIterator | |
init(_ iterator: AsyncIterator) { | |
self.iterator = iterator | |
} | |
func makeAsyncIterator() -> AsyncIterator { | |
return iterator |
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
actor Deferred<Value> { | |
enum State { | |
case waiting(Task<Value, Never>, CheckedContinuation<Value, Never>?) | |
case ready(Value) | |
} | |
var state: State? | |
init() async { | |
state = .waiting(Task { await withCheckedContinuation { continuation in | |
Task { |