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.
- checksums.yaml +4 -4
- data/README.md +39 -1
- data/lib/motion-kit-tvos/deprecated.rb +31 -0
- data/lib/motion-kit-tvos/dummy.rb +93 -0
- data/lib/motion-kit-tvos/helpers/constraints_helpers.rb +24 -0
- data/lib/motion-kit-tvos/helpers/layout_device.rb +36 -0
- data/lib/motion-kit-tvos/helpers/layout_orientation.rb +54 -0
- data/lib/motion-kit-tvos/helpers/uibutton_helpers.rb +52 -0
- data/lib/motion-kit-tvos/helpers/uiview_autoresizing_helpers.rb +79 -0
- data/lib/motion-kit-tvos/helpers/uiview_constraints_helpers.rb +36 -0
- data/lib/motion-kit-tvos/helpers/uiview_frame_helpers.rb +316 -0
- data/lib/motion-kit-tvos/helpers/uiview_gradient_helpers.rb +22 -0
- data/lib/motion-kit-tvos/helpers/uiview_helpers.rb +28 -0
- data/lib/motion-kit-tvos/ios_util.rb +24 -0
- data/lib/motion-kit.rb +2 -0
- data/lib/motion-kit/version.rb +1 -1
- data/spec/tvos/apply_styles_spec.rb +37 -0
- data/spec/tvos/autoresizing_helper_spec.rb +240 -0
- data/spec/tvos/calayer_spec.rb +23 -0
- data/spec/tvos/calculate_spec.rb +322 -0
- data/spec/tvos/calculator_spec.rb +31 -0
- data/spec/tvos/child_layouts_spec.rb +65 -0
- data/spec/tvos/constraints_helpers/active_constraints_spec.rb +25 -0
- data/spec/tvos/constraints_helpers/attribute_lookup_spec.rb +27 -0
- data/spec/tvos/constraints_helpers/axis_lookup_spec.rb +13 -0
- data/spec/tvos/constraints_helpers/center_constraints_spec.rb +421 -0
- data/spec/tvos/constraints_helpers/constraint_placeholder_spec.rb +72 -0
- data/spec/tvos/constraints_helpers/priority_lookup_spec.rb +19 -0
- data/spec/tvos/constraints_helpers/relationship_lookup_spec.rb +27 -0
- data/spec/tvos/constraints_helpers/relative_corners_spec.rb +276 -0
- data/spec/tvos/constraints_helpers/relative_location_spec.rb +113 -0
- data/spec/tvos/constraints_helpers/scale_constraints_spec.rb +62 -0
- data/spec/tvos/constraints_helpers/simple_constraints_spec.rb +2755 -0
- data/spec/tvos/constraints_helpers/size_constraints_spec.rb +423 -0
- data/spec/tvos/constraints_helpers/view_lookup_constraints_spec.rb +95 -0
- data/spec/tvos/create_layout_spec.rb +40 -0
- data/spec/tvos/custom_layout_spec.rb +13 -0
- data/spec/tvos/custom_root_layout_spec.rb +57 -0
- data/spec/tvos/deferred_spec.rb +89 -0
- data/spec/tvos/device_helpers_spec.rb +58 -0
- data/spec/tvos/frame_helper_spec.rb +1160 -0
- data/spec/tvos/layer_layout_spec.rb +36 -0
- data/spec/tvos/layout_extensions_spec.rb +70 -0
- data/spec/tvos/layout_spec.rb +57 -0
- data/spec/tvos/layout_state_spec.rb +27 -0
- data/spec/tvos/memory_leak_spec.rb +74 -0
- data/spec/tvos/motion_kit_id_spec.rb +15 -0
- data/spec/tvos/motionkit_util_spec.rb +15 -0
- data/spec/tvos/nearest_spec.rb +80 -0
- data/spec/tvos/objc_selectors_spec.rb +10 -0
- data/spec/tvos/orientation_helper_specs.rb +67 -0
- data/spec/tvos/parent_layout_spec.rb +19 -0
- data/spec/tvos/parent_spec.rb +45 -0
- data/spec/tvos/prev_next_spec.rb +153 -0
- data/spec/tvos/reapply_frame.rb +64 -0
- data/spec/tvos/relative_layout.spec.rb +31 -0
- data/spec/tvos/remove_layout_spec.rb +28 -0
- data/spec/tvos/root_layout_spec.rb +53 -0
- data/spec/tvos/setters_spec.rb +63 -0
- data/spec/tvos/uibutton_layout_spec.rb +37 -0
- data/spec/tvos/uitextfield_spec.rb +14 -0
- data/spec/tvos/view_attr_spec.rb +32 -0
- metadata +118 -8
@@ -0,0 +1,423 @@
|
|
1
|
+
describe 'Constraints - Size helpers' do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@layout = MK::Layout.new
|
5
|
+
@constraint = nil
|
6
|
+
@view = UIView.new
|
7
|
+
@parent_view = UIView.new
|
8
|
+
@parent_view.addSubview(@view)
|
9
|
+
@another_view = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should support `size 10`' do
|
13
|
+
@layout.context(@view) do
|
14
|
+
@layout.constraints do
|
15
|
+
@constraint = @layout.size(10)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
@constraint.constant.should == [10, 10]
|
20
|
+
@constraint.relationship.should == :equal
|
21
|
+
@constraint.multiplier.should == [1, 1]
|
22
|
+
@constraint.relative_to.should == nil
|
23
|
+
@constraint.attribute.should == [:width, :height]
|
24
|
+
@constraint.attribute2.should == [:width, :height]
|
25
|
+
end
|
26
|
+
it 'should support `min_size 10`' do
|
27
|
+
@layout.context(UIView.new) do
|
28
|
+
@layout.constraints do
|
29
|
+
@constraint = @layout.min_size(10)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
@constraint.constant.should == [10, 10]
|
34
|
+
@constraint.relationship.should == :gte
|
35
|
+
@constraint.multiplier.should == [1, 1]
|
36
|
+
@constraint.relative_to.should == nil
|
37
|
+
@constraint.attribute.should == [:width, :height]
|
38
|
+
@constraint.attribute2.should == [:width, :height]
|
39
|
+
end
|
40
|
+
it 'should support `max_size 10`' do
|
41
|
+
@layout.context(UIView.new) do
|
42
|
+
@layout.constraints do
|
43
|
+
@constraint = @layout.max_size(10)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
@constraint.constant.should == [10, 10]
|
48
|
+
@constraint.relationship.should == :lte
|
49
|
+
@constraint.multiplier.should == [1, 1]
|
50
|
+
@constraint.relative_to.should == nil
|
51
|
+
@constraint.attribute.should == [:width, :height]
|
52
|
+
@constraint.attribute2.should == [:width, :height]
|
53
|
+
end
|
54
|
+
it 'should support `size [10, 10]`' do
|
55
|
+
@layout.context(UIView.new) do
|
56
|
+
@layout.constraints do
|
57
|
+
@constraint = @layout.size([10, 10])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
@constraint.constant.should == [10, 10]
|
62
|
+
@constraint.relationship.should == :equal
|
63
|
+
@constraint.multiplier.should == [1, 1]
|
64
|
+
@constraint.relative_to.should == nil
|
65
|
+
@constraint.attribute.should == [:width, :height]
|
66
|
+
@constraint.attribute2.should == [:width, :height]
|
67
|
+
end
|
68
|
+
it 'should support `min_size [10, 10]`' do
|
69
|
+
@layout.context(UIView.new) do
|
70
|
+
@layout.constraints do
|
71
|
+
@constraint = @layout.min_size([10, 10])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
@constraint.constant.should == [10, 10]
|
76
|
+
@constraint.relationship.should == :gte
|
77
|
+
@constraint.multiplier.should == [1, 1]
|
78
|
+
@constraint.relative_to.should == nil
|
79
|
+
@constraint.attribute.should == [:width, :height]
|
80
|
+
@constraint.attribute2.should == [:width, :height]
|
81
|
+
end
|
82
|
+
it 'should support `max_size [10, 10]`' do
|
83
|
+
@layout.context(UIView.new) do
|
84
|
+
@layout.constraints do
|
85
|
+
@constraint = @layout.max_size([10, 10])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
@constraint.constant.should == [10, 10]
|
90
|
+
@constraint.relationship.should == :lte
|
91
|
+
@constraint.multiplier.should == [1, 1]
|
92
|
+
@constraint.relative_to.should == nil
|
93
|
+
@constraint.attribute.should == [:width, :height]
|
94
|
+
@constraint.attribute2.should == [:width, :height]
|
95
|
+
end
|
96
|
+
it 'should support `size w: 10, h: 10`' do
|
97
|
+
@layout.context(UIView.new) do
|
98
|
+
@layout.constraints do
|
99
|
+
@constraint = @layout.size(w: 10, h: 10)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
@constraint.constant.should == [10, 10]
|
104
|
+
@constraint.relationship.should == :equal
|
105
|
+
@constraint.multiplier.should == [1, 1]
|
106
|
+
@constraint.relative_to.should == nil
|
107
|
+
@constraint.attribute.should == [:width, :height]
|
108
|
+
@constraint.attribute2.should == [:width, :height]
|
109
|
+
end
|
110
|
+
it 'should support `min_size w: 10, h: 10`' do
|
111
|
+
@layout.context(UIView.new) do
|
112
|
+
@layout.constraints do
|
113
|
+
@constraint = @layout.min_size(w: 10, h: 10)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
@constraint.constant.should == [10, 10]
|
118
|
+
@constraint.relationship.should == :gte
|
119
|
+
@constraint.multiplier.should == [1, 1]
|
120
|
+
@constraint.relative_to.should == nil
|
121
|
+
@constraint.attribute.should == [:width, :height]
|
122
|
+
@constraint.attribute2.should == [:width, :height]
|
123
|
+
end
|
124
|
+
it 'should support `max_size w: 10, h: 10`' do
|
125
|
+
@layout.context(UIView.new) do
|
126
|
+
@layout.constraints do
|
127
|
+
@constraint = @layout.max_size(w: 10, h: 10)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
@constraint.constant.should == [10, 10]
|
132
|
+
@constraint.relationship.should == :lte
|
133
|
+
@constraint.multiplier.should == [1, 1]
|
134
|
+
@constraint.relative_to.should == nil
|
135
|
+
@constraint.attribute.should == [:width, :height]
|
136
|
+
@constraint.attribute2.should == [:width, :height]
|
137
|
+
end
|
138
|
+
it 'should support `size.equals(:another_view[, :size])`' do
|
139
|
+
@layout.context(UIView.new) do
|
140
|
+
@layout.constraints do
|
141
|
+
@constraint = @layout.size.equals(:another_view)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
@constraint.constant.should == [0, 0]
|
146
|
+
@constraint.relationship.should == :equal
|
147
|
+
@constraint.multiplier.should == [1, 1]
|
148
|
+
@constraint.relative_to.should == :another_view
|
149
|
+
@constraint.attribute.should == [:width, :height]
|
150
|
+
@constraint.attribute2.should == [:width, :height]
|
151
|
+
end
|
152
|
+
it 'should support `size.equals(:another_view).plus(10).plus([5, 10])`' do
|
153
|
+
@layout.context(UIView.new) do
|
154
|
+
@layout.constraints do
|
155
|
+
@constraint = @layout.size.equals(:another_view).plus(10).plus([5, 10])
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
@constraint.constant.should == [15, 20]
|
160
|
+
@constraint.relationship.should == :equal
|
161
|
+
@constraint.multiplier.should == [1, 1]
|
162
|
+
@constraint.relative_to.should == :another_view
|
163
|
+
@constraint.attribute.should == [:width, :height]
|
164
|
+
@constraint.attribute2.should == [:width, :height]
|
165
|
+
end
|
166
|
+
it 'should support `min_size.equals(:another_view[, :size])`' do
|
167
|
+
@layout.context(UIView.new) do
|
168
|
+
@layout.constraints do
|
169
|
+
@constraint = @layout.min_size.equals(:another_view)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
@constraint.constant.should == [0, 0]
|
174
|
+
@constraint.relationship.should == :gte
|
175
|
+
@constraint.multiplier.should == [1, 1]
|
176
|
+
@constraint.relative_to.should == :another_view
|
177
|
+
@constraint.attribute.should == [:width, :height]
|
178
|
+
@constraint.attribute2.should == [:width, :height]
|
179
|
+
end
|
180
|
+
it 'should support `max_size.equals(:another_view[, :size])`' do
|
181
|
+
@layout.context(UIView.new) do
|
182
|
+
@layout.constraints do
|
183
|
+
@constraint = @layout.max_size.equals(:another_view)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
@constraint.constant.should == [0, 0]
|
188
|
+
@constraint.relationship.should == :lte
|
189
|
+
@constraint.multiplier.should == [1, 1]
|
190
|
+
@constraint.relative_to.should == :another_view
|
191
|
+
@constraint.attribute.should == [:width, :height]
|
192
|
+
@constraint.attribute2.should == [:width, :height]
|
193
|
+
end
|
194
|
+
it 'should support `size.equals(:another_view).plus(10)`' do
|
195
|
+
@layout.context(UIView.new) do
|
196
|
+
@layout.constraints do
|
197
|
+
@constraint = @layout.size.equals(:another_view).plus(10)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
@constraint.constant.should == [10, 10]
|
202
|
+
@constraint.relationship.should == :equal
|
203
|
+
@constraint.multiplier.should == [1, 1]
|
204
|
+
@constraint.relative_to.should == :another_view
|
205
|
+
@constraint.attribute.should == [:width, :height]
|
206
|
+
@constraint.attribute2.should == [:width, :height]
|
207
|
+
end
|
208
|
+
it 'should support `min_size.equals(:another_view).plus(10)`' do
|
209
|
+
@layout.context(UIView.new) do
|
210
|
+
@layout.constraints do
|
211
|
+
@constraint = @layout.min_size.equals(:another_view).plus(10)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
@constraint.constant.should == [10, 10]
|
216
|
+
@constraint.relationship.should == :gte
|
217
|
+
@constraint.multiplier.should == [1, 1]
|
218
|
+
@constraint.relative_to.should == :another_view
|
219
|
+
@constraint.attribute.should == [:width, :height]
|
220
|
+
@constraint.attribute2.should == [:width, :height]
|
221
|
+
end
|
222
|
+
it 'should support `max_size.equals(:another_view).plus(10)`' do
|
223
|
+
@layout.context(UIView.new) do
|
224
|
+
@layout.constraints do
|
225
|
+
@constraint = @layout.max_size.equals(:another_view).plus(10)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
@constraint.constant.should == [10, 10]
|
230
|
+
@constraint.relationship.should == :lte
|
231
|
+
@constraint.multiplier.should == [1, 1]
|
232
|
+
@constraint.relative_to.should == :another_view
|
233
|
+
@constraint.attribute.should == [:width, :height]
|
234
|
+
@constraint.attribute2.should == [:width, :height]
|
235
|
+
end
|
236
|
+
it 'should support `size.equals(:another_view).plus([10, 10])`' do
|
237
|
+
@layout.context(UIView.new) do
|
238
|
+
@layout.constraints do
|
239
|
+
@constraint = @layout.size.equals(:another_view).plus([10, 10])
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
@constraint.constant.should == [10, 10]
|
244
|
+
@constraint.relationship.should == :equal
|
245
|
+
@constraint.multiplier.should == [1, 1]
|
246
|
+
@constraint.relative_to.should == :another_view
|
247
|
+
@constraint.attribute.should == [:width, :height]
|
248
|
+
@constraint.attribute2.should == [:width, :height]
|
249
|
+
end
|
250
|
+
it 'should support `min_size.equals(:another_view).plus([10, 10])`' do
|
251
|
+
@layout.context(UIView.new) do
|
252
|
+
@layout.constraints do
|
253
|
+
@constraint = @layout.min_size.equals(:another_view).plus([10, 10])
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
@constraint.constant.should == [10, 10]
|
258
|
+
@constraint.relationship.should == :gte
|
259
|
+
@constraint.multiplier.should == [1, 1]
|
260
|
+
@constraint.relative_to.should == :another_view
|
261
|
+
@constraint.attribute.should == [:width, :height]
|
262
|
+
@constraint.attribute2.should == [:width, :height]
|
263
|
+
end
|
264
|
+
it 'should support `max_size.equals(:another_view).plus(w: 10, h: 10)`' do
|
265
|
+
@layout.context(UIView.new) do
|
266
|
+
@layout.constraints do
|
267
|
+
@constraint = @layout.max_size.equals(:another_view).plus(w: 10, h: 10)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
@constraint.constant.should == [10, 10]
|
272
|
+
@constraint.relationship.should == :lte
|
273
|
+
@constraint.multiplier.should == [1, 1]
|
274
|
+
@constraint.relative_to.should == :another_view
|
275
|
+
@constraint.attribute.should == [:width, :height]
|
276
|
+
@constraint.attribute2.should == [:width, :height]
|
277
|
+
end
|
278
|
+
it 'should support `size.equals(:another_view).times(2).plus(10)`' do
|
279
|
+
@layout.context(UIView.new) do
|
280
|
+
@layout.constraints do
|
281
|
+
@constraint = @layout.size.equals(:another_view).times(2).plus(10)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
@constraint.constant.should == [10, 10]
|
286
|
+
@constraint.relationship.should == :equal
|
287
|
+
@constraint.multiplier.should == [2, 2]
|
288
|
+
@constraint.relative_to.should == :another_view
|
289
|
+
@constraint.attribute.should == [:width, :height]
|
290
|
+
@constraint.attribute2.should == [:width, :height]
|
291
|
+
end
|
292
|
+
it 'should support `min_size.equals(:another_view).times(2).plus(10)`' do
|
293
|
+
@layout.context(UIView.new) do
|
294
|
+
@layout.constraints do
|
295
|
+
@constraint = @layout.min_size.equals(:another_view).times(2).plus(10)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
@constraint.constant.should == [10, 10]
|
300
|
+
@constraint.relationship.should == :gte
|
301
|
+
@constraint.multiplier.should == [2, 2]
|
302
|
+
@constraint.relative_to.should == :another_view
|
303
|
+
@constraint.attribute.should == [:width, :height]
|
304
|
+
@constraint.attribute2.should == [:width, :height]
|
305
|
+
end
|
306
|
+
it 'should support `max_size.equals(:another_view).times(2).plus(10)`' do
|
307
|
+
@layout.context(UIView.new) do
|
308
|
+
@layout.constraints do
|
309
|
+
@constraint = @layout.max_size.equals(:another_view).times(2).plus(10)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
@constraint.constant.should == [10, 10]
|
314
|
+
@constraint.relationship.should == :lte
|
315
|
+
@constraint.multiplier.should == [2, 2]
|
316
|
+
@constraint.relative_to.should == :another_view
|
317
|
+
@constraint.attribute.should == [:width, :height]
|
318
|
+
@constraint.attribute2.should == [:width, :height]
|
319
|
+
end
|
320
|
+
it 'should support `max_size("50%")`' do
|
321
|
+
@layout.context(@parent_view) do
|
322
|
+
@view = @layout.add(UIView.new) do
|
323
|
+
@layout.constraints do
|
324
|
+
@constraint = @layout.max_size('50%')
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
@constraint.constant.should == [0, 0]
|
330
|
+
@constraint.relationship.should == :lte
|
331
|
+
@constraint.multiplier.should == [0.5, 0.5]
|
332
|
+
@constraint.relative_to.should == nil
|
333
|
+
@constraint.attribute.should == [:width, :height]
|
334
|
+
@constraint.attribute2.should == [:width, :height]
|
335
|
+
end
|
336
|
+
it 'should support `max_size("50% + 1").of(:another_view)`' do
|
337
|
+
@layout.context(@parent_view) do
|
338
|
+
@view = @layout.add(UIView.new) do
|
339
|
+
@layout.constraints do
|
340
|
+
@constraint = @layout.max_size('50% + 1').of(:another_view)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
@constraint.constant.should == [1, 1]
|
346
|
+
@constraint.relationship.should == :lte
|
347
|
+
@constraint.multiplier.should == [0.5, 0.5]
|
348
|
+
@constraint.relative_to.should == :another_view
|
349
|
+
@constraint.attribute.should == [:width, :height]
|
350
|
+
@constraint.attribute2.should == [:width, :height]
|
351
|
+
end
|
352
|
+
it 'should support `size.equals(:another_view).times([2, 2]).plus(10)`' do
|
353
|
+
@layout.context(UIView.new) do
|
354
|
+
@layout.constraints do
|
355
|
+
@constraint = @layout.size.equals(:another_view).times([2, 2]).plus(10)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
@constraint.constant.should == [10, 10]
|
360
|
+
@constraint.relationship.should == :equal
|
361
|
+
@constraint.multiplier.should == [2, 2]
|
362
|
+
@constraint.relative_to.should == :another_view
|
363
|
+
@constraint.attribute.should == [:width, :height]
|
364
|
+
@constraint.attribute2.should == [:width, :height]
|
365
|
+
end
|
366
|
+
it 'should support `min_size.equals(:another_view).times([2, 2]).plus(10)`' do
|
367
|
+
@layout.context(UIView.new) do
|
368
|
+
@layout.constraints do
|
369
|
+
@constraint = @layout.min_size.equals(:another_view).times([2, 2]).plus(10)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
@constraint.constant.should == [10, 10]
|
374
|
+
@constraint.relationship.should == :gte
|
375
|
+
@constraint.multiplier.should == [2, 2]
|
376
|
+
@constraint.relative_to.should == :another_view
|
377
|
+
@constraint.attribute.should == [:width, :height]
|
378
|
+
@constraint.attribute2.should == [:width, :height]
|
379
|
+
end
|
380
|
+
it 'should support `max_size.equals(:another_view).times(w: 2, h: 2).plus(10)`' do
|
381
|
+
@layout.context(UIView.new) do
|
382
|
+
@layout.constraints do
|
383
|
+
@constraint = @layout.max_size.equals(:another_view).times(w: 2, h: 2).plus(10)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
@constraint.constant.should == [10, 10]
|
388
|
+
@constraint.relationship.should == :lte
|
389
|
+
@constraint.multiplier.should == [2, 2]
|
390
|
+
@constraint.relative_to.should == :another_view
|
391
|
+
@constraint.attribute.should == [:width, :height]
|
392
|
+
@constraint.attribute2.should == [:width, :height]
|
393
|
+
end
|
394
|
+
it 'should support `size.equals(:another_view).times(2).times([3, 4])`' do
|
395
|
+
@layout.context(UIView.new) do
|
396
|
+
@layout.constraints do
|
397
|
+
@constraint = @layout.size.equals(:another_view).times(2).times([3, 4])
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
@constraint.constant.should == [0, 0]
|
402
|
+
@constraint.relationship.should == :equal
|
403
|
+
@constraint.multiplier.should == [6, 8]
|
404
|
+
@constraint.relative_to.should == :another_view
|
405
|
+
@constraint.attribute.should == [:width, :height]
|
406
|
+
@constraint.attribute2.should == [:width, :height]
|
407
|
+
end
|
408
|
+
it 'should support `size.equals(:another_view).divided_by(2)`' do
|
409
|
+
@layout.context(UIView.new) do
|
410
|
+
@layout.constraints do
|
411
|
+
@constraint = @layout.size.equals(:another_view).divided_by(2)
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
@constraint.constant.should == [0, 0]
|
416
|
+
@constraint.relationship.should == :equal
|
417
|
+
@constraint.multiplier.should == [0.5, 0.5]
|
418
|
+
@constraint.relative_to.should == :another_view
|
419
|
+
@constraint.attribute.should == [:width, :height]
|
420
|
+
@constraint.attribute2.should == [:width, :height]
|
421
|
+
end
|
422
|
+
|
423
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
describe 'Constraints - view_lookup method' do
|
2
|
+
|
3
|
+
before do
|
4
|
+
@layout = MK::Layout.new
|
5
|
+
@constraint = nil
|
6
|
+
@view = UIView.new
|
7
|
+
@parent_view = UIView.new
|
8
|
+
@parent_view.addSubview(@view)
|
9
|
+
@another_view = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should support :superview' do
|
13
|
+
@layout.context(@parent_view) do
|
14
|
+
@layout.context(@view) do
|
15
|
+
@layout.constraints do
|
16
|
+
@constraint = @layout.left.equals(:superview).plus(10)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
@constraint.constant.should == 10
|
22
|
+
@constraint.relationship.should == :equal
|
23
|
+
@constraint.multiplier.should == 1
|
24
|
+
@constraint.relative_to.should == :superview
|
25
|
+
@constraint.attribute.should == :left
|
26
|
+
@constraint.attribute2.should == :left
|
27
|
+
|
28
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
29
|
+
resolved.length.should == 1
|
30
|
+
resolved[0].firstItem.should.be.kind_of(UIView)
|
31
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
32
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
33
|
+
resolved[0].secondItem.should == @parent_view
|
34
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
35
|
+
resolved[0].multiplier.should == 1
|
36
|
+
resolved[0].constant.should == 10
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should support :another_view' do
|
40
|
+
@layout.context(@parent_view) do
|
41
|
+
@layout.context(@view) do
|
42
|
+
@layout.constraints do
|
43
|
+
@constraint = @layout.left.equals(:another_view).plus(10)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
47
|
+
end
|
48
|
+
|
49
|
+
@constraint.constant.should == 10
|
50
|
+
@constraint.relationship.should == :equal
|
51
|
+
@constraint.multiplier.should == 1
|
52
|
+
@constraint.relative_to.should == :another_view
|
53
|
+
@constraint.attribute.should == :left
|
54
|
+
@constraint.attribute2.should == :left
|
55
|
+
|
56
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
57
|
+
resolved.length.should == 1
|
58
|
+
resolved[0].firstItem.should.be.kind_of(UIView)
|
59
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
60
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
61
|
+
resolved[0].secondItem.should == @another_view
|
62
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
63
|
+
resolved[0].multiplier.should == 1
|
64
|
+
resolved[0].constant.should == 10
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should support @another_view' do
|
68
|
+
@layout.context(@parent_view) do
|
69
|
+
@another_view = @layout.add UIView.alloc.initWithFrame([[1, 1], [2, 2]]), :another_view
|
70
|
+
@layout.context(@view) do
|
71
|
+
@layout.constraints do
|
72
|
+
@constraint = @layout.left.equals(@another_view).plus(10)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
@constraint.constant.should == 10
|
78
|
+
@constraint.relationship.should == :equal
|
79
|
+
@constraint.multiplier.should == 1
|
80
|
+
@constraint.relative_to.should == @another_view
|
81
|
+
@constraint.attribute.should == :left
|
82
|
+
@constraint.attribute2.should == :left
|
83
|
+
|
84
|
+
resolved = @constraint.resolve_all(@layout, @view)
|
85
|
+
resolved.length.should == 1
|
86
|
+
resolved[0].firstItem.should.be.kind_of(UIView)
|
87
|
+
resolved[0].firstAttribute.should == NSLayoutAttributeLeft
|
88
|
+
resolved[0].relation.should == NSLayoutRelationEqual
|
89
|
+
resolved[0].secondItem.should == @another_view
|
90
|
+
resolved[0].secondAttribute.should == NSLayoutAttributeLeft
|
91
|
+
resolved[0].multiplier.should == 1
|
92
|
+
resolved[0].constant.should == 10
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|