Skip to content

Instantly share code, notes, and snippets.

@dkun7944
dkun7944 / CDView.swift
Last active July 17, 2024 03:27
SwiftUI + Swift.Shader CD
//
// CDView.swift
// CD
//
// Created by Daniel Kuntz on 7/3/23.
//
import SwiftUI
struct ShapeWithHole: Shape {
@jasdev
jasdev / ScrimLoader.swift
Last active April 19, 2024 03:47
Rough sketch of Arc’s scrim loading view.
import SwiftUI
/**
### Exercises for the viewer
- Phase interrupt handling.
- Use Swift concurrency.
- Color scheme awareness.
- Rework animations to be more spring-like à la what shipped in `0.90.0`.
@stammy
stammy / LiquidBlobs.swift
Last active July 24, 2024 14:49
Liquid Blob effect with SwiftUI
//
// ContentView.swift
// LiquidCircles
//
// Created by Paul Stamatiou on 10/10/22.
//
import SwiftUI
struct ContentView: View {
import SwiftUI
@main
struct MenuBarApp: App {
@NSApplicationDelegateAdaptor(StatusBarDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
@joshdholtz
joshdholtz / ATinySampleApp.swift
Last active July 12, 2024 07:47
Super basic SwiftUI app (70 lines of code) with paywall using RevenueCat
import SwiftUI
import RevenueCat
struct Constants {
static let apiKey = "<your_api_key>" // Will look like: appl_bunchofotherstuffhere
static let entitlementName = "<your_entitlement_name>" // I use something like "pro"
}
@main
struct ATinySampleApp: App {
//
// ContentView.swift
// MadeForYouCard
//
// Created by AppleDesignDev on 1/24/22.
//
import SwiftUI
struct ContentView: View {
@importRyan
importRyan / whenHovered.md
Last active July 9, 2024 19:51
Reliable SwiftUI mouse hover

Reliable mouseEnter/Exit for SwiftUI

Kapture 2021-03-01 at 14 43 39

On Mac, SwiftUI's .onHover closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.

It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.

import SwiftUI
@importRyan
importRyan / TextView.md
Last active May 10, 2023 14:15
Custom NSTextView Insertion Point

Custom NSTextView Insertion Point

While making the default insertion caret pop a little wider for better accessibility, I ran into an issue where the insertion point ghosted on arrow key presses. Christian Tietze observed the same issue.

My culprit was settings an x offset for the rect inside drawInsertionPoint. While Christian's blog code doesn't include an offset, there's otherwise no difference in our approach.

Below draws wider insertion caret with rounded corners.

class FatRoundInsertionCaretTextView: NSTextView {
@almonk
almonk / SnappyWindow.swift
Last active May 2, 2024 03:05
SnappyWindow – A NSWindow that acts like the PIP Video Window from Safari
//
// SnappyWindow.swift
// A NSWindow that snaps to corners
//
// Created by Alasdair Monk on 03/02/2021.
//
import Foundation
import Cocoa
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
/*Terminal*/
VStack {