Skip to content

Instantly share code, notes, and snippets.

View jverkoey's full-sized avatar

Jeff Verkoeyen jverkoey

View GitHub Profile
MotionAggregator is active: true
Child is active: true
tween(duration: 5.0, values: UIExtendedSRGBColorSpace 1 0 0 1, UIExtendedSRGBColorSpace 1 0 1 1, UIExtendedSRGBColorSpace 1 0 0 1)
-> <CAKeyframeAnimation:0x608000223060; keyPath = backgroundColor; values = (
"<CGColor 0x6000000a8340> [<CGColorSpace 0x600000429520> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 1 0 0 1 )",
"<CGColor 0x6000000a8640> [<CGColorSpace 0x600000429520> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 1 0 1 1 )",
"<CGColor 0x6000000a8340> [<CGColorSpace 0x600000429520> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 1 0 0 1 )"
); duration = 5> '6591F5BE-E262-447D-A04B-6967BAF32095' to CALayer::0x60000003e940.backgroundColor
springTo(destination: 400.0, source: UIView::0x7f90b59143c0, property: centerY)
-> 333.5 to UIView::0x7f90b59143c0.centerY
let tween = Tween<CGFloat>(
duration: 0.3,
values: [0, 5],
timeline: timeline
)
runtime.addPlan(tween,
to: layer,
property: tweenPropertyOf(layer).position)
/*
Copyright 2016-present The Material Motion Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
public typealias MaterialRestableStream<T> = (stream: MaterialStream<T>, atRest: MaterialStream<Bool>)
public func drag(_ pan: UIPanGestureRecognizer) -> MaterialRestableStream<CGPoint> {
return (MaterialStream<CGPoint>(named: #function) { observer in
let dragObserver = DragObserver {
observer.next(pan.location(in: pan.view!.superview!))
}
pan.addTarget(dragObserver, action: #selector(DragObserver.didPan))
public class MaterialRestableStream<T>: MaterialStream<T> {
public var atRest = true {
didSet {
if atRest != oldValue {
for listener in listeners {
(listener as! AnyObserver<Bool>).next(atRest)
}
}
}
protocol Observer {
associatedtype Value
func next(_ value: Value) -> Void
}
class Subscription {
init(_ unsubscribe: (() -> Void)? = nil) {
_unsubscribe = unsubscribe
}
@jverkoey
jverkoey / rubberBand.swift
Created November 30, 2016 06:55
Rubber banding in swift
public func rubberBand(value: CGFloat, min: CGFloat, max: CGFloat, bandLength: CGFloat) -> CGFloat {
if value >= min && value <= max {
// While we're within range we don't rubber band the value.
return value
}
if bandLength <= 0 {
// The rubber band doesn't exist, return the minimum value so that we stay put.
return min
@jverkoey
jverkoey / TossableDrawerTransitionDirector.swift
Created November 30, 2016 06:54
Tossable drawer transition director in Material Motion
func willBeginTransition(_ transition: Transition) {
self.transition = transition
runtime = StreamRuntime(runtime: transition.runtime)
if transition.foreViewController.preferredContentSize != .zero {
drawerSize = transition.foreViewController.preferredContentSize
} else {
drawerSize = transition.foreViewController.view.bounds.size
}
if transition.direction == .forward {
@jverkoey
jverkoey / DrawerTransitionDirector.swift
Last active November 30, 2016 05:34
Drawer transition director with Material Motion streams
var transition: Transition!
func willBeginTransition(_ transition: Transition) {
self.transition = transition
runtime = StreamRuntime(runtime: transition.runtime)
if transition.foreViewController.preferredContentSize != .zero {
drawerSize = transition.foreViewController.preferredContentSize
} else {
drawerSize = transition.foreViewController.view.bounds.size
}
@jverkoey
jverkoey / stream.swift
Last active December 16, 2017 07:52
Stream prototype in swift
/**
An Observable emits values to its subscribed observers.
A minimal implementation based upon the reactivex specification:
http://reactivex.io/documentation/observable.html
*/
public class Observable<Value> {
/** Add a new observer. The provided instance will receive all values provided to onNext. */
public func subscribe(_ observer: @escaping (Value) -> Void) -> Observable<Value> {
observers.append(observer)