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 OverflowLayout: Layout { | |
var spacing = CGFloat(10) | |
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { | |
let containerWidth = proposal.replacingUnspecifiedDimensions().width | |
let sizes = subviews.map { $0.sizeThatFits(.unspecified) } | |
return layout(sizes: sizes, containerWidth: containerWidth).size | |
} | |
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { |
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
// | |
// SFSymbolImage.swift | |
// SFSymbolVariableValueAnimationWrong | |
// | |
// Created by Matthew Young on 12/22/22. | |
// | |
import SwiftUI | |
struct AnimatableVariableValueModifier: Animatable, 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
// | |
// ContentView.swift | |
// SwiftUIPlayground | |
// | |
// Created by BJ Homer on 4/26/21. | |
// | |
import SwiftUI | |
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 UIKit | |
class ViewController: UIViewController { | |
let textViewWrapper = TextViewWrapper() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// The problem view! I want to add this one to my set of Auto Layout constraints, | |
// even though it's not using Auto Layout internally. |
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 UIKit | |
import Combine | |
public extension Task { | |
/// Keep a reference to a task that can be cancelled. | |
func store(in set: inout Set<AnyCancellable>) { | |
set.insert(AnyCancellable { | |
self.cancel() | |
}) | |
} |
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
public extension Task { | |
/// Cancels this `Task` when the surrounding `Task` is cancelled. | |
/// This is necessary if `Task {}` and `Task.detached {}` | |
/// should be automatically cancelled - otherwise, such Tasks | |
/// just run until finished. | |
/// | |
/// Usage: | |
/// | |
/// await Task { await myAsyncFunc() }.autoCancel() | |
func autoCancel() async -> Void { |
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 Foundation | |
// Props to @pteasima and @MichalKleinJr: | |
// https://twitter.com/pteasima/status/1544723987606929408?s=21&t=JL1oIuL87Ms_VPBQBZQ7Rg | |
public extension AsyncSequence { | |
func eraseToAsyncStream() -> AsyncStream<Element> { | |
return AsyncStream { continuation in | |
let task = Task { | |
do { | |
for try await value in self { |
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 Foundation | |
#if canImport(Cocoa) | |
import Cocoa | |
#elseif canImport(UIKit) | |
import UIKit | |
#endif | |
public struct EdgeInsets { | |
var top, bottom, leading, trailing: CGFloat |
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
/// A type-erased task that you can store in a collection | |
/// to allow you to cancel at a later date. | |
/// | |
/// Upon deinit of the task, the task will be cancelled | |
/// automatically. Similar to Combine's AnyCancellable. | |
final class AnyTask { | |
/// Call this cancellation block to cancel the task manually. | |
let cancel: () -> Void | |
/// Checks whether the task is cancelled. |
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 | |
import Combine | |
struct ContentView: View { | |
var body: some View { | |
TaskList(tasks: [ | |
Task(id: 1, title: "Task 1", isCompleted: false), | |
Task(id: 2, title: "Task 2", isCompleted: false), | |
Task(id: 3, title: "Task 3", isCompleted: true), |
NewerOlder