Skip to content

Instantly share code, notes, and snippets.

/*
Copied from https://stackoverflow.com/questions/65784294/how-to-detect-if-keyboard-is-present-in-swiftui/76027034#76027034
Credit to StackOverflow users Confused Vorlon + Lepidopteron
*/
import SwiftUI
import Combine
public extension View {
/// Sets an environment value for keyboardShowing
@bardigolriz
bardigolriz / menubar_event_monitoring.txt
Last active January 25, 2024 12:53
Monitoring mouse events when a menu bar popover is open to know when you have clicked outside its bounds to facilitate a close. This is helpful when you’ve set the popover to have application defined behaviour, so that you control when it does close (selecting transient would make it auto-dismiss when macOS in fullscreen mode and semitransient w…
// Code from ChatGPT
import SwiftUI
@main
struct MenuBarApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
@bardigolriz
bardigolriz / RotatingChevron.swift
Last active June 22, 2022 14:26
RotatingChevron
import SwiftUI
struct RootView: View {
@State var isExpanded: Bool = false
var body: some View {
Image(systemName: "chevron.right")
.rotationEffect(Angle(degrees: isExpanded ? 90 : 0))
.onTapGesture {
@bardigolriz
bardigolriz / ScaleButtonStyle.swift
Created June 20, 2022 10:25
ScaleButtonStyle.swift
import Foundation
import SwiftUI
public struct ScaleButtonStyle: ButtonStyle {
let scaleAmount: CGFloat
public init(to scaleAmount: CGFloat = 1.05) {
self.scaleAmount = scaleAmount
}
import SwiftUI
struct MarkdownText: View {
let text: String
init(_ text: String) {
self.text = text
}
@bardigolriz
bardigolriz / Int.Extension
Last active June 17, 2022 08:31
Converting an Int to get approximate time in either mins/hours based on duration
extension Int {
/// Converts total minutes integer to the approximate minute or hours based on duration
public var approximately: String {
let hours = self/60
let additionalMinutes = self%60
if additionalMinutes == 0 {
if hours > 1 {
return "$numHours hours".localized(with: ["numHours": hours])
}