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
+ # @requires MotionKit::UIViewHelpers
2
+ module MotionKit
3
+ class UIViewHelpers
4
+
5
+ def constraints(add_to_view=nil, &block)
6
+ add_to_view ||= target
7
+ if add_to_view.is_a?(Symbol)
8
+ add_to_view = self.get_view(add_to_view)
9
+ end
10
+ add_to_view.setTranslatesAutoresizingMaskIntoConstraints(false)
11
+
12
+ constraints_target = ConstraintsTarget.new(add_to_view)
13
+ deferred(constraints_target) do
14
+ context(constraints_target, &block)
15
+ constraints_target.apply_all_constraints(self, add_to_view)
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ class Layout
22
+
23
+ # Ensure we always have a context in this method; makes it easier to define
24
+ # constraints in an `add_constraints` method.
25
+ def constraints(add_to_view=nil, &block)
26
+ if has_context?
27
+ apply(:constraints, add_to_view, &block)
28
+ else
29
+ context(self.view) do
30
+ constraints(add_to_view, &block)
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,316 @@
1
+ # @requires MotionKit::UIViewHelpers
2
+ module MotionKit
3
+ class UIViewHelpers
4
+
5
+ def x(value)
6
+ f = target.frame
7
+ f.origin.x = MotionKit.calculate(target, :width, value)
8
+ target.frame = f
9
+ return CGRectGetMinX(f)
10
+ end
11
+ alias left x
12
+
13
+ def right(value)
14
+ f = target.frame
15
+ f.origin.x = MotionKit.calculate(target, :width, value) - f.size.width
16
+ target.frame = f
17
+ return CGRectGetMaxX(f)
18
+ end
19
+
20
+ def center_x(value)
21
+ c = target.center
22
+ c.x = MotionKit.calculate(target, :width, value)
23
+ target.center = c
24
+ return CGRectGetMidX(target.frame)
25
+ end
26
+ alias middle_x center_x
27
+
28
+ def y(value)
29
+ f = target.frame
30
+ f.origin.y = MotionKit.calculate(target, :height, value)
31
+ target.frame = f
32
+ return CGRectGetMinY(f)
33
+ end
34
+ alias top y
35
+
36
+ def bottom(value)
37
+ f = target.frame
38
+ f.origin.y = MotionKit.calculate(target, :height, value) - f.size.height
39
+ target.frame = f
40
+ return CGRectGetMaxY(f)
41
+ end
42
+
43
+ def center_y(value)
44
+ c = target.center
45
+ c.y = MotionKit.calculate(target, :height, value)
46
+ target.center = c
47
+ return CGRectGetMidY(target.frame)
48
+ end
49
+ alias middle_y center_y
50
+
51
+ def width(value)
52
+ f = target.frame
53
+ f.size.width = MotionKit.calculate(target, :width, value)
54
+ target.frame = f
55
+ return CGRectGetWidth(f)
56
+ end
57
+ alias w width
58
+
59
+ def height(value)
60
+ f = target.frame
61
+ f.size.height = MotionKit.calculate(target, :height, value)
62
+ target.frame = f
63
+ return CGRectGetHeight(f)
64
+ end
65
+ alias h height
66
+
67
+ def origin(value)
68
+ f = target.frame
69
+ f.origin = MotionKit.calculate(target, :origin, value)
70
+ target.frame = f
71
+ return target.frame.origin
72
+ end
73
+
74
+ def center(value)
75
+ target.center = MotionKit.calculate(target, :center, value)
76
+ return target.center
77
+ end
78
+ alias middle center
79
+
80
+ def size(value)
81
+ f = target.frame
82
+ f.size = MotionKit.calculate(target, :size, value)
83
+ target.frame = f
84
+ return target.frame.size
85
+ end
86
+
87
+ def frame(value)
88
+ target.frame = MotionKit.calculate(target, :frame, value)
89
+ return target.frame
90
+ end
91
+
92
+ def _calculate_frame(f, from: from_view, relative_to: point)
93
+ if from_view.is_a?(Symbol)
94
+ from_view = self.get_view(from_view)
95
+ end
96
+
97
+ from_view_size = from_view.frame.size
98
+ o = from_view.convertPoint([0, 0], toView: target.superview)
99
+
100
+ calculate_view = UIView.alloc.initWithFrame([[0, 0], target.frame.size])
101
+
102
+ if f.is_a?(Hash)
103
+ f = f.merge(relative: true)
104
+ end
105
+ f = MotionKit.calculate(calculate_view, :frame, f, target.superview)
106
+ f.origin.x += o.x
107
+ f.origin.y += o.y
108
+
109
+ case point[:x]
110
+ when :min, :reset
111
+ # pass
112
+ when :mid
113
+ f.origin.x += (from_view_size.width - f.size.width) / 2.0
114
+ when :max
115
+ f.origin.x += from_view_size.width - f.size.width
116
+ when :before
117
+ f.origin.x -= f.size.width
118
+ when :after
119
+ f.origin.x += from_view_size.width
120
+ else
121
+ f.origin.x += point[:x]
122
+ end
123
+
124
+ case point[:y]
125
+ when :min, :reset
126
+ # pass
127
+ when :mid
128
+ f.origin.y += (from_view_size.height - f.size.height) / 2.0
129
+ when :max
130
+ f.origin.y += from_view_size.height - f.size.height
131
+ when :above
132
+ f.origin.y -= f.size.height
133
+ when :below
134
+ f.origin.y += from_view_size.height
135
+ else
136
+ f.origin.y += point[:y]
137
+ end
138
+
139
+ return f
140
+ end
141
+
142
+ # The first arg can be a view or a frame
143
+ # @example
144
+ # frame from_top_left(width: 80, height: 22)
145
+ # frame from_top_left(another_view, width: 80, height: 22)
146
+ def from_top_left(from_view=nil, f=nil)
147
+ if from_view.is_a?(Hash)
148
+ f = from_view
149
+ from_view = nil
150
+ end
151
+ f ||= {}
152
+ from_view ||= target.superview
153
+ _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :min })
154
+ end
155
+
156
+ # The first arg can be a view or a frame
157
+ # @example
158
+ # frame from_top(width: 80, height: 22)
159
+ # frame from_top(another_view, width: 80, height: 22)
160
+ def from_top(from_view=nil, f=nil)
161
+ if from_view.is_a?(Hash)
162
+ f = from_view
163
+ from_view = nil
164
+ end
165
+ f ||= {}
166
+ from_view ||= target.superview
167
+ _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :min })
168
+ end
169
+
170
+ # The first arg can be a view or a frame
171
+ # @example
172
+ # frame from_top_right(width: 80, height: 22)
173
+ # frame from_top_right(another_view, width: 80, height: 22)
174
+ def from_top_right(from_view=nil, f=nil)
175
+ if from_view.is_a?(Hash)
176
+ f = from_view
177
+ from_view = nil
178
+ end
179
+ f ||= {}
180
+ from_view ||= target.superview
181
+ _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :min })
182
+ end
183
+
184
+ # The first arg can be a view or a frame
185
+ # @example
186
+ # frame from_left(width: 80, height: 22)
187
+ # frame from_left(another_view, width: 80, height: 22)
188
+ def from_left(from_view=nil, f=nil)
189
+ if from_view.is_a?(Hash)
190
+ f = from_view
191
+ from_view = nil
192
+ end
193
+ f ||= {}
194
+ from_view ||= target.superview
195
+ _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :mid })
196
+ end
197
+
198
+ # The first arg can be a view or a frame
199
+ # @example
200
+ # frame from_center(width: 80, height: 22)
201
+ # frame from_center(another_view, width: 80, height: 22)
202
+ def from_center(from_view=nil, f=nil)
203
+ if from_view.is_a?(Hash)
204
+ f = from_view
205
+ from_view = nil
206
+ end
207
+ f ||= {}
208
+ from_view ||= target.superview
209
+ _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :mid })
210
+ end
211
+
212
+ # The first arg can be a view or a frame
213
+ # @example
214
+ # frame from_right(width: 80, height: 22)
215
+ # frame from_right(another_view, width: 80, height: 22)
216
+ def from_right(from_view=nil, f=nil)
217
+ if from_view.is_a?(Hash)
218
+ f = from_view
219
+ from_view = nil
220
+ end
221
+ f ||= {}
222
+ from_view ||= target.superview
223
+ _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :mid })
224
+ end
225
+
226
+ # The first arg can be a view or a frame
227
+ # @example
228
+ # frame from_bottom_left(width: 80, height: 22)
229
+ # frame from_bottom_left(another_view, width: 80, height: 22)
230
+ def from_bottom_left(from_view=nil, f=nil)
231
+ if from_view.is_a?(Hash)
232
+ f = from_view
233
+ from_view = nil
234
+ end
235
+ f ||= {}
236
+ from_view ||= target.superview
237
+ _calculate_frame(f, from: from_view, relative_to: { x: :min, y: :max })
238
+ end
239
+
240
+ # The first arg can be a view or a frame
241
+ # @example
242
+ # frame from_bottom(width: 80, height: 22)
243
+ # frame from_bottom(another_view, width: 80, height: 22)
244
+ def from_bottom(from_view=nil, f=nil)
245
+ if from_view.is_a?(Hash)
246
+ f = from_view
247
+ from_view = nil
248
+ end
249
+ f ||= {}
250
+ from_view ||= target.superview
251
+ _calculate_frame(f, from: from_view, relative_to: { x: :mid, y: :max })
252
+ end
253
+
254
+ # The first arg can be a view or a frame
255
+ # @example
256
+ # frame from_bottom_right(width: 80, height: 22)
257
+ # frame from_bottom_right(another_view, width: 80, height: 22)
258
+ def from_bottom_right(from_view=nil, f=nil)
259
+ if from_view.is_a?(Hash)
260
+ f = from_view
261
+ from_view = nil
262
+ end
263
+ f ||= {}
264
+ from_view ||= target.superview
265
+ _calculate_frame(f, from: from_view, relative_to: { x: :max, y: :max })
266
+ end
267
+
268
+ # The first arg can be a view or a frame
269
+ # @example
270
+ # frame above(view, [[0, 0], [100, 20]])
271
+ # frame above(:view, x: 0, y: 0, width: 100, height: 20)
272
+ # frame above(:view, down: 0, right: 0, width: 100, height: 20)
273
+ def above(from_view, f={})
274
+ _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :above })
275
+ end
276
+
277
+ # The first arg can be a view or a frame
278
+ # @example
279
+ # frame below(view, [[0, 0], [100, 20]])
280
+ # frame below(:view, x: 0, y: 0, width: 100, height: 20)
281
+ # frame below(:view, down: 0, right: 0, width: 100, height: 20)
282
+ def below(from_view, f={})
283
+ _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :below })
284
+ end
285
+
286
+ # The first arg can be a view or a frame
287
+ # @example
288
+ # frame before(view, [[0, 0], [100, 20]])
289
+ # frame before(:view, x: 0, y: 0, width: 100, height: 20)
290
+ # frame before(:view, down: 0, right: 0, width: 100, height: 20)
291
+ def before(from_view, f={})
292
+ _calculate_frame(f, from: from_view, relative_to: { x: :before, y: :reset })
293
+ end
294
+ alias left_of before
295
+
296
+ # The first arg can be a view or a frame
297
+ # @example
298
+ # frame after(view, [[0, 0], [100, 20]])
299
+ # frame after(:view, x: 0, y: 0, width: 100, height: 20)
300
+ # frame after(:view, down: 0, right: 0, width: 100, height: 20)
301
+ def after(from_view, f={})
302
+ _calculate_frame(f, from: from_view, relative_to: { x: :after, y: :reset })
303
+ end
304
+ alias right_of after
305
+
306
+ # The first arg must be a view
307
+ # @example
308
+ # frame relative_to(view, [[0, 0], [100, 20]])
309
+ # frame relative_to(:view, x: 0, y: 0, width: 100, height: 20)
310
+ # frame relative_to(:view, down: 0, right: 0, width: 100, height: 20)
311
+ def relative_to(from_view, f)
312
+ _calculate_frame(f, from: from_view, relative_to: { x: :reset, y: :reset })
313
+ end
314
+
315
+ end
316
+ end
@@ -0,0 +1,22 @@
1
+ # @requires MotionKit::UIViewHelpers
2
+ module MotionKit
3
+ class UIViewHelpers
4
+
5
+ # gradient colors:
6
+ def gradient(&block)
7
+ gradient_layer = target.motion_kit_meta[:motionkit_gradient_layer] || begin
8
+ gradient_layer = CAGradientLayer.layer
9
+ gradient_layer.frame = CGRect.new([0, 0], target.frame.size)
10
+ target.layer.insertSublayer(gradient_layer, atIndex:0)
11
+ target.motion_kit_meta[:motionkit_gradient_layer] = gradient_layer
12
+
13
+ gradient_layer
14
+ end
15
+
16
+ context(gradient_layer, &block)
17
+
18
+ gradient_layer
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # @provides MotionKit::Layout
2
+ # @provides MotionKit::UIViewHelpers
3
+ # @requires MotionKit::TreeLayout
4
+ module MotionKit
5
+ class Layout < TreeLayout
6
+
7
+ # platform specific default root view
8
+ def default_root
9
+ # child Layout classes will return *their* UIView subclass from self.targets
10
+ view_class = self.class.targets || MotionKit.default_view_class
11
+ view_class.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
12
+ end
13
+
14
+ def add_child(subview)
15
+ target.addSubview(subview)
16
+ end
17
+
18
+ def remove_child(subview)
19
+ subview.removeFromSuperview
20
+ end
21
+
22
+ end
23
+
24
+ class UIViewHelpers < Layout
25
+ targets UIView
26
+ end
27
+
28
+ end
@@ -0,0 +1,24 @@
1
+ module MotionKit
2
+ module_function
3
+
4
+ def appearance_class
5
+ @appearance_klass ||= UIView.appearance.class
6
+ end
7
+
8
+ def base_view_class
9
+ UIView
10
+ end
11
+
12
+ def default_view_class
13
+ UIView
14
+ end
15
+
16
+ def color_class
17
+ UIColor
18
+ end
19
+
20
+ def no_intrinsic_metric
21
+ UIViewNoIntrinsicMetric
22
+ end
23
+
24
+ end
data/lib/motion-kit.rb CHANGED
@@ -14,6 +14,8 @@ Motion::Project::App.setup do |app|
14
14
  platform_name = 'ios'
15
15
  elsif platform.to_s.start_with?('osx')
16
16
  platform_name = 'osx'
17
+ elsif platform.to_s.start_with?('tvos')
18
+ platform_name = 'tvos'
17
19
  end
18
20
  platform_lib = File.join(File.dirname(__FILE__), "motion-kit-#{platform_name}")
19
21
  unless File.exists? platform_lib
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '0.18.0'
2
+ VERSION = '1.0.0'
3
3
  end