Skip to content

Instantly share code, notes, and snippets.

View mac-cain13's full-sized avatar

Mathijs Kadijk mac-cain13

View GitHub Profile
@mac-cain13
mac-cain13 / AccessibleHStack.swift
Created July 9, 2020 07:19
SwiftUI - AccessibleHStack
//
// AccessibleHStack.swift
//
// Created by Mathijs Kadijk on 08/07/2020.
//
import SwiftUI
/// HStack that will switch to a VStack when the horizontal size class is compact and the content size category is set to an accessibility size option
struct AccessibleHStack<Content>: View where Content: View {
@mac-cain13
mac-cain13 / Readme.md
Last active July 21, 2020 20:22
SwiftUI - ScrollViewSpy

ScrollViewLongPressSpy

Unleash the power of UIScrollView when just using SwiftUI ScrollView.

What is it?

A dummy "spy" view you can add inside your ScrollView that will attach a UILongPressGestureRecognizer to it and gives you a binding to the point where the finger is in the direct superview of the spy.

Why do I need it?

SwiftUI ScrollView is getting better every release, but currently (iOS 14) you can't add extra gesture recognizers. This is often needed for more complex interactions, this little spy gets that job done.

Is this the recommended way to add complex ScrollView behaviour?

@swhitty
swhitty / Mutex.swift
Last active June 2, 2026 08:45
Backports the Swift 6 type Mutex<Value> to all Apple platforms that support OSAllocatedUnfairLock
// Backports the Swift 6 type Mutex<Value> to all Darwin platforms via OSAllocatedUnfairLock.
// Lightweight version of https://github.com/swhitty/swift-mutex
// Feel free to use any part of this gist.
import struct os.OSAllocatedUnfairLock
// Backports the Swift 6.0 Mutex API
@available(iOS, introduced: 16.0, deprecated: 18.0, message: "use Mutex from Synchronization module")
@available(macOS, introduced: 13.0, deprecated: 15.0, message: "use Mutex from Synchronization module")
public struct Mutex<Value: ~Copyable>: @unchecked Sendable, ~Copyable {