This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>? | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Streams | |
let drag$ = .... | |
aggregator.write(drag$.x().rubberBanded(0, 100), | |
to: propertyOf(view).center) | |
# Plan/Performer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |