motion-kit 0.18.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,19 @@
1
+ describe "layout parent methods" do
2
+ before do
3
+ @subject = TestParentLayout.new.view.subviews.first
4
+ end
5
+
6
+ it "should be a UIView" do
7
+ @subject.should.be.kind_of UIView
8
+ end
9
+
10
+ it "should set the first subview frame properly" do
11
+ @subject.frame.should == CGRectMake(0, 0, 100, 60)
12
+ end
13
+
14
+ it "should use parent to set its frame properly" do
15
+ @subject.subviews.first.frame.should == CGRectMake(10, 10, 50, 30)
16
+ @subject.subviews.first.subviews.first.frame.should == CGRectMake(25, 15, 40, 20)
17
+ end
18
+
19
+ end
@@ -0,0 +1,45 @@
1
+ describe MotionKit::Parent do
2
+
3
+ before do
4
+ uiview = UIView.new
5
+ uiview.frame = [[10, 20], [30, 40]]
6
+ @subject = MotionKit::Parent.new(uiview)
7
+ end
8
+
9
+ it "should return the x value" do
10
+ @subject.x.should == 10
11
+ end
12
+
13
+ it "should return the y value" do
14
+ @subject.y.should == 20
15
+ end
16
+
17
+ it "should return the width value" do
18
+ @subject.width.should == 30
19
+ end
20
+
21
+ it "should return the height value" do
22
+ @subject.height.should == 40
23
+ end
24
+
25
+ it "should return the center_x value" do
26
+ @subject.center_x.should == 15
27
+ end
28
+
29
+ it "should return the center_y value" do
30
+ @subject.center_y.should == 20
31
+ end
32
+
33
+ it "should return the center point" do
34
+ @subject.center.should == CGPointMake(15, 20)
35
+ end
36
+
37
+ it "should return the origin point" do
38
+ @subject.origin.should == CGPointMake(10, 20)
39
+ end
40
+
41
+ it "should return the size rect" do
42
+ @subject.size.should == CGSizeMake(30, 40)
43
+ end
44
+
45
+ end
@@ -0,0 +1,153 @@
1
+ describe 'MotionKit prev/next element logic' do
2
+
3
+ before do
4
+ @subject = TestPrevNextLayout.new.build
5
+ end
6
+
7
+ it 'should find "nil" before "first"' do
8
+ found = nil
9
+ @subject.context(@subject.first_row) do
10
+ found = @subject.prev(:row)
11
+ end
12
+ found.should == nil
13
+ end
14
+
15
+ it 'should find "first" before "second"' do
16
+ found = nil
17
+ @subject.context(@subject.second_row) do
18
+ found = @subject.prev(:row)
19
+ end
20
+ found.should == @subject.first_row
21
+ end
22
+
23
+ it 'should find "second" before "third"' do
24
+ found = nil
25
+ @subject.context(@subject.third_row) do
26
+ found = @subject.prev(:row)
27
+ end
28
+ found.should == @subject.second_row
29
+ end
30
+
31
+ it 'should find "second" after "first"' do
32
+ found = nil
33
+ @subject.context(@subject.first_row) do
34
+ found = @subject.next(:row)
35
+ end
36
+ found.should == @subject.second_row
37
+ end
38
+
39
+ it 'should find "third" after "second"' do
40
+ found = nil
41
+ @subject.context(@subject.second_row) do
42
+ found = @subject.next(:row)
43
+ end
44
+ found.should == @subject.third_row
45
+ end
46
+
47
+ it 'should find "nil" after "third"' do
48
+ found = nil
49
+ @subject.context(@subject.third_row) do
50
+ found = @subject.next(:row)
51
+ end
52
+ found.should == nil
53
+ end
54
+
55
+ describe 'Using :from option' do
56
+
57
+ before do
58
+ @subject.from_search
59
+ @start_here = @subject.get(:start_here)
60
+ end
61
+
62
+ it 'should find "nil" before "first"' do
63
+ found = nil
64
+ @subject.context(@start_here) do
65
+ found = @subject.prev(:row, from: @subject.first_row)
66
+ end
67
+ found.should == nil
68
+ end
69
+
70
+ it 'should find "first" before "second"' do
71
+ found = nil
72
+ @subject.context(@start_here) do
73
+ found = @subject.prev(:row, from: @subject.second_row)
74
+ end
75
+ found.should == @subject.first_row
76
+ end
77
+
78
+ it 'should find "second" before "third"' do
79
+ found = nil
80
+ @subject.context(@start_here) do
81
+ found = @subject.prev(:row, from: @subject.third_row)
82
+ end
83
+ found.should == @subject.second_row
84
+ end
85
+
86
+ it 'should find "second" after "first"' do
87
+ found = nil
88
+ @subject.context(@start_here) do
89
+ found = @subject.next(:row, from: @subject.first_row)
90
+ end
91
+ found.should == @subject.second_row
92
+ end
93
+
94
+ it 'should find "third" after "second"' do
95
+ found = nil
96
+ @subject.context(@start_here) do
97
+ found = @subject.next(:row, from: @subject.second_row)
98
+ end
99
+ found.should == @subject.third_row
100
+ end
101
+
102
+ it 'should find "nil" after "third"' do
103
+ found = nil
104
+ @subject.context(@start_here) do
105
+ found = @subject.next(:row, from: @subject.third_row)
106
+ end
107
+ found.should == nil
108
+ end
109
+
110
+ end
111
+
112
+ describe 'Using :from option and symbols' do
113
+
114
+ before do
115
+ @subject.from_symbol_search
116
+ @start_here = @subject.get(:start_here)
117
+ end
118
+
119
+ it 'should find prev(:first_row, from: :second_row)' do
120
+ found = nil
121
+ @subject.context(@start_here) do
122
+ found = @subject.prev(:first_row, from: :second_row)
123
+ end
124
+ found.should == @subject.first_row
125
+ end
126
+
127
+ it 'should find next(:third_row, from: :second_row)' do
128
+ found = nil
129
+ @subject.context(@start_here) do
130
+ found = @subject.next(:third_row, from: :second_row)
131
+ end
132
+ found.should == @subject.third_row
133
+ end
134
+
135
+ it 'should find prev(:first_row, from: :third_row)' do
136
+ found = nil
137
+ @subject.context(@start_here) do
138
+ found = @subject.prev(:first_row, from: :third_row)
139
+ end
140
+ found.should == @subject.first_row
141
+ end
142
+
143
+ it 'should find next(:third_row, from: :first_row)' do
144
+ found = nil
145
+ @subject.context(@start_here) do
146
+ found = @subject.next(:third_row, from: :first_row)
147
+ end
148
+ found.should == @subject.third_row
149
+ end
150
+
151
+ end
152
+
153
+ end
@@ -0,0 +1,64 @@
1
+ describe 'Views frames should remain unchanged' do
2
+
3
+ before do
4
+ @subject = ReapplyTestLayout.new
5
+ @cw = @subject.view.frame.size.width # container width
6
+ @ch = @subject.view.frame.size.height # container height
7
+ end
8
+
9
+ it "top_left should be in the right position before and after reapply" do
10
+ @subject.get(:top_left).frame.should == CGRectMake(0,0,10,10)
11
+ @subject.reapply!
12
+ @subject.get(:top_left).frame.should == CGRectMake(0,0,10,10)
13
+ end
14
+
15
+ it "top should be in the right position before and after reapply" do
16
+ @subject.get(:top).frame.should == CGRectMake(@cw/2 - 5, 0, 10, 10)
17
+ @subject.reapply!
18
+ @subject.get(:top).frame.should == CGRectMake(@cw/2 - 5, 0, 10, 10)
19
+ end
20
+
21
+ it "top_right should be in the right position before and after reapply" do
22
+ @subject.get(:top_right).frame.should == CGRectMake(@cw - 10, 0, 10, 10)
23
+ @subject.reapply!
24
+ @subject.get(:top_right).frame.should == CGRectMake(@cw - 10, 0, 10, 10)
25
+ end
26
+
27
+ it "left should be in the right position before and after reapply" do
28
+ @subject.get(:left).frame.should == CGRectMake(0, @ch/2 - 5, 10, 10)
29
+ @subject.reapply!
30
+ @subject.get(:left).frame.should == CGRectMake(0, @ch/2 - 5, 10, 10)
31
+ end
32
+
33
+ it "center should be in the right position before and after reapply" do
34
+ @subject.get(:center).frame.should == CGRectMake(@cw/2 - 5, @ch/2 - 5, 10, 10)
35
+ @subject.reapply!
36
+ @subject.get(:center).frame.should == CGRectMake(@cw/2 - 5, @ch/2 - 5, 10, 10)
37
+ end
38
+
39
+ it "right should be in the right position before and after reapply" do
40
+ @subject.get(:right).frame.should == CGRectMake(@cw - 10, @ch/2 - 5, 10, 10)
41
+ @subject.reapply!
42
+ @subject.get(:right).frame.should == CGRectMake(@cw - 10, @ch/2 - 5, 10, 10)
43
+ end
44
+
45
+ it "bottom_left should be in the right position before and after reapply" do
46
+ @subject.get(:bottom_left).frame.should == CGRectMake(0, @ch - 10, 10, 10)
47
+ @subject.reapply!
48
+ @subject.get(:bottom_left).frame.should == CGRectMake(0, @ch - 10, 10, 10)
49
+ end
50
+
51
+ it "bottom should be in the right position before and after reapply" do
52
+ @subject.get(:bottom).frame.should == CGRectMake(@cw/2 - 5, @ch - 10, 10, 10)
53
+ @subject.reapply!
54
+ @subject.get(:bottom).frame.should == CGRectMake(@cw/2 - 5, @ch - 10, 10, 10)
55
+ end
56
+
57
+ it "bottom_right should be in the right position before and after reapply" do
58
+ @subject.get(:bottom_right).frame.should == CGRectMake(@cw - 10, @ch - 10, 10, 10)
59
+ @subject.reapply!
60
+ @subject.get(:bottom_right).frame.should == CGRectMake(@cw - 10, @ch - 10, 10, 10)
61
+ end
62
+
63
+ end
64
+
@@ -0,0 +1,31 @@
1
+ describe 'Relative Layouts' do
2
+ before do
3
+ @subject = TestRelativeLayout.new.build
4
+ end
5
+
6
+ it "should have two subviews" do
7
+ @subject.view.subviews.count.should == 2
8
+ end
9
+
10
+ describe "should have a test view" do
11
+ it "with origin x = y = 0" do
12
+ @subject.get(:test).frame.origin.x.should == 0
13
+ @subject.get(:test).frame.origin.y.should == 0
14
+ end
15
+ it "with frame w = h = 100" do
16
+ @subject.get(:test).frame.size.width.should == UIScreen.mainScreen.bounds.size.width
17
+ @subject.get(:test).frame.size.height.should == 100
18
+ end
19
+ end
20
+
21
+ describe "should have a test2 view below test view" do
22
+ it "with origin x = 0, y = 100" do
23
+ @subject.get(:test2).frame.origin.x.should == 0
24
+ @subject.get(:test2).frame.origin.y.should == 100
25
+ end
26
+ it "with frame w = 100, h = 50" do
27
+ @subject.get(:test2).frame.size.width.should == UIScreen.mainScreen.bounds.size.width
28
+ @subject.get(:test2).frame.size.height.should == 50
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ describe 'Remove views' do
2
+ before do
3
+ @subject = TestRemoveLayout.new.build
4
+ end
5
+
6
+ it 'should remove the #label view' do
7
+ @subject.get(:label).should.be.kind_of(UILabel)
8
+ @subject.remove_label
9
+ @subject.get(:label).should.be.nil
10
+ end
11
+
12
+ it 'should forget the #image view' do
13
+ image = @subject.get(:image)
14
+ image.should.be.kind_of(UIImageView)
15
+ @subject.forget_image
16
+ @subject.get(:image).should.be.nil
17
+ image.superview.should.not.be.nil
18
+ end
19
+
20
+ it 'should remove the #view from the hierarchy' do
21
+ view = @subject.get(:view)
22
+ view.should.be.kind_of(UIView)
23
+ @subject.remove_view
24
+ @subject.get(:view).should.be.nil
25
+ view.superview.should.be.nil
26
+ end
27
+
28
+ end
@@ -0,0 +1,53 @@
1
+ describe 'Assigning explicit root view' do
2
+ before { @subject = TestRootLayout.new }
3
+
4
+ it "should allow setting the root view" do
5
+ @subject.view.should.be.kind_of UIScrollView
6
+ end
7
+
8
+ it "should still create subviews" do
9
+ @subject.view.subviews.first.should.be.kind_of UIButton
10
+ @subject.view.subviews.first.subviews.first.should.be.kind_of UILabel
11
+ end
12
+
13
+ it "should call style method" do
14
+ @subject.view
15
+ @subject.scroll_view_styled.should == true
16
+ end
17
+
18
+ it "should call style method on simple root layout" do
19
+ subject = TestSimpleRootLayout.new
20
+
21
+ subject.view
22
+ subject.label_styled.should == true
23
+ end
24
+
25
+ it "should raise exception if you try to specify two roots" do
26
+ -> do
27
+ subject = TestDuplicateRootLayout.new
28
+ subject.view
29
+ end.should.raise(MotionKit::ContextConflictError)
30
+ end
31
+
32
+ it "should raise exception if you don't add views inside the root" do
33
+ -> do
34
+ subject = TestNoRootContextLayout.new
35
+ subject.view
36
+ end.should.raise(MotionKit::NoContextError)
37
+ end
38
+
39
+ it 'should raise an exception when there is no context' do
40
+ -> do
41
+ subject = TestNoContextLayout.new
42
+ subject.foo
43
+ end.should.raise(MotionKit::NoContextError)
44
+ end
45
+
46
+ it 'should raise an exception when creating a root view outside of `layout`' do
47
+ -> do
48
+ subject = TestInvalidRootContextLayout.new
49
+ subject.foo
50
+ end.should.raise(MotionKit::InvalidRootError)
51
+ end
52
+
53
+ end
@@ -0,0 +1,63 @@
1
+ describe "Layout setters" do
2
+
3
+ describe "Pure ruby object" do
4
+
5
+ before do
6
+ @subject = TestSetters.new(TestSettersFixture.new)
7
+ end
8
+
9
+ it 'should set foo (setFoo)' do
10
+ @subject.run_foo
11
+ @subject.target.foo.should == 'foo'
12
+ end
13
+
14
+ it 'should set bar (bar=)' do
15
+ @subject.run_bar
16
+ @subject.target.bar.should == 'bar'
17
+ end
18
+
19
+ it 'should set setter (setter(val))' do
20
+ @subject.run_setter
21
+ @subject.target.setter.should == 'setter'
22
+ end
23
+
24
+ it 'should assign quux (baz.quux, attr_accessor) with baz as context' do
25
+ @subject.run_baz
26
+ @subject.target.baz.quux.should == 'quux'
27
+ end
28
+
29
+ it 'should assign quux (bazBaz.quux, attr_accessor) with baz_baz as context' do
30
+ @subject.run_baz_baz
31
+ @subject.target.bazBaz.quux.should == 'quux'
32
+ end
33
+
34
+ end
35
+
36
+ describe "Objective-C object" do
37
+
38
+ before do
39
+ @subject = TestSetters.new(TestSettersLabel.new)
40
+ end
41
+
42
+ it 'should set text (setText)' do
43
+ @subject.run_text
44
+ @subject.target.text.should == 'text'
45
+ end
46
+
47
+ it 'should set bar (bar=)' do
48
+ @subject.run_bar
49
+ @subject.target.bar.should == 'bar'
50
+ end
51
+
52
+ it 'should set background_color (setBackgroundColor)' do
53
+ @subject.run_background_color
54
+ @subject.target.backgroundColor.should == UIColor.whiteColor
55
+ end
56
+
57
+ it 'should assign cornerRadius (layer.corner_radius) with layer as context' do
58
+ @subject.run_layer(5)
59
+ @subject.target.layer.cornerRadius.should == 5
60
+ end
61
+ end
62
+
63
+ end