From a63e61a21d32e06c320132cd5191bd931cd043db Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Tue, 14 Mar 2017 16:46:10 -0400 Subject: [PATCH] Organizing the example view controllers in groups and cleaning up their implementations. Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, chuga Reviewed By: O4 Material Apple platform reviewers, chuga Tags: #material_motion Differential Revision: http://codereview.cc/D2877 --- examples/CarouselExample.swift | 15 +++-- examples/DirectlyManipulableExample.swift | 5 +- examples/DraggableConstraintExample.swift | 3 +- examples/DraggableCustomOperatorExample.swift | 3 +- examples/DraggableExample.swift | 3 +- .../DraggableReactiveConstraintExample.swift | 4 +- .../Catalog/Catalog.xcodeproj/project.pbxproj | 60 ++++++++++++++----- .../Catalog/Catalog/TableOfContents.swift | 10 ++-- 8 files changed, 66 insertions(+), 37 deletions(-) diff --git a/examples/CarouselExample.swift b/examples/CarouselExample.swift index 3267174..a1c7269 100644 --- a/examples/CarouselExample.swift +++ b/examples/CarouselExample.swift @@ -17,16 +17,14 @@ import UIKit import ReactiveMotion -public class CarouselExampleViewController: UIViewController, UIScrollViewDelegate { +class CarouselExampleViewController: ExampleViewController, UIScrollViewDelegate { var runtime: MotionRuntime! - public override func viewDidLoad() { + override func viewDidLoad() { super.viewDidLoad() automaticallyAdjustsScrollViewInsets = false - runtime = MotionRuntime(containerView: view) - view.backgroundColor = UIColor(hexColor: 0xF8AA36) let scrollView = UIScrollView(frame: view.bounds) @@ -49,6 +47,8 @@ public class CarouselExampleViewController: UIViewController, UIScrollViewDelega (title: "Purr purr", description: "Meow", image: UIImage(named: "sticker2")!), ] + runtime = MotionRuntime(containerView: view) + let stream = runtime.get(scrollView) for (index, data) in datas.enumerated() { let page = CarouselPage(frame: view.bounds) @@ -71,9 +71,14 @@ public class CarouselExampleViewController: UIViewController, UIScrollViewDelega var pager: UIPageControl! - public func scrollViewDidScroll(_ scrollView: UIScrollView) { + func scrollViewDidScroll(_ scrollView: UIScrollView) { pager.currentPage = Int((scrollView.contentOffset.x + scrollView.bounds.width / 2) / scrollView.bounds.width) } + + override func exampleInformation() -> ExampleInfo { + return .init(title: type(of: self).catalogBreadcrumbs().last!, + instructions: "Swipe betwen pages to see the scroll effects.") + } } private class CarouselPage: UIView { diff --git a/examples/DirectlyManipulableExample.swift b/examples/DirectlyManipulableExample.swift index 631d439..6c87c48 100644 --- a/examples/DirectlyManipulableExample.swift +++ b/examples/DirectlyManipulableExample.swift @@ -24,13 +24,10 @@ class DirectlyManipulableExampleViewController: ExampleViewController { override func viewDidLoad() { super.viewDidLoad() - runtime = MotionRuntime(containerView: view) - - view.backgroundColor = .white - let square = center(createExampleView(), within: view) view.addSubview(square) + runtime = MotionRuntime(containerView: view) runtime.add(DirectlyManipulable(), to: square) } diff --git a/examples/DraggableConstraintExample.swift b/examples/DraggableConstraintExample.swift index 0268f78..12e3525 100644 --- a/examples/DraggableConstraintExample.swift +++ b/examples/DraggableConstraintExample.swift @@ -24,11 +24,10 @@ class DraggableConstraintExampleViewController: ExampleViewController { override func viewDidLoad() { super.viewDidLoad() - runtime = MotionRuntime(containerView: view) - let square = center(createExampleView(), within: view) view.addSubview(square) + runtime = MotionRuntime(containerView: view) runtime.add(Draggable(), to: square) { $0.xLocked(to: square.layer.position.x) } } diff --git a/examples/DraggableCustomOperatorExample.swift b/examples/DraggableCustomOperatorExample.swift index 66a2d17..d7782b7 100644 --- a/examples/DraggableCustomOperatorExample.swift +++ b/examples/DraggableCustomOperatorExample.swift @@ -24,11 +24,10 @@ class DraggableCustomOperatorExampleViewController: ExampleViewController { override func viewDidLoad() { super.viewDidLoad() - runtime = MotionRuntime(containerView: view) - let square = center(createExampleView(), within: view) view.addSubview(square) + runtime = MotionRuntime(containerView: view) runtime.add(Draggable(), to: square) { $0.wobble(width: 100) } } diff --git a/examples/DraggableExample.swift b/examples/DraggableExample.swift index 56235e2..ce44191 100644 --- a/examples/DraggableExample.swift +++ b/examples/DraggableExample.swift @@ -24,11 +24,10 @@ class DraggableExampleViewController: ExampleViewController { override func viewDidLoad() { super.viewDidLoad() - runtime = MotionRuntime(containerView: view) - let square = center(createExampleView(), within: view) view.addSubview(square) + runtime = MotionRuntime(containerView: view) runtime.add(Draggable(), to: square) } diff --git a/examples/DraggableReactiveConstraintExample.swift b/examples/DraggableReactiveConstraintExample.swift index b75f5a0..e04fbd1 100644 --- a/examples/DraggableReactiveConstraintExample.swift +++ b/examples/DraggableReactiveConstraintExample.swift @@ -24,8 +24,6 @@ class DraggableReactiveConstraintExampleViewController: ExampleViewController { override func viewDidLoad() { super.viewDidLoad() - runtime = MotionRuntime(containerView: view) - let axisLine = UIView(frame: .init(x: view.bounds.midX - 8, y: 0, width: 16, height: view.bounds.height)) axisLine.backgroundColor = .red view.addSubview(axisLine) @@ -33,6 +31,8 @@ class DraggableReactiveConstraintExampleViewController: ExampleViewController { let square = center(createExampleView(), within: view) view.addSubview(square) + runtime = MotionRuntime(containerView: view) + let axisCenterX = runtime.get(axisLine.layer).position.x() runtime.add(Draggable(), to: square) { $0 .initialValue(square.layer.position) diff --git a/examples/apps/Catalog/Catalog.xcodeproj/project.pbxproj b/examples/apps/Catalog/Catalog.xcodeproj/project.pbxproj index 86b93c1..dd83830 100644 --- a/examples/apps/Catalog/Catalog.xcodeproj/project.pbxproj +++ b/examples/apps/Catalog/Catalog.xcodeproj/project.pbxproj @@ -175,16 +175,14 @@ isa = PBXGroup; children = ( 664A5B761DD10D320082B5DF /* TableOfContents.swift */, - 66DDFD0B1E71F0B300AA46B7 /* Draggable */, - 66DDFD0E1E71F0F600AA46B7 /* Directly Manipulable */, + 66DDFD0B1E71F0B300AA46B7 /* How to drag views */, + 66DDFD231E788DC500AA46B7 /* How to apply constraints to an interaction */, + 66DDFD0E1E71F0F600AA46B7 /* How to directly manipulate views */, + 66DDFD221E788D1B00AA46B7 /* How to build a view controller transition */, + 66DDFD211E788C1200AA46B7 /* How to react to scrolling */, + 66DDFD241E788DD500AA46B7 /* How to create custom operators */, 667E94451E71EF0E005CAC78 /* ArcMoveExample.swift */, - 667E94461E71EF0E005CAC78 /* CarouselExample.swift */, - 667E94471E71EF0E005CAC78 /* ContextualTransitionExample.swift */, 667E94491E71EF0E005CAC78 /* DragSourceExample.swift */, - 667E944A1E71EF0E005CAC78 /* FabTransitionExample.swift */, - 667E944B1E71EF0E005CAC78 /* InteractivePushBackTransitionExample.swift */, - 667E944C1E71EF0E005CAC78 /* ModalDialogExample.swift */, - 667E944D1E71EF0E005CAC78 /* PushBackTransitionExample.swift */, 667E944E1E71EF0E005CAC78 /* StickerPickerExample.swift */, 667E94511E71EF0E005CAC78 /* SwipeExample.swift */, 667E944F1E71EF0E005CAC78 /* supplemental */, @@ -265,23 +263,57 @@ path = ../../supplemental; sourceTree = ""; }; - 66DDFD0B1E71F0B300AA46B7 /* Draggable */ = { + 66DDFD0B1E71F0B300AA46B7 /* How to drag views */ = { isa = PBXGroup; children = ( 66DDFD0C1E71F0F100AA46B7 /* DraggableExample.swift */, + ); + name = "How to drag views"; + sourceTree = ""; + }; + 66DDFD0E1E71F0F600AA46B7 /* How to directly manipulate views */ = { + isa = PBXGroup; + children = ( + 667E94481E71EF0E005CAC78 /* DirectlyManipulableExample.swift */, + ); + name = "How to directly manipulate views"; + sourceTree = ""; + }; + 66DDFD211E788C1200AA46B7 /* How to react to scrolling */ = { + isa = PBXGroup; + children = ( + 667E94461E71EF0E005CAC78 /* CarouselExample.swift */, + ); + name = "How to react to scrolling"; + sourceTree = ""; + }; + 66DDFD221E788D1B00AA46B7 /* How to build a view controller transition */ = { + isa = PBXGroup; + children = ( + 667E944D1E71EF0E005CAC78 /* PushBackTransitionExample.swift */, + 667E944B1E71EF0E005CAC78 /* InteractivePushBackTransitionExample.swift */, + 667E94471E71EF0E005CAC78 /* ContextualTransitionExample.swift */, + 667E944C1E71EF0E005CAC78 /* ModalDialogExample.swift */, + 667E944A1E71EF0E005CAC78 /* FabTransitionExample.swift */, + ); + name = "How to build a view controller transition"; + sourceTree = ""; + }; + 66DDFD231E788DC500AA46B7 /* How to apply constraints to an interaction */ = { + isa = PBXGroup; + children = ( 66DDFD0F1E71F32800AA46B7 /* DraggableConstraintExample.swift */, 66DDFD151E71F90F00AA46B7 /* DraggableReactiveConstraintExample.swift */, - 66DDFD1F1E73281200AA46B7 /* DraggableCustomOperatorExample.swift */, ); - name = Draggable; + name = "How to apply constraints to an interaction"; sourceTree = ""; }; - 66DDFD0E1E71F0F600AA46B7 /* Directly Manipulable */ = { + 66DDFD241E788DD500AA46B7 /* How to create custom operators */ = { isa = PBXGroup; children = ( - 667E94481E71EF0E005CAC78 /* DirectlyManipulableExample.swift */, + 66DDFD1F1E73281200AA46B7 /* DraggableCustomOperatorExample.swift */, ); - name = "Directly Manipulable"; + name = "How to create custom operators"; sourceTree = ""; }; 8C6A745BCA20C3282C1419A7 /* Pods */ = { diff --git a/examples/apps/Catalog/Catalog/TableOfContents.swift b/examples/apps/Catalog/Catalog/TableOfContents.swift index 83a2502..2b0685c 100644 --- a/examples/apps/Catalog/Catalog/TableOfContents.swift +++ b/examples/apps/Catalog/Catalog/TableOfContents.swift @@ -34,6 +34,10 @@ extension DraggableReactiveConstraintExampleViewController { class func catalogBreadcrumbs() -> [String] { return ["Draggable with reactive constraints"] } } +extension DirectlyManipulableExampleViewController { + class func catalogBreadcrumbs() -> [String] { return ["Directly manipulable"] } +} + @available(iOS 9.0, *) extension DragSourceExampleViewController { class func catalogBreadcrumbs() -> [String] { @@ -99,9 +103,3 @@ extension StickerPickerExampleViewController { return ["Sticker picker"] } } - -extension DirectlyManipulableExampleViewController { - class func catalogBreadcrumbs() -> [String] { - return ["Directly manipulable"] - } -}