Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
// Advanced SwiftUI Transitions
// https://swiftui-lab.com
// https://swiftui-lab.com/advanced-transitions
import SwiftUI
struct GeometryEffectTransitionsDemo: View {
@State private var show = false
var body: some View {
@samsonjs
samsonjs / PlatformDependentValue.swift
Created May 4, 2020 14:22 — forked from myell0w/PlatformDependentValue.swift
Cross-Platform Helpers for iOS/macOS
/// Used to identify traits of the current UI Environment - especially useful for cross-platform code
public struct MNCUITraits: Withable {
/// Does *not* identify the device type, but the idiom of the layout to apply
/// This means that e.g. on iPad the layoutIdiom can be `.phone`, if run in Split Screen or SlideOver
public enum LayoutIdiom {
case phone(hasRoundCorners: Bool)
case pad(hasRoundCorners: Bool)
case mac
}
//
// ContentView.swift
//
// Created by Chris Eidhof on 20.04.20.
// Copyright © 2020 objc.io. All rights reserved.
//
import SwiftUI
import UIKit
@samsonjs
samsonjs / MRDMenuView.h
Created March 1, 2020 21:06 — forked from steventroughtonsmith/MRDMenuView.h
Simplified iOS menu view wired up to UIMenuBuilder
//
// MRDMenuView.h
// MobileRadio
//
// Created by Steven Troughton-Smith on 29/02/2020.
// Copyright © 2020 High Caffeine Content. All rights reserved.
//
#import <UIKit/UIKit.h>
//
// ContentView.swift
// Layout
//
// Created by Matt Gallagher on 7/6/19.
// Copyright © 2019 Matt Gallagher. All rights reserved.
//
import SwiftUI
@samsonjs
samsonjs / InteractiveTransitionTableViewDeselection.m
Created February 7, 2019 05:24 — forked from smileyborg/InteractiveTransitionCollectionViewDeselection.m
Animate table view deselection alongside interactive transition on iOS 11
/*
In iOS 11, interactive view controller transitions no longer scrub by setting the layer speed to zero
and changing the timeOffset. As a result of this change, implicit animations that occur in places like
-viewWillAppear: (called during an interactive transition) no longer end up “caught in” the animation.
To get the same behavior for table view row deselection as before, you can either use UITableViewController
which implements this for you, or you can implement it manually by deselecting the row in an alongside
animation for the transition (set up in -viewWillAppear: using the transition coordinator).
Here is an example implementation which correctly handles some of the more subtle corner cases:
@samsonjs
samsonjs / references.swift
Created July 22, 2017 03:20 — forked from chriseidhof/references.swift
References Blogpost
//: Playground - noun: a place where people can play
import Foundation
final class Disposable {
private let dispose: () -> ()
init(_ dispose: @escaping () -> ()) {
self.dispose = dispose
}
@samsonjs
samsonjs / KeyboardLayoutGuide.swift
Created July 19, 2017 15:02 — forked from myell0w/KeyboardLayoutGuide.swift
A UILayoutGuide that follows the Keyboard on iOS
import Foundation
import UIKit
/// Used to create a layout guide that pins to the top of the keyboard
final class KeyboardLayoutGuide {
private let notificationCenter: NotificationCenter
private let bottomConstraint: NSLayoutConstraint
@samsonjs
samsonjs / LongPressGestureRecognizer.swift
Created July 19, 2017 15:02 — forked from myell0w/LongPressGestureRecognizer.swift
A UIGestureRecognizer that fires either on long-press or on a force-touch (3D Touch ™️)
import Foundation
import UIKit
import UIKit.UIGestureRecognizerSubclass
/// A Gesture Recognizer that fires either on long press, or on "3D Touch"
final class MNTLongPressGestureRecognizer: UILongPressGestureRecognizer {
// MARK: - Properties
@samsonjs
samsonjs / MD5.swift
Created July 14, 2017 22:54 — forked from pietbrauer/MD5.swift
NSString & NSData to MD5
import Foundation
extension NSData {
var md5: NSString {
let digestLength = Int(CC_MD5_DIGEST_LENGTH)
let md5Buffer = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLength)
CC_MD5(bytes, CC_LONG(length), md5Buffer)
let output = NSMutableString(capacity: Int(CC_MD5_DIGEST_LENGTH * 2))
for i in 0..<digestLength {