motion-kit 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0809f323d3149b38020e0d4dbeef458c83bf936f
4
- data.tar.gz: c610c4e21ad2de907bce51b884092266689cd340
3
+ metadata.gz: 7f25a8221661392838e777d1bc48bed110fd9857
4
+ data.tar.gz: 17f939c142298c5b5744bf688c1e93dab9f46ab9
5
5
  SHA512:
6
- metadata.gz: d7a30089db1ea834657578e3ad013f8f9821151d326dc12fd878ec2b8fe44535eae0c7bacb994dee16abc68736a344212e23af49d33a2110f9d66da5d2357a94
7
- data.tar.gz: 01fd1e8d1bd85bfca638bc339ae74f79868bbd26c2e09bb86831801b8039c20b611c4cf3bc736477dca66458963909c5473d5a424fc64d0a2aef2f1f9b7181d6
6
+ metadata.gz: b8f8534aaad7966740767eace569905f5213feacdfec9756b199014acdefe7802eddf11d101bc58f4f821452a8dd49ea518c98cce6ea99e094a22096d63e3f48
7
+ data.tar.gz: fc72309ba61213afd1040a94e8d392b4057ff64f8502128fe8165908f2a50fe93c91ffa55072802b8c1320c5d5799a6a7c05bca131a0ee7f5fc65d0486cc8a09
data/README.md CHANGED
@@ -203,6 +203,31 @@ end
203
203
  ```
204
204
 
205
205
 
206
+ ### Dynamically adding views
207
+
208
+ In MotionKit, it is easy to add views on the fly using the same API as used during layout.
209
+ ```ruby
210
+ def add_button style, button_title
211
+
212
+ context get(:inputs) do #Two very useful methods for accessing/modifying previously added views
213
+ add UIButton, :dynamic_button do
214
+ title button_title
215
+ constraints do # if using autolayout
216
+ ...
217
+ end
218
+ end
219
+ end
220
+ end
221
+ ```
222
+
223
+ During layout, z-order is determined by the sequence in which views are added to the hierarchy. You can control this dynamically by supplying :behind, :in_front_of, or :z_index options
224
+ ```ruby
225
+ add UIImageView, :highlight_square, behind: get(:dynamic_button)
226
+ add UIImageView, :x_marks_the_spot, in_front_of: @selected_label
227
+ add UILabel, :subterranian_marker, z_index: 4 #becomes the 4th view in the subview hierarchy
228
+ ```
229
+
230
+
206
231
  ### Styles are compiled, simple, and clean
207
232
 
208
233
  In MotionKit, when you define a method that has the same name as a view
@@ -11,8 +11,16 @@ module MotionKit
11
11
  view_class.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
12
12
  end
13
13
 
14
- def add_child(subview)
15
- target.addSubview(subview)
14
+ def add_child(subview, options={})
15
+ if (sibling = options[:behind])
16
+ target.insertSubview(subview, belowSubview: sibling)
17
+ elsif (sibling = options[:in_front_of])
18
+ target.insertSubview(subview, aboveSubview: sibling)
19
+ elsif (z_index = options[:z_index])
20
+ target.insertSubview(subview, atIndex: z_index)
21
+ else
22
+ target.addSubview(subview)
23
+ end
16
24
  end
17
25
 
18
26
  def remove_child(subview)
@@ -215,7 +215,7 @@ module MotionKit
215
215
  # If there is no context, a default root view can be created if that has
216
216
  # been enabled (e.g. within the `layout` method). The block is run in the
217
217
  # context of the new view.
218
- def add(element, element_id=nil, &block)
218
+ def add(element, element_id=nil, options={}, &block)
219
219
  # make sure we have a target - raises NoContextError if none exists
220
220
  self.target
221
221
 
@@ -226,7 +226,7 @@ module MotionKit
226
226
  # We want to be sure that the element has a supeview or superlayer before
227
227
  # the style method is called.
228
228
  element = initialize_element(element, element_id)
229
- self.apply(:add_child, element)
229
+ self.apply(:add_child, element, options)
230
230
  style_and_context(element, element_id, &block)
231
231
 
232
232
  element
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  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: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray