motion-kit 0.18.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -1
  3. data/lib/motion-kit-tvos/deprecated.rb +31 -0
  4. data/lib/motion-kit-tvos/dummy.rb +93 -0
  5. data/lib/motion-kit-tvos/helpers/constraints_helpers.rb +24 -0
  6. data/lib/motion-kit-tvos/helpers/layout_device.rb +36 -0
  7. data/lib/motion-kit-tvos/helpers/layout_orientation.rb +54 -0
  8. data/lib/motion-kit-tvos/helpers/uibutton_helpers.rb +52 -0
  9. data/lib/motion-kit-tvos/helpers/uiview_autoresizing_helpers.rb +79 -0
  10. data/lib/motion-kit-tvos/helpers/uiview_constraints_helpers.rb +36 -0
  11. data/lib/motion-kit-tvos/helpers/uiview_frame_helpers.rb +316 -0
  12. data/lib/motion-kit-tvos/helpers/uiview_gradient_helpers.rb +22 -0
  13. data/lib/motion-kit-tvos/helpers/uiview_helpers.rb +28 -0
  14. data/lib/motion-kit-tvos/ios_util.rb +24 -0
  15. data/lib/motion-kit.rb +2 -0
  16. data/lib/motion-kit/version.rb +1 -1
  17. data/spec/tvos/apply_styles_spec.rb +37 -0
  18. data/spec/tvos/autoresizing_helper_spec.rb +240 -0
  19. data/spec/tvos/calayer_spec.rb +23 -0
  20. data/spec/tvos/calculate_spec.rb +322 -0
  21. data/spec/tvos/calculator_spec.rb +31 -0
  22. data/spec/tvos/child_layouts_spec.rb +65 -0
  23. data/spec/tvos/constraints_helpers/active_constraints_spec.rb +25 -0
  24. data/spec/tvos/constraints_helpers/attribute_lookup_spec.rb +27 -0
  25. data/spec/tvos/constraints_helpers/axis_lookup_spec.rb +13 -0
  26. data/spec/tvos/constraints_helpers/center_constraints_spec.rb +421 -0
  27. data/spec/tvos/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  28. data/spec/tvos/constraints_helpers/priority_lookup_spec.rb +19 -0
  29. data/spec/tvos/constraints_helpers/relationship_lookup_spec.rb +27 -0
  30. data/spec/tvos/constraints_helpers/relative_corners_spec.rb +276 -0
  31. data/spec/tvos/constraints_helpers/relative_location_spec.rb +113 -0
  32. data/spec/tvos/constraints_helpers/scale_constraints_spec.rb +62 -0
  33. data/spec/tvos/constraints_helpers/simple_constraints_spec.rb +2755 -0
  34. data/spec/tvos/constraints_helpers/size_constraints_spec.rb +423 -0
  35. data/spec/tvos/constraints_helpers/view_lookup_constraints_spec.rb +95 -0
  36. data/spec/tvos/create_layout_spec.rb +40 -0
  37. data/spec/tvos/custom_layout_spec.rb +13 -0
  38. data/spec/tvos/custom_root_layout_spec.rb +57 -0
  39. data/spec/tvos/deferred_spec.rb +89 -0
  40. data/spec/tvos/device_helpers_spec.rb +58 -0
  41. data/spec/tvos/frame_helper_spec.rb +1160 -0
  42. data/spec/tvos/layer_layout_spec.rb +36 -0
  43. data/spec/tvos/layout_extensions_spec.rb +70 -0
  44. data/spec/tvos/layout_spec.rb +57 -0
  45. data/spec/tvos/layout_state_spec.rb +27 -0
  46. data/spec/tvos/memory_leak_spec.rb +74 -0
  47. data/spec/tvos/motion_kit_id_spec.rb +15 -0
  48. data/spec/tvos/motionkit_util_spec.rb +15 -0
  49. data/spec/tvos/nearest_spec.rb +80 -0
  50. data/spec/tvos/objc_selectors_spec.rb +10 -0
  51. data/spec/tvos/orientation_helper_specs.rb +67 -0
  52. data/spec/tvos/parent_layout_spec.rb +19 -0
  53. data/spec/tvos/parent_spec.rb +45 -0
  54. data/spec/tvos/prev_next_spec.rb +153 -0
  55. data/spec/tvos/reapply_frame.rb +64 -0
  56. data/spec/tvos/relative_layout.spec.rb +31 -0
  57. data/spec/tvos/remove_layout_spec.rb +28 -0
  58. data/spec/tvos/root_layout_spec.rb +53 -0
  59. data/spec/tvos/setters_spec.rb +63 -0
  60. data/spec/tvos/uibutton_layout_spec.rb +37 -0
  61. data/spec/tvos/uitextfield_spec.rb +14 -0
  62. data/spec/tvos/view_attr_spec.rb +32 -0
  63. metadata +118 -8
