Skip to content

Instantly share code, notes, and snippets.

View Matt54's full-sized avatar

Matt Pfeiffer Matt54

View GitHub Profile
//
// CustomTabBarExample.swift
//
// Created by Matt Pfeiffer on 10/22/23.
//
import SwiftUI
struct CustomTabBarExample: View {
@State var index: Int = 0
@Matt54
Matt54 / RepeatedFadeBetweenViews.Swift
Created January 15, 2024 19:54
SwiftUI repeated fade between two views
struct RepeatedFadeBetweenViews<ViewA: View, ViewB: View>: View {
var animationDuration: Double = 2.0
let viewA: () -> ViewA
let viewB: () -> ViewB
@State private var isViewAVisible = false
var body: some View {
Group {
if isViewAVisible {
@Matt54
Matt54 / ChordType+Codable.swift
Created January 25, 2024 23:18
Stable Codable extension for ChordType in Tonic
import Tonic
import Foundation
extension ChordType: Codable {
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let chordKey = try values.decode(String.self, forKey: .chordKey)
self.init(chordKey: chordKey)
}
@Matt54
Matt54 / BlobView.Swift
Last active May 4, 2024 17:33
A fluid-like animating SwiftUI View
import SwiftUI
struct BlobView: View {
@State private var mainPosition: CGPoint = .zero
@State private var positions: [CGPoint] = []
private let blurRadius = 20.0
private let alphaThreshold = 0.875
private let ballCount = 20
@Matt54
Matt54 / WindowWatchingApp.Swift
Last active May 17, 2024 21:32
Keeping track of visionOS windows being opened/closed
import SwiftUI
import RealityKit
import RealityKitContent
@main
struct WindowWatchingApp: App {
@State private var windowManager: WindowManager
init() {
_windowManager = State(initialValue: WindowManager())
@Matt54
Matt54 / AnimatingMeshCircle.swift
Created June 13, 2024 11:39
Animating mesh view with circle mask
import SwiftUI
struct AnimatingMeshCircle: View {
var body: some View {
AnimatingMeshView()
.mask(Circle().frame(width:300, height: 300))
}
}
#Preview {
@Matt54
Matt54 / AnimatingMaskedMeshView.swift
Created June 13, 2024 12:21
An animating mesh gradient view with an animating mask
import SwiftUI
struct AnimatingMaskedMeshView: View {
let referenceDate: Date = .now
@State private var mainPosition: CGPoint = .zero
@State private var positions: [CGPoint] = []
private let blurRadius = 20.0
private let alphaThreshold = 0.875
@Matt54
Matt54 / MorphingSphereRealityView.swift
Created June 20, 2024 23:49
A RealityView using a LowLevelMesh to produce a morphing sphere
import RealityKit
import SwiftUI
import GameplayKit
struct MorphingSphereRealityView: View {
@State private var currentEntity: Entity?
@State private var morphFactor: Float = 0.0
@State private var frameDuration: TimeInterval = 0.0
@State private var lastUpdateTime = CACurrentMediaTime()
@Matt54
Matt54 / DiscoBallRealityView.swift
Created June 22, 2024 23:14
A rotating disco ball RealityView created from a LowLevelMesh
import RealityKit
import SwiftUI
struct DiscoBallRealityView: View {
@State private var currentEntity: Entity?
@State private var morphFactor: Float = 0.0
@State private var frameDuration: TimeInterval = 0.0
@State private var lastUpdateTime = CACurrentMediaTime()
static let animationFrameDuration: TimeInterval = 1.0 / 120.0
@Matt54
Matt54 / BubbleRealityView.swift
Last active July 1, 2024 03:20
A floating bubble (morphing transparent sphere) RealityView created from a LowLevelMesh
import RealityKit
import SwiftUI
struct BubbleRealityView: View {
@State private var currentEntity: Entity?
@State private var morphFactor: Float = 0.0
@State private var frameDuration: TimeInterval = 0.0
@State private var lastUpdateTime = CACurrentMediaTime()
static let animationFrameDuration: TimeInterval = 1.0 / 120.0