This file contains hidden or 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 | |
import Dependencies | |
struct Foo: DependencyKey { | |
static var liveValue: Self { | |
.init { | |
"foo" | |
} | |
} | |
This file contains hidden or 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 | |
private struct LifetimeTask: ViewModifier { | |
@State @Reference private var hasAppeared = false | |
@State @Reference private var task: Task<Void, Never>? | |
let perform: () async -> Void | |
func body(content: Content) -> some View { | |
content | |
.onFirstAppear { |
This file contains hidden or 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 | |
private struct OnDestroy: ViewModifier { | |
let onDestroy: () -> Void | |
final class Lifetime { | |
var onDestroy: () -> Void = { } | |
deinit { onDestroy() } | |
} | |
@State var lifetime: Lifetime = .init() | |
func body(content: Content) -> some View { |
This file contains hidden or 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 | |
import Introspect | |
//TODO: what if we use more custom tags in nested hierarchy. We need to somehow confine them to a single level. | |
enum CustomTag: PreferenceKey { | |
static var defaultValue: [AnyHashable] = [] | |
static func reduce(value: inout [AnyHashable], nextValue: () -> [AnyHashable]) { | |
value.append(contentsOf: nextValue()) | |
} | |
} |
This file contains hidden or 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 | |
#if os(macOS) | |
import Cocoa | |
protocol ViewRepresentable: NSViewRepresentable { | |
func makeView(context: Context) -> NSViewType | |
func updateView(_ view: NSViewType, context: Context) | |
} | |
extension ViewRepresentable { | |
func makeNSView(context: Context) -> NSViewType { |
This file contains hidden or 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 MissionControlState<State> { | |
var currentState: State | |
} | |
enum MissionControlAction<Action> { | |
case app(Action) | |
case lldb | |
} | |
struct MissionControl<State, Action, Environment, Content: View>: View { | |
This file contains hidden or 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 FirebaseAuth | |
import Combine | |
extension PublishersNamespace where Base: FirebaseAuth.Auth { | |
var currentUser: AnyPublisher<User?, Never> { | |
let userSubject = PassthroughSubject<User?, Never>() | |
let handle = base.addStateDidChangeListener { auth, user in | |
userSubject.send(user) | |
} | |
This file contains hidden or 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
contents |
This file contains hidden or 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 | |
extension ForEach where Data == Range<Int>{ | |
init(_ v1: @autoclosure @escaping () -> Content) { | |
self.init(0..<1) { _ in | |
v1() | |
} | |
} | |
init<V1, V2>( | |
_ v1: @autoclosure @escaping () -> V1, |
This file contains hidden or 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
// I wrote this and then decided its an overengineered piece of bullshit code. Just deleting it makes me sad so let it forever take up space on Github | |
// a property that flips back to its default value when it is read | |
// TODO: does this have proper value semantics with the class inside? And do we even care? | |
@propertyWrapper struct ReadOnce<Value> { | |
init(initialValue: Value) { | |
defaultValue = initialValue | |
box = ValueBox(value: initialValue) | |
} | |
private let defaultValue: Value |
NewerOlder