Skip to content

Instantly share code, notes, and snippets.

View anthonycastelli's full-sized avatar

Anthony anthonycastelli

View GitHub Profile
@gavinmn
gavinmn / KeyboardAttachedView.swift
Created August 20, 2024 02:38
Attach a view to the keyboard with interactive dismissal support
//
// ContentView.Swift
// KeyboardAttachedView
//
// Created by Gavin Nelson on 8/19/24.
//
import SwiftUI
import UIKit
@christianselig
christianselig / LongPressButton.swift
Last active November 4, 2024 06:52
How to accomplish a long-pressable button in SwiftUI with two different techniques. The first just uses SwiftUI but due to the simultaneous gesture requirement you also have to ensure both don't fire concurrently. The second uses UIKit and wraps UIButton and UILongPressGestureRecognizer which natively handles this behavior.
import SwiftUI
// PURE SwiftUI way with State tracking to prevent double events
struct ContentView: View {
@State private var ignoreTapEvent = false
var body: some View {
Button {
guard !ignoreTapEvent else {
//
// VolumePopupView.swift
//
// Created by Alex Rosenberg on 1/24/24.
//
import SwiftUI
import AVFoundation
import MediaPlayer
@KhaosT
KhaosT / HDMI on Apple Vision Pro.md
Last active November 19, 2024 19:02
Guide for using Apple Vision Pro as HDMI display

Displaying HDMI sources on Apple Vision Pro

While it's possible to stream most content to Apple Vision Pro directly over the internet, having the ability to use Apple Vision Pro as an HDMI display can still be useful.

Since Apple Vision Pro does not support connecting to an HDMI input directly or using an HDMI capture card, we have to be a little creative to make this work. NDI provides the ability to stream HDMI content over a local network with really low latency, and it works great with Apple Vision Pro.

This page shows the setup I’m using.

@IanKeen
IanKeen / Storage.swift
Last active June 11, 2024 08:35
PropertyWrapper: Storage to extend support for more types using `@AppStorage`
@propertyWrapper
struct Storage<T: AppStorageConvertible>: RawRepresentable {
var rawValue: String { wrappedValue.storedValue }
var wrappedValue: T
init?(rawValue: String) {
guard let value = T.init(rawValue) else { return nil }
self.wrappedValue = value
}
init(wrappedValue: T) {
@daweido
daweido / user.controller.ts
Last active April 19, 2023 20:03
SMS OTP - Partial User authentification
import { Controller, Get, Res, HttpStatus, Body, Post } from '@nestjs/common';
import { User } from './interfaces/user.interface';
import { UserService } from './user.service';
@Controller('user')
export class UserController {
constructor(private userService: UserService) {}
@Post('/login')
async loginUser(
@propertyWrapper
public final class LayoutInvalidating<Value> where Value: Equatable {
public static subscript<EnclosingSelf>(
_enclosingInstance observed: EnclosingSelf,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, LayoutInvalidating>
) -> Value where EnclosingSelf: UIView {
get {
return observed[keyPath: storageKeyPath].stored
@frankfka
frankfka / iOSCustomSegmentedControlSwiftUI.swift
Created May 17, 2020 16:47
Custom Segmented Picker / Segmented Control in SwiftUI
import SwiftUI
extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}
struct SizePreferenceKey: PreferenceKey {
typealias Value = CGSize
@propertyWrapper
public struct AnyProxy<EnclosingSelf, Value> {
private let keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>
public init(_ keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>) {
self.keyPath = keyPath
}
@available(*, unavailable, message: "The wrapped value must be accessed from the enclosing instance property.")
public var wrappedValue: Value {
import Foundation
extension Character {
var isEmoji: Bool {
return unicodeScalars.allSatisfy { $0.properties.isEmoji }
}
}
func recentlyUsedEmoji() -> [Character]? {
#if os(iOS)