@@ -0,0 +1,36 @@
1
+ describe TestLayerHelpers do
2
+ before do
3
+ @subject = TestLayerHelpers.new
4
+ end
5
+
6
+ it 'should create a CALayer root' do
7
+ @subject.view.should.be.kind_of(CALayer)
8
+ end
9
+
10
+ it 'should add sublayers' do
11
+ @subject.view.sublayers.length.should == 3
12
+ end
13
+
14
+ describe 'should have styled sublayers' do
15
+ before do
16
+ @subject = TestLayerHelpers.new
17
+ end
18
+
19
+ it 'should have a CALayer' do
20
+ @subject.view.sublayers[0].opacity.should == 0.5
21
+ @subject.view.sublayers[0].backgroundColor.should.not == nil
22
+ end
23
+
24
+ it 'should have a CAGradientLayer' do
25
+ @subject.view.sublayers[1].opacity.should == 0.5
26
+ @subject.view.sublayers[1].colors.should.not == nil
27
+ @subject.view.sublayers[1].colors.length.should == 2
28
+ end
29
+
30
+ it 'should have a CAShapeLayer' do
31
+ @subject.view.sublayers[2].opacity.should == 0.5
32
+ @subject.view.sublayers[2].path.should.not == nil
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,70 @@
1
+ describe "Layout extensions - iOS" do
2
+
3
+ before do
4
+ @subject = MK::UIViewHelpers.new
5
+ @subject.instance_variable_set(:@context, "don't matter what i be, as long as i be.")
6
+ end
7
+
8
+ it 'should have `orientation?` method' do
9
+ tf = @subject.orientation?(:portrait)
10
+ (tf == true || tf == false).should.be.true
11
+ end
12
+
13
+ it 'should return true for `orientation?(:portrait)` when in portrait' do
14
+ tf = @subject.orientation?(:portrait)
15
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationPortrait)
16
+ tf.should == should_be
17
+ end
18
+
19
+ it 'should return true for `orientation?(:landscape_left)` when in landscape_left' do
20
+ tf = @subject.orientation?(:landscape_left)
21
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
22
+ tf.should == should_be
23
+ end
24
+
25
+ it 'should return true for `orientation?(:landscape_right)` when in landscape_right' do
26
+ tf = @subject.orientation?(:landscape_right)
27
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeRight)
28
+ tf.should == should_be
29
+ end
30
+
31
+ it 'should return true for `orientation?(:landscape)` when in landscape' do
32
+ tf = @subject.orientation?(:landscape)
33
+ should_be = (UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeLeft || UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationLandscapeRight)
34
+ tf.should == should_be
35
+ end
36
+
37
+ it 'should have `iphone?` method' do
38
+ tf = @subject.iphone?
39
+ (tf == true || tf == false).should.be.true
40
+ end
41
+
42
+ it 'should return `true` for `iphone?` when using an iphone' do
43
+ tf = @subject.iphone?
44
+ should_be = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone
45
+ tf.should == should_be
46
+ end
47
+
48
+ it 'should have `ipad?` method' do
49
+ tf = @subject.ipad?
50
+ (tf == true || tf == false).should.be.true
51
+ end
52
+
53
+ it 'should return `true` for `ipad?` when using an ipad' do
54
+ tf = @subject.ipad?
55
+ should_be = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
56
+ tf.should == should_be
57
+ end
58
+
59
+ it 'should have `retina?` method' do
60
+ tf = @subject.retina?
61
+ (tf == true || tf == false).should.be.true
62
+ end
63
+
64
+ it 'should return `true` for `return?` when using a retina device' do
65
+ tf = @subject.retina?
66
+ should_be = UIScreen.mainScreen.scale == 2
67
+ tf.should == should_be
68
+ end
69
+
70
+ end
@@ -0,0 +1,57 @@
1
+ describe 'Simple Layout' do
2
+ before do
3
+ @subject = TestLayout.new.build
4
+ end
5
+
6
+ it "should be an instance of MotionKit::Layout" do
7
+ @subject.should.be.kind_of(MotionKit::Layout)
8
+ end
9
+
10
+ it "should be an instance of MK::Layout" do
11
+ @subject.should.be.kind_of(MK::Layout)
12
+ end
13
+
14
+ it "should add a UIView subview with the name :basic_view" do
15
+ view = @subject.get(:basic_view)
16
+ view.should.be.kind_of(UIView)
17
+ end
18
+
19
+ it "should add two subviews under :basic_view" do
20
+ @subject.view.subviews.first.subviews.length.should == 2
21
+ end
22
+
23
+ it "should add a UIButton as the first subview under :basic_view" do
24
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UIButton
25
+ end
26
+
27
+ it "should add a UILabel as the second subview under :basic_view" do
28
+ @subject.view.subviews.first.subviews[1].should.be.kind_of UILabel
29
+ end
30
+
31
+ it "should allow getting the subviews by their id" do
32
+ @subject.get(:basic_view).should.be.kind_of UIView
33
+ @subject.get(:basic_button).should.be.kind_of UIButton
34
+ @subject.get(:basic_label).should.be.kind_of UILabel
35
+ end
36
+
37
+ it "should allow getting the subviews by first, last and nth child" do
38
+ @subject.first(:repeated_label_3).should == @subject.first_view
39
+ @subject.nth(:repeated_label_3, 3).should == @subject.nth_view
40
+ @subject.last(:repeated_label_3).should == @subject.last_view
41
+ end
42
+
43
+ it "should allow getting all the subviews by name" do
44
+ views = @subject.all(:repeated_label_3)
45
+ views.length.should > 1
46
+ views[0].should.be.kind_of UIView
47
+ views[3].should.be.kind_of UIButton
48
+ views[-1].should.be.kind_of UILabel
49
+ end
50
+
51
+ it "should support missing methods" do
52
+ -> do
53
+ @subject.foo_bar_baz
54
+ end.should.raise(NoMethodError)
55
+ end
56
+
57
+ end
@@ -0,0 +1,27 @@
1
+ describe 'Blocks that are state specific' do
2
+
3
+ before do
4
+ @subject = TestLayoutState.new
5
+ end
6
+
7
+ it 'should run the initial blocks from layout' do
8
+ @subject.view.text.should == 'initial'
9
+ end
10
+
11
+ it 'should run the reapply blocks from layout' do
12
+ @subject.reapply!
13
+ @subject.view.text.should == 'reapply'
14
+ end
15
+
16
+ it 'should run the initial blocks from any method' do
17
+ any_view = @subject.any_view
18
+ any_view.text.should == 'initial'
19
+ end
20
+
21
+ it 'should run the reapply blocks from any method' do
22
+ any_view = @subject.any_view
23
+ @subject.reapply!
24
+ any_view.text.should == 'reapply'
25
+ end
26
+
27
+ end
@@ -0,0 +1,74 @@
1
+ describe 'MemoryLeaks' do
2
+
3
+ before do
4
+ window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
5
+ @controller = UINavigationController.new
6
+ @controller.viewControllers = [UIViewController.new, TestMemoryLeakController.new]
7
+ window.rootViewController = @controller
8
+ window.makeKeyAndVisible
9
+
10
+ @did_dealloc_controller = false
11
+ @did_dealloc_layout = false
12
+ @did_dealloc_cell = false
13
+ @did_dealloc_cell_layout = false
14
+
15
+ @observe_controller = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakController dealloc', object: nil, queue: nil, usingBlock: -> notification do
16
+ @did_dealloc_controller = true
17
+ end)
18
+ @observe_layout = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakLayout dealloc', object: nil, queue: nil, usingBlock: -> notification do
19
+ @did_dealloc_layout = true
20
+ end)
21
+ @observe_cell = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakCell dealloc', object: nil, queue: nil, usingBlock: -> notification do
22
+ @did_dealloc_cell = true
23
+ end)
24
+ @observe_cell_layout = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakCellLayout dealloc', object: nil, queue: nil, usingBlock: -> notification do
25
+ @did_dealloc_cell_layout = true
26
+ end)
27
+ end
28
+
29
+ after do
30
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_controller)
31
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_layout)
32
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_cell)
33
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_cell_layout)
34
+ end
35
+
36
+ describe 'When popping a controller' do
37
+
38
+ before do
39
+ wait 0.1 do
40
+ @controller.popViewControllerAnimated(false)
41
+
42
+ # window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
43
+ # window.rootViewController = @controller
44
+ # window.makeKeyAndVisible
45
+ end
46
+ end
47
+
48
+ it 'should release the TestMemoryLeakController' do
49
+ wait 0.1 do
50
+ @did_dealloc_controller.should == true
51
+ end
52
+ end
53
+
54
+ it 'should release the TestMemoryLeakLayout' do
55
+ wait 0.1 do
56
+ @did_dealloc_layout.should == true
57
+ end
58
+ end
59
+
60
+ it 'should release the TestMemoryLeakCell' do
61
+ wait 0.1 do
62
+ @did_dealloc_cell.should == true
63
+ end
64
+ end
65
+
66
+ it 'should release the TestMemoryLeakCellLayout' do
67
+ wait 0.1 do
68
+ @did_dealloc_cell_layout.should == true
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,15 @@
1
+ describe "MotionKit id" do
2
+
3
+ before do
4
+ @layout = TestIdsLayout.new.build
5
+ end
6
+
7
+ it 'should have a label' do
8
+ @layout.get(:label).should.be.kind_of UILabel
9
+ end
10
+
11
+ it 'should have a label with id :label' do
12
+ @layout.get(:label).motion_kit_id.should == :label
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ describe 'MotionKit utility methods' do
2
+
3
+ it 'should objc-ify a string' do
4
+ MotionKit.objective_c_method_name('this_is_my_string').should == 'thisIsMyString'
5
+ end
6
+
7
+ it 'should camel case a string' do
8
+ MotionKit.camel_case('this_is_my_string').should == 'ThisIsMyString'
9
+ end
10
+
11
+ it 'should return the UIView appearance class' do
12
+ MotionKit.appearance_class.should.be.kind_of(Class)
13
+ end
14
+
15
+ end
@@ -0,0 +1,80 @@
1
+ describe 'MotionKit nearest element logic' do
2
+
3
+ before do
4
+ @subject = TestNearestLayout.new.build
5
+ end
6
+
7
+ it 'should support self_search' do
8
+ found = nil
9
+ @subject.self_search
10
+ @subject.context(@subject.start_here) do
11
+ found = @subject.nearest(:self_search)
12
+ end
13
+ found.should == @subject.expected_to_find
14
+ end
15
+
16
+ it 'should support child_search' do
17
+ found = nil
18
+ @subject.child_search
19
+ @subject.context(@subject.start_here) do
20
+ found = @subject.nearest(:child_search)
21
+ end
22
+ found.should == @subject.expected_to_find
23
+ end
24
+
25
+ it 'should support sibling_search' do
26
+ found = nil
27
+ @subject.sibling_search
28
+ @subject.context(@subject.start_here) do
29
+ found = @subject.nearest(:sibling_search)
30
+ end
31
+ found.should == @subject.expected_to_find
32
+ end
33
+
34
+ it 'should support siblings_child_search' do
35
+ found = nil
36
+ @subject.siblings_child_search
37
+ @subject.context(@subject.start_here) do
38
+ found = @subject.nearest(:siblings_child_search)
39
+ end
40
+ found.should == @subject.expected_to_find
41
+ end
42
+
43
+ it 'should support parent_search' do
44
+ found = nil
45
+ @subject.parent_search
46
+ @subject.context(@subject.start_here) do
47
+ found = @subject.nearest(:parent_search)
48
+ end
49
+ found.should == @subject.expected_to_find
50
+ end
51
+
52
+ it 'should support distant_search' do
53
+ found = nil
54
+ @subject.distant_search
55
+ @subject.context(@subject.start_here) do
56
+ found = @subject.nearest(:distant_search)
57
+ end
58
+ found.should == @subject.expected_to_find
59
+ end
60
+
61
+ it 'should support nearest(id, from: view)' do
62
+ found = nil
63
+ @subject.nearest_from_search
64
+ @subject.context(@subject.start_here) do
65
+ from_here = @subject.get(:from_here)
66
+ found = @subject.nearest(:nearest_from_search, from: from_here)
67
+ end
68
+ found.should == @subject.expected_to_find
69
+ end
70
+
71
+ it 'should support nearest(id, from: id)' do
72
+ found = nil
73
+ @subject.nearest_from_search
74
+ @subject.context(@subject.start_here) do
75
+ found = @subject.nearest(:nearest_from_search, from: :from_here)
76
+ end
77
+ found.should == @subject.expected_to_find
78
+ end
79
+
80
+ end
@@ -0,0 +1,10 @@
1
+ describe 'Obj-C Selectors' do
2
+
3
+ it 'should work' do
4
+ -> do
5
+ layout = TestObjcSelectorsLayout.new
6
+ layout.view
7
+ end.should.not.raise
8
+ end
9
+
10
+ end
@@ -0,0 +1,67 @@
1
+ describe 'Orientation helpers' do
2
+
3
+ before do
4
+ @layout = MK::Layout.new
5
+ end
6
+
7
+ it 'should have orientation helpers' do
8
+ @layout.context({}) do
9
+ @layout.orientation?(UIInterfaceOrientationPortrait).should == true
10
+ @layout.orientation?(UIInterfaceOrientationLandscapeLeft).should == false
11
+ @layout.orientation?(UIInterfaceOrientationLandscapeRight).should == false
12
+ @layout.orientation?(UIInterfaceOrientationPortraitUpsideDown).should == false
13
+ end
14
+ end
15
+
16
+ it 'should have orientation (portrait?) helpers' do
17
+ @layout.context({}) do
18
+ @layout.portrait?.should == true
19
+ @layout.upright?.should == true
20
+ @layout.upside_down?.should == false
21
+ @layout.landscape?.should == false
22
+ @layout.landscape_left?.should == false
23
+ @layout.landscape_right?.should == false
24
+ end
25
+ end
26
+
27
+ it 'should have orientation (portrait do end) helpers' do
28
+ @layout.context({}) do
29
+ @check = false
30
+ @layout.portrait do
31
+ @check = true
32
+ end
33
+ @check.should == true
34
+
35
+ @check = false
36
+ @layout.upright do
37
+ @check = true
38
+ end
39
+ @check.should == true
40
+
41
+ @check = false
42
+ @layout.upside_down do
43
+ @check = true
44
+ end
45
+ @check.should == false
46
+
47
+ @check = false
48
+ @layout.landscape do
49
+ @check = true
50
+ end
51
+ @check.should == false
52
+
53
+ @check = false
54
+ @layout.landscape_left do
55
+ @check = true
56
+ end
57
+ @check.should == false
58
+
59
+ @check = false
60
+ @layout.landscape_right do
61
+ @check = true
62
+ end
63
+ @check.should == false
64
+ end
65
+ end
66
+
67
+ end