Skip to content

Instantly share code, notes, and snippets.

View innneang's full-sized avatar

Sarat Limawongpranee innneang

View GitHub Profile
@importRyan
importRyan / whenHovered.md
Last active May 11, 2024 03:13
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
@iccir
iccir / SimStatusBar.sh
Last active May 13, 2024 05:15
iOS Simulator Status Bars
# iPhone with home button
xcrun simctl status_bar booted clear
xcrun simctl status_bar booted override \
--time "9:41 AM" \
--wifiBars 3 --cellularBars 4 --operatorName ""
xcrun simctl spawn booted defaults write com.apple.springboard SBShowBatteryPercentage 1
# iPhone X
xcrun simctl status_bar booted clear
xcrun simctl status_bar booted override --time "9:41" --wifiBars 3 --cellularBars 4
Email: 982092332@qq.com
SN: GAWAE-FCWQ3-P8NYB-C7GF7-NEDRT-Q5DTB-MFZG6-6NEQC-CRMUD-8MZ2K-66SRB-SU8EW-EDLZ9-TGH3S-8SGA