motion-kit 0.13.0 → 0.14.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 +45 -2
- data/lib/motion-kit-cocoa/cocoa_util.rb +74 -0
- data/lib/motion-kit-cocoa/constraints/constraint.rb +0 -2
- data/lib/motion-kit-cocoa/constraints/constraints_helpers.rb +28 -28
- data/lib/motion-kit-cocoa/constraints/constraints_target.rb +8 -0
- data/lib/motion-kit/helpers/base_layout.rb +3 -0
- data/lib/motion-kit/helpers/tree_layout.rb +106 -0
- data/lib/motion-kit/util.rb +5 -1
- data/lib/motion-kit/version.rb +1 -1
- data/spec/ios/nearest_spec.rb +80 -0
- data/spec/ios/prev_next_spec.rb +153 -0
- metadata +6 -2
- data/lib/motion-kit-cocoa/constraints/constraint_placeholder.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1de6fcc1bebb1578ad6110741b7d5edb084c307
|
4
|
+
data.tar.gz: 2b21fc0a39cae00452ed4ef9fd709cfea10d51e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac2fd44e427fa6c0d91706b0243e4902ad66a402a1974e655e2e1cd2c6f882f083426f49ab8334d771748bb3e726d07eb25f3cd20a2b534bb8bc651dbfda1cd2
|
7
|
+
data.tar.gz: bc6d0928ca21a6af0b7876b882c5b704b40a41e2f04e8e1784835cd3e100deade600360268240a367aa2f7b9a05d8cd3f9d8817d65a3ccfc942576da620471a4
|
data/README.md
CHANGED
@@ -109,7 +109,7 @@ class SimpleLayout < MotionKit::Layout
|
|
109
109
|
|
110
110
|
# note: there are better ways to set the center, see the frame helpers below
|
111
111
|
center [CGRectGetMidX(superview.bounds), CGRectGetMidY(superview.bounds)]
|
112
|
-
text_alignment
|
112
|
+
text_alignment NSTextAlignmentCenter
|
113
113
|
text_color UIColor.whiteColor
|
114
114
|
|
115
115
|
# if you prefer to use shorthands from another gem, you certainly can!
|
@@ -706,6 +706,47 @@ add UIView, :bar do
|
|
706
706
|
end
|
707
707
|
```
|
708
708
|
|
709
|
+
One common use case is to use a child layout to create many instances of the
|
710
|
+
same layout that repeat, for instance a "row" of content. In this case you will
|
711
|
+
probably have many views with the same id, and you will not know the index of
|
712
|
+
the container view that you want to add constraints to. In this situation, use
|
713
|
+
the `nearest`, `previous` or `next` method to find a container, sibling, or
|
714
|
+
child view.
|
715
|
+
|
716
|
+
`previous` and `next` are easy; they just search for a sibling view. No
|
717
|
+
superviews or subviews are searched.
|
718
|
+
|
719
|
+
`nearest` will search child views, siblings, and superviews, in that order. The
|
720
|
+
"distance" is calculated as such:
|
721
|
+
|
722
|
+
- the current view
|
723
|
+
- subviews
|
724
|
+
- siblings
|
725
|
+
- superview
|
726
|
+
- superview's siblings, or a child of the sibling (depth-first search)
|
727
|
+
- continue up the tree
|
728
|
+
|
729
|
+
See the AutoLayout sample app for an example of this usage.
|
730
|
+
|
731
|
+
```ruby
|
732
|
+
items.each do |item|
|
733
|
+
add UIView, :row do
|
734
|
+
add UIImageView, :avatar
|
735
|
+
add UILabel, :title
|
736
|
+
end
|
737
|
+
end
|
738
|
+
|
739
|
+
def title_style
|
740
|
+
constraints do
|
741
|
+
# center the view vertically
|
742
|
+
center.equals(nearest(:row))
|
743
|
+
# and place it to the right of the :avatar
|
744
|
+
left.equals(nearest(:avatar), :right).plus(8)
|
745
|
+
right.equals(nearest(:row)).minus(8)
|
746
|
+
end
|
747
|
+
end
|
748
|
+
```
|
749
|
+
|
709
750
|
One pain point in working with constraints is determining when to add them to
|
710
751
|
your views. We tried really hard to figure out a way to automatically add them,
|
711
752
|
but it's just an untenable problem (Teacup suffers from a similar conundrum).
|
@@ -731,8 +772,10 @@ class MainLayout < MK::Layout
|
|
731
772
|
end
|
732
773
|
end
|
733
774
|
|
734
|
-
#
|
775
|
+
# You should call this method from `UIViewController#updateViewConstraints`
|
776
|
+
# and pass in your controller
|
735
777
|
def add_constraints(controller)
|
778
|
+
# guard against adding these constraints more than once
|
736
779
|
unless @layout_constraints_added
|
737
780
|
@layout_constraints_added = true
|
738
781
|
constraints(:label) do
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module MotionKit
|
2
|
+
module_function
|
3
|
+
|
4
|
+
def siblings(view)
|
5
|
+
case view
|
6
|
+
when CALayer
|
7
|
+
view.superlayer ? view.superlayer.sublayers : []
|
8
|
+
else
|
9
|
+
view.superview ? view.superview.subviews : []
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def children(view)
|
14
|
+
case view
|
15
|
+
when CALayer
|
16
|
+
view.sublayers
|
17
|
+
else
|
18
|
+
view.subviews
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parent(view)
|
23
|
+
case view
|
24
|
+
when CALayer
|
25
|
+
view.superlayer
|
26
|
+
else
|
27
|
+
view.superview
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# - check view
|
32
|
+
# - check subviews (unless 'skip' is provided)
|
33
|
+
# - check siblings (skipping 'view')
|
34
|
+
# - go up to parent and repeat, skipping children
|
35
|
+
def nearest(view, skip=nil, &test)
|
36
|
+
return nil if view.nil?
|
37
|
+
|
38
|
+
if test.call(view)
|
39
|
+
return view
|
40
|
+
end
|
41
|
+
|
42
|
+
children = MotionKit.children(view)
|
43
|
+
siblings = MotionKit.siblings(view)
|
44
|
+
parent = MotionKit.parent(view)
|
45
|
+
|
46
|
+
found = nil
|
47
|
+
|
48
|
+
# only check the children starting at the "root", e.g. nearest hasn't been
|
49
|
+
# called recursively.
|
50
|
+
if !skip || skip == parent
|
51
|
+
children.each do |child|
|
52
|
+
found = nearest(child, &test)
|
53
|
+
break if found
|
54
|
+
end
|
55
|
+
return found if found
|
56
|
+
end
|
57
|
+
|
58
|
+
# siblings are closer than parents
|
59
|
+
# passing 'parent' means only check self and children
|
60
|
+
unless skip == parent
|
61
|
+
siblings.each do |sibling|
|
62
|
+
found = (sibling != view && nearest(sibling, parent, &test))
|
63
|
+
break if found
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if found
|
68
|
+
found
|
69
|
+
elsif skip != parent
|
70
|
+
nearest(parent, true, &test)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -303,8 +303,6 @@ module MotionKit
|
|
303
303
|
def view_lookup(layout, view, target)
|
304
304
|
if ! target || target.is_a?(MotionKit.base_view_class)
|
305
305
|
target
|
306
|
-
elsif target.is_a?(ConstraintPlaceholder)
|
307
|
-
target.resolve(layout)
|
308
306
|
elsif target == :self
|
309
307
|
view
|
310
308
|
elsif target == :superview
|
@@ -10,32 +10,20 @@ module MotionKit
|
|
10
10
|
target
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
ConstraintPlaceholder.new(:first, name)
|
15
|
-
end
|
16
|
-
|
17
|
-
def last(name)
|
18
|
-
ConstraintPlaceholder.new(:last, name)
|
19
|
-
end
|
20
|
-
|
21
|
-
def nth(name, value)
|
22
|
-
ConstraintPlaceholder.new(:nth, name, value)
|
23
|
-
end
|
24
|
-
|
25
|
-
def x(value=nil, rel=nil)
|
13
|
+
def left(value=nil, rel=nil)
|
26
14
|
target_constraint(:left, rel, value)
|
27
15
|
end
|
28
|
-
alias left
|
16
|
+
alias x left
|
29
17
|
|
30
|
-
def
|
31
|
-
|
18
|
+
def min_left(value=nil)
|
19
|
+
left(value, :gte)
|
32
20
|
end
|
33
|
-
alias min_left
|
21
|
+
alias min_x min_left
|
34
22
|
|
35
|
-
def
|
36
|
-
|
23
|
+
def max_left(value=nil)
|
24
|
+
left(value, :lte)
|
37
25
|
end
|
38
|
-
alias max_left
|
26
|
+
alias max_x max_left
|
39
27
|
|
40
28
|
def leading(value=nil, rel=nil)
|
41
29
|
target_constraint(:leading, rel, value)
|
@@ -85,20 +73,20 @@ module MotionKit
|
|
85
73
|
trailing(value, :lte)
|
86
74
|
end
|
87
75
|
|
88
|
-
def
|
76
|
+
def top(value=nil, rel=nil)
|
89
77
|
target_constraint(:top, rel, value)
|
90
78
|
end
|
91
|
-
alias top
|
79
|
+
alias y top
|
92
80
|
|
93
|
-
def
|
94
|
-
|
81
|
+
def min_top(value=nil)
|
82
|
+
top(value, :gte)
|
95
83
|
end
|
96
|
-
alias min_top
|
84
|
+
alias min_y min_top
|
97
85
|
|
98
|
-
def
|
99
|
-
|
86
|
+
def max_top(value=nil)
|
87
|
+
top(value, :lte)
|
100
88
|
end
|
101
|
-
alias max_top
|
89
|
+
alias max_y max_top
|
102
90
|
|
103
91
|
def center_y(value=nil, rel=nil)
|
104
92
|
target_constraint(:center_y, rel, value)
|
@@ -238,6 +226,9 @@ module MotionKit
|
|
238
226
|
end
|
239
227
|
|
240
228
|
def above(view)
|
229
|
+
unless view
|
230
|
+
raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `above` constraint.")
|
231
|
+
end
|
241
232
|
constraint = Constraint.new(constraint_target.view, :bottom, :equal)
|
242
233
|
constraint.equals(view, :top)
|
243
234
|
|
@@ -246,6 +237,9 @@ module MotionKit
|
|
246
237
|
end
|
247
238
|
|
248
239
|
def below(view)
|
240
|
+
unless view
|
241
|
+
raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `below` constraint.")
|
242
|
+
end
|
249
243
|
constraint = Constraint.new(constraint_target.view, :top, :equal)
|
250
244
|
constraint.equals(view, :bottom)
|
251
245
|
|
@@ -254,6 +248,9 @@ module MotionKit
|
|
254
248
|
end
|
255
249
|
|
256
250
|
def before(view)
|
251
|
+
unless view
|
252
|
+
raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `before` constraint.")
|
253
|
+
end
|
257
254
|
constraint = Constraint.new(constraint_target.view, :right, :equal)
|
258
255
|
constraint.equals(view, :left)
|
259
256
|
|
@@ -263,6 +260,9 @@ module MotionKit
|
|
263
260
|
alias left_of before
|
264
261
|
|
265
262
|
def after(view)
|
263
|
+
unless view
|
264
|
+
raise ArgumentError.new("`#{view.inspect}` is not a valid target for making a `after` constraint.")
|
265
|
+
end
|
266
266
|
constraint = Constraint.new(constraint_target.view, :left, :equal)
|
267
267
|
constraint.equals(view, :right)
|
268
268
|
|
@@ -12,6 +12,14 @@ module MotionKit
|
|
12
12
|
@constraints.concat(constraints)
|
13
13
|
end
|
14
14
|
|
15
|
+
def ==(value)
|
16
|
+
if value.is_a?(ConstraintsTarget)
|
17
|
+
super
|
18
|
+
else
|
19
|
+
@view == value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
15
23
|
def apply_all_constraints(layout, target)
|
16
24
|
@constraints.map do |mk_constraint|
|
17
25
|
mk_constraint.resolve_all(layout, target).map do |constraint|
|
@@ -276,6 +276,7 @@ module MotionKit
|
|
276
276
|
objc_method_name, objc_method_args = objc_version(method_name, args)
|
277
277
|
ruby_method_name, ruby_method_args = ruby_version(method_name, args)
|
278
278
|
|
279
|
+
objc_setter = objc_method_name && MotionKit.setter(objc_method_name)
|
279
280
|
setter = MotionKit.setter(ruby_method_name)
|
280
281
|
assign = "#{ruby_method_name}="
|
281
282
|
|
@@ -290,6 +291,8 @@ module MotionKit
|
|
290
291
|
target.send(objc_method_name, *objc_method_args, &block)
|
291
292
|
elsif args.empty? && target.respond_to?(ruby_method_name)
|
292
293
|
target.send(ruby_method_name, *ruby_method_args, &block)
|
294
|
+
elsif objc_setter && target.respond_to?(objc_setter)
|
295
|
+
target.send(objc_setter, *objc_method_args, &block)
|
293
296
|
elsif target.respond_to?(setter)
|
294
297
|
target.send(setter, *args, &block)
|
295
298
|
elsif target.respond_to?(assign)
|
@@ -287,6 +287,112 @@ module MotionKit
|
|
287
287
|
element
|
288
288
|
end
|
289
289
|
|
290
|
+
# Search for a sibling: the next sibling that has the given id
|
291
|
+
def next(element_id)
|
292
|
+
self.next(element_id, from: target)
|
293
|
+
end
|
294
|
+
|
295
|
+
def next(element_id, from: from_view)
|
296
|
+
unless is_parent_layout?
|
297
|
+
return parent_layout.next(element_id, from: from_view)
|
298
|
+
end
|
299
|
+
search = @elements[element_id]
|
300
|
+
if search.nil? || search.empty?
|
301
|
+
return nil
|
302
|
+
end
|
303
|
+
|
304
|
+
if from_view.is_a?(NSString)
|
305
|
+
from_view = self.get(from_view)
|
306
|
+
end
|
307
|
+
|
308
|
+
if from_view.is_a?(ConstraintsTarget)
|
309
|
+
from_view = from_view.view
|
310
|
+
end
|
311
|
+
|
312
|
+
searching = false
|
313
|
+
found = nil
|
314
|
+
MotionKit.siblings(from_view).each do |sibling|
|
315
|
+
if sibling == from_view
|
316
|
+
searching = true
|
317
|
+
elsif searching && search.include?(sibling)
|
318
|
+
found = sibling
|
319
|
+
break
|
320
|
+
end
|
321
|
+
end
|
322
|
+
return found
|
323
|
+
end
|
324
|
+
|
325
|
+
# Search for a sibling: the previous sibling that has the given id
|
326
|
+
def prev(element_id)
|
327
|
+
prev(element_id, from: target)
|
328
|
+
end
|
329
|
+
|
330
|
+
def prev(element_id, from: from_view)
|
331
|
+
unless is_parent_layout?
|
332
|
+
return parent_layout.prev(element_id, from: from_view)
|
333
|
+
end
|
334
|
+
|
335
|
+
search = @elements[element_id]
|
336
|
+
if search.nil? || search.empty?
|
337
|
+
return nil
|
338
|
+
end
|
339
|
+
|
340
|
+
if from_view.is_a?(NSString)
|
341
|
+
from_view = self.get(from_view)
|
342
|
+
end
|
343
|
+
|
344
|
+
if from_view.is_a?(ConstraintsTarget)
|
345
|
+
from_view = from_view.view
|
346
|
+
end
|
347
|
+
|
348
|
+
found = nil
|
349
|
+
MotionKit.siblings(from_view).each do |sibling|
|
350
|
+
if sibling == from_view
|
351
|
+
break
|
352
|
+
elsif search.include?(sibling)
|
353
|
+
# keep searching; prev should find the *closest* matching view
|
354
|
+
found = sibling
|
355
|
+
end
|
356
|
+
end
|
357
|
+
return found
|
358
|
+
end
|
359
|
+
|
360
|
+
# This searches for the "nearest" view with a given id. First, all child
|
361
|
+
# views are checked. Then the search goes up to the parent view, and its
|
362
|
+
# child views are checked. This means *any* view that is in the parent
|
363
|
+
# view's hierarchy is considered closer than a view in a grandparent's
|
364
|
+
# hierarchy. This is a "depth-first" search, so any subview that contains
|
365
|
+
# a view with the element id
|
366
|
+
#
|
367
|
+
# A--B--C--D* Starting at D, E is closer than F, because D&E are siblings.
|
368
|
+
# \ \ \-E But F, G and H are closer than A or I, because they share a
|
369
|
+
# \ \-F--G closer *parent* (B). The logic is, "B" is a container, and
|
370
|
+
# \-I \-H all views in that container are in a closer family.
|
371
|
+
def nearest(element_id)
|
372
|
+
nearest(element_id, from: target)
|
373
|
+
end
|
374
|
+
|
375
|
+
def nearest(element_id, from: from_view)
|
376
|
+
unless is_parent_layout?
|
377
|
+
return parent_layout.nearest(element_id, from: from_view)
|
378
|
+
end
|
379
|
+
|
380
|
+
search = @elements[element_id]
|
381
|
+
if search.nil? || search.empty?
|
382
|
+
return nil
|
383
|
+
end
|
384
|
+
|
385
|
+
if from_view.is_a?(NSString)
|
386
|
+
from_view = self.get(from_view)
|
387
|
+
end
|
388
|
+
|
389
|
+
if from_view.is_a?(ConstraintsTarget)
|
390
|
+
from_view = from_view.view
|
391
|
+
end
|
392
|
+
|
393
|
+
MotionKit.nearest(from_view) { |test_view| search.include?(test_view) }
|
394
|
+
end
|
395
|
+
|
290
396
|
# Removes a view (or several with the same name) from the hierarchy
|
291
397
|
# and forgets it entirely. Returns the views that were removed.
|
292
398
|
def remove(element_id)
|
data/lib/motion-kit/util.rb
CHANGED
@@ -10,7 +10,11 @@ module MotionKit
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def setter(method_name)
|
13
|
-
"set#{method_name[0].capitalize}#{method_name[1..-1]}
|
13
|
+
setter = "set#{method_name[0].capitalize}#{method_name[1..-1]}"
|
14
|
+
unless setter.end_with?(':')
|
15
|
+
setter << ':'
|
16
|
+
end
|
17
|
+
setter
|
14
18
|
end
|
15
19
|
|
16
20
|
def appearance_class
|
data/lib/motion-kit/version.rb
CHANGED
@@ -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,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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin T.A. Gray
|
@@ -48,8 +48,8 @@ files:
|
|
48
48
|
- lib/motion-kit/util.rb
|
49
49
|
- lib/motion-kit/version.rb
|
50
50
|
- lib/motion-kit-cocoa/calculator/view_calculator.rb
|
51
|
+
- lib/motion-kit-cocoa/cocoa_util.rb
|
51
52
|
- lib/motion-kit-cocoa/constraints/constraint.rb
|
52
|
-
- lib/motion-kit-cocoa/constraints/constraint_placeholder.rb
|
53
53
|
- lib/motion-kit-cocoa/constraints/constraints_helpers.rb
|
54
54
|
- lib/motion-kit-cocoa/constraints/constraints_target.rb
|
55
55
|
- lib/motion-kit-cocoa/helpers/accessibility_compat.rb
|
@@ -116,10 +116,12 @@ files:
|
|
116
116
|
- spec/ios/memory_leak_spec.rb
|
117
117
|
- spec/ios/motion_kit_id_spec.rb
|
118
118
|
- spec/ios/motionkit_util_spec.rb
|
119
|
+
- spec/ios/nearest_spec.rb
|
119
120
|
- spec/ios/objc_selectors_spec.rb
|
120
121
|
- spec/ios/orientation_helper_specs.rb
|
121
122
|
- spec/ios/parent_layout_spec.rb
|
122
123
|
- spec/ios/parent_spec.rb
|
124
|
+
- spec/ios/prev_next_spec.rb
|
123
125
|
- spec/ios/reapply_frame.rb
|
124
126
|
- spec/ios/relative_layout.spec.rb
|
125
127
|
- spec/ios/remove_layout_spec.rb
|
@@ -200,10 +202,12 @@ test_files:
|
|
200
202
|
- spec/ios/memory_leak_spec.rb
|
201
203
|
- spec/ios/motion_kit_id_spec.rb
|
202
204
|
- spec/ios/motionkit_util_spec.rb
|
205
|
+
- spec/ios/nearest_spec.rb
|
203
206
|
- spec/ios/objc_selectors_spec.rb
|
204
207
|
- spec/ios/orientation_helper_specs.rb
|
205
208
|
- spec/ios/parent_layout_spec.rb
|
206
209
|
- spec/ios/parent_spec.rb
|
210
|
+
- spec/ios/prev_next_spec.rb
|
207
211
|
- spec/ios/reapply_frame.rb
|
208
212
|
- spec/ios/relative_layout.spec.rb
|
209
213
|
- spec/ios/remove_layout_spec.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module MotionKit
|
2
|
-
class ConstraintPlaceholder
|
3
|
-
|
4
|
-
def initialize(type, name, value=nil)
|
5
|
-
@type = type
|
6
|
-
@name = name
|
7
|
-
@value = value
|
8
|
-
end
|
9
|
-
|
10
|
-
def resolve(layout)
|
11
|
-
case @type
|
12
|
-
when :first
|
13
|
-
layout.get_view(@name)
|
14
|
-
when :last
|
15
|
-
layout.last_view(@name)
|
16
|
-
when :nth
|
17
|
-
layout.nth_view(@name, @value)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|