Skip to content

Instantly share code, notes, and snippets.

@radiofun
radiofun / simplewavenoise.metal
Last active March 18, 2026 16:40
Simple Wave with Noise
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
float hash21(float2 p) {
float3 p3 = fract(float3(p.xyx) * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
@radiofun
radiofun / SiriAnimation.metal
Created February 15, 2026 19:55
Siri Animation
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
float sdBox(float2 p, float2 b) {
float2 q = abs(p) - b;
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0));
}
float sdRoundBox(float2 p, float2 b, float radius) {
@Mcrich23
Mcrich23 / _UIViewGlass.swift
Last active January 3, 2026 20:56
A function that creates a _UIViewGlass object with the correctly numbered variant. All in swift!
public func _UIViewGlass(variant: Int) -> NSObject? {
let glassClass = objc_lookUpClass("_UIViewGlass")! as AnyObject
let glass = glassClass._alloc()._init(variant: variant)
return glass as? NSObject
}
/// Registers Objective-C methods Swift needs.
fileprivate final class PrivateSelectors: NSObject {
@objc(alloc)
@Mcrich23
Mcrich23 / withAnimation.swift
Created November 6, 2025 18:58
Ever wanted to run a SwiftUI animation in an asynchronous context? Here is a function to do it!
import SwiftUI
public func withAnimation<Result>(
_ animation: Animation? = .default,
_ body: @MainActor @escaping () throws -> Result
) async rethrows {
await withCheckedContinuation { continuation in
// Ensure the work runs on the MainActor
Task { @MainActor in
do {
@zachgibson
zachgibson / gist:ac8591934cdb37b05c281e0ecf023e50
Created October 25, 2025 16:58
This is mimics a keyboard toolbar, but uses safeAreaBar instead. This allows the bar to have custom layout properties (like bottom padding). iOS 26.0.1 has a bug where toolbar items with keyboard placement sit directly on the keyboard with no bottom padding whatsoever.
import Combine
import SwiftUI
struct ContentView: View {
@State var text = ""
@State var keyboardObserver = KeyboardObserver()
@Namespace var union
var body: some View {
VStack {
@JohnnyD1776
JohnnyD1776 / ShareLInkView.swift
Created October 11, 2025 19:20
SwiftUi Demo of ShareLinks in iOS 16+
//
/*
Filename: ShareLInkView.swift
Project: Demo Project
Created by John Durcan on 11/10/2025.
Copyright © 2025 Itch Studio Ltd.. All rights reserved.
@JohnnyD1776
JohnnyD1776 / ParallaxDemo.swift
Created October 1, 2025 14:58
SwiftUI Parallax Demo
//
/*
Filename: ParallaxDemo.swift
Project: Demo Project
Created by John Durcan on 01/10/2025.
Copyright © 2025 Itch Studio Ltd.. All rights reserved.
@juliensagot
juliensagot / AsymmetricInsettableShape.swift
Last active March 16, 2026 10:32
Adds horizontal/vertical inset support to Shapes with full InsettableShape compatibility.
private struct AsymmetricInsettableShape<S: Shape>: InsettableShape {
private let shape: S
private var horizontal: CGFloat
private var vertical: CGFloat
private var insetAccumulator: CGFloat = 0
init(
shape: S,
horizontal: CGFloat,
//
// DotPatternView.swift
// x.com/mickces
//
// Created by mick on 4/27/25.
//
import SwiftUI
public struct DotPatternView: View {
@slowbrewedmacchiato
slowbrewedmacchiato / AncientProphecyTabBarsApp.swift
Last active February 10, 2026 01:18
Creating iOS 26 Tab bars with separated option
import SwiftUI
/// The main application entry point for the Ancient Prophecy Tab Bars app.
///
/// This app demonstrates a custom tab bar implementation with an overlay menu system.
/// Specifically the implementation of a separate tab bar option now available in iOS 26.
/// The app automatically exits when the main content view disappears and uses a fixed content size window.
@main
struct AncientProphecyTabBarsApp: App {
var body: some Scene {