Skip to content

Instantly share code, notes, and snippets.

View Pyroh's full-sized avatar
💭
I may be slow to respond.

Pierre TACCHI Pyroh

💭
I may be slow to respond.
View GitHub Profile
@Pyroh
Pyroh / purple-scroll-inset.swift
Created March 25, 2022 16:18 — forked from christianselig/purple-scroll-inset.swift
Trying to replicate an inset scroll view effect in SwiftUI
import SwiftUI
struct ContentView: View {
struct HeightPreferenceKey: PreferenceKey {
let heigh: Anchor<CGRect>?
static func reduce(value: inout Anchor<CGRect>?, nextValue: () -> Anchor<CGRect>?) {
value = nextValue()
}
}
@Pyroh
Pyroh / KeyCommand.swift
Created February 3, 2021 11:45 — forked from steipete/KeyCommand.swift
Add Keyboard Shortcuts to SwiftUI on iOS 13 when using `UIHostingController`. See https://steipete.com/posts/fixing-keyboardshortcut-in-swiftui/
//
// KeyCommand.swift
// Adds Keyboard Shortcuts to SwiftUI on iOS 13
// See https://steipete.com/posts/fixing-keyboardshortcut-in-swiftui/
// License: MIT
//
// Usage: (wrap view in `KeyboardEnabledHostingController`)
// Button(action: {
// print("Button Tapped!!")
// }) {
@Pyroh
Pyroh / NSObjectBindingExtension.swift
Last active September 20, 2016 13:48
Handy NSObject extension to propagate a value through bindings. Yep, juste like any Cocoa control. OSX only (no bindings on iOS)
import Cocoa
fileprivate func nullableToOptionnal(value: Any?) -> Any? {
return value is NSNull ? nil : value
}
public extension NSObject {
public func propagateBoundValue(value: AnyObject?, forBinding key: String) {
guard let info = self.infoForBinding(key) else { return }
guard let boundObject = nullableToOptionnal(value: info[NSObservedObjectKey]) as? NSObject,