Skip to content

Instantly share code, notes, and snippets.

View jverkoey's full-sized avatar

Jeff Verkoeyen jverkoey

View GitHub Profile
/*
Copyright 2017-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
@jverkoey
jverkoey / DirectlyManipulable.swift
Created April 12, 2017 18:25
Directly manipulable constraints
public final class DirectlyManipulable {
public func add(to view: UIView, withRuntime runtime: MotionRuntime, constraints: NoConstraints)
public final class Constraints {
public var draggable: ConstraintApplicator<T>?
public var rotatable: ConstraintApplicator<T>?
public var scalable: ConstraintApplicator<T>?
}
}
public func openValve<O: MotionObservableConvertible>(whenAllTrue observables: [O]) -> MotionObservable<T> where O.T == Bool {
return MotionObservable<T> { observer in
var upstreamSubscription: Subscription?
var connectUpstream = {
upstreamSubscription = self.asStream().subscribe(next: observer.next,
state: observer.state,
coreAnimation: observer.coreAnimation)
}
let square2Reactive = runtime.get(square2.layer)
let pan = runtime.get(UIPanGestureRecognizer())
let rawPosition = createProperty(withInitialValue: square2.layer.position)
runtime.add(pan.translated(from: rawPosition, in: view), to: rawPosition)
runtime.add(rawPosition.y().rubberBanded(below: 50, above: 400, length: 100), to: square2Reactive.positionY)
let pan = UIPanGestureRecognizer()
let rotate = UIRotationGestureRecognizer()
let scale = UIPinchGestureRecognizer()
[pan, rotate, scale].forEach { $0.delegate = self }
let directlyManipulable = DirectlyManipulable(view: square,
containerView: view,
panGestureRecognizer: pan,
rotationGestureRecognizer: rotate,
/*
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
#if (arch(i386) || arch(x86_64)) && os(iOS)
@_silgen_name("UIAnimationDragCoefficient") func UIAnimationDragCoefficient() -> Float
func simulatorDragCoefficient() -> CGFloat {
let drag = UIAnimationDragCoefficient()
if drag > 1 {
return CGFloat(drag)
}
return 1
}
# Streams
let drag$ = ....
aggregator.write(drag$.x().rubberBanded(0, 100),
to: propertyOf(view).center)
# Plan/Performer
/*
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
/*
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