Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Add a new Reactive type for querying reactive properties.
Browse files Browse the repository at this point in the history
Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, randcode-generator

Reviewed By: randcode-generator

Tags: #material_motion

Differential Revision: http://codereview.cc/D3112
  • Loading branch information
Jeff Verkoeyen committed Apr 27, 2017
1 parent 67cb7b1 commit be0ea01
Show file tree
Hide file tree
Showing 16 changed files with 655 additions and 419 deletions.
2 changes: 1 addition & 1 deletion examples/ContextualTransitionExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private class PushBackTransition: Transition {

let size = TransitionSpring(back: contextView.bounds.size, fore: fitSize, direction: ctx.direction)
runtime.toggle(size, inReactionTo: draggable)
runtime.add(size, to: runtime.get(replicaView).reactiveLayer.size)
runtime.add(size, to: runtime.get(replicaView).layer.size)

let opacity = TransitionSpring<CGFloat>(back: 0, fore: 1, direction: ctx.direction)
runtime.add(opacity, to: runtime.get(ctx.fore.view.layer).opacity)
Expand Down
4 changes: 2 additions & 2 deletions examples/FabTransitionExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ private class CircularRevealTransition: Transition {
let foreShadowPath = CGRect(origin: .zero(), size: expandedSize)
let shadowPath = tween(back: floodFillView.layer.shadowPath!, fore: UIBezierPath(ovalIn: foreShadowPath).cgPath, ctx: ctx)

let floodLayer = runtime.get(floodFillView).reactiveLayer
let floodLayer = runtime.get(floodFillView).layer
runtime.add(expansion, to: floodLayer.size)
runtime.add(fadeOut, to: floodLayer.opacity)
runtime.add(radius, to: floodLayer.cornerRadius)
runtime.add(shadowPath, to: floodLayer.shadowPath)

let shiftIn = tween(back: ctx.fore.view.layer.position.y + 40, fore: ctx.fore.view.layer.position.y, ctx: ctx)
runtime.add(shiftIn, to: runtime.get(ctx.fore.view).reactiveLayer.positionY)
runtime.add(shiftIn, to: runtime.get(ctx.fore.view).layer.positionY)

let maskShiftIn = tween(back: CGFloat(-40), fore: CGFloat(0), ctx: ctx)
runtime.add(maskShiftIn, to: runtime.get(maskLayer).positionY)
Expand Down
18 changes: 9 additions & 9 deletions src/MotionRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,24 @@ public final class MotionRuntime {
// MARK: Reactive object storage

/**
Returns a reactive version of the given object and caches the returned result for future access.
Returns a reactive version of the given object.
*/
public func get(_ view: UIView) -> ReactiveUIView {
return get(view) { .init($0, runtime: self) }
public func get(_ view: UIView) -> Reactive<UIView> {
return Reactive(view)
}

/**
Returns a reactive version of the given object and caches the returned result for future access.
Returns a reactive version of the given object.
*/
public func get(_ layer: CALayer) -> ReactiveCALayer {
return get(layer) { .init($0) }
public func get(_ layer: CALayer) -> Reactive<CALayer> {
return Reactive(layer)
}

/**
Returns a reactive version of the given object and caches the returned result for future access.
Returns a reactive version of the given object.
*/
public func get(_ layer: CAShapeLayer) -> ReactiveCAShapeLayer {
return get(layer) { .init($0) }
public func get(_ layer: CAShapeLayer) -> Reactive<CAShapeLayer> {
return Reactive(layer)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/Draggable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class Draggable: Gesturable<UIPanGestureRecognizer>, Interaction, T
guard let gestureRecognizer = dequeueGestureRecognizer(withReactiveView: reactiveView) else {
return
}
let position = reactiveView.reactiveLayer.position
let position = reactiveView.layer.position

runtime.connect(enabled, to: ReactiveProperty(initialValue: gestureRecognizer.isEnabled) { enabled in
gestureRecognizer.isEnabled = enabled
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/Rotatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class Rotatable: Gesturable<UIRotationGestureRecognizer>, Interacti
guard let gestureRecognizer = dequeueGestureRecognizer(withReactiveView: reactiveView) else {
return
}
let rotation = reactiveView.reactiveLayer.rotation
let rotation = reactiveView.layer.rotation

runtime.connect(enabled, to: ReactiveProperty(initialValue: gestureRecognizer.isEnabled) { enabled in
gestureRecognizer.isEnabled = enabled
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/Scalable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class Scalable: Gesturable<UIPinchGestureRecognizer>, Interaction,
guard let gestureRecognizer = dequeueGestureRecognizer(withReactiveView: reactiveView) else {
return
}
let scale = reactiveView.reactiveLayer.scale
let scale = reactiveView.layer.scale

runtime.connect(enabled, to: ReactiveProperty(initialValue: gestureRecognizer.isEnabled) { enabled in
gestureRecognizer.isEnabled = enabled
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/Gesturable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public class Gesturable<T: UIGestureRecognizer> {
/**
Prepares and returns the gesture recognizer that should be used to drive this interaction.
*/
func dequeueGestureRecognizer(withReactiveView reactiveView: ReactiveUIView) -> T? {
func dequeueGestureRecognizer(withReactiveView reactiveView: Reactive<UIView>) -> T? {
let gestureRecognizer = self.nextGestureRecognizer
_nextGestureRecognizer = nil

switch config {
case .registerNewRecognizerToTargetView:
reactiveView.view.addGestureRecognizer(gestureRecognizer!)
reactiveView._object.addGestureRecognizer(gestureRecognizer!)
default: ()
}

Expand Down
Loading

0 comments on commit be0ea01

Please sign in to comment.