Skip to content

Instantly share code, notes, and snippets.

@alnaranjo
alnaranjo / whenHovered.md
Created February 13, 2024 16:55 — forked from importRyan/whenHovered.md
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
@alnaranjo
alnaranjo / gist:08aa9d9927db6b72ebe4775f31117a36
Last active October 24, 2023 15:29
JWT Private/Public Key Generation
# Generate PKCS#8 Keys
openssl genrsa -out keypair.pem 2048
openssl rsa -in keypair.pem -pubout -out public.key
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in keypair.pem -out private.key
# Copy keys as single line
awk -v ORS='\\n' '1' public.key | pbcopy
awk -v ORS='\\n' '1' private.pub | pbcopy