motion-kit 1.0.3 → 1.1.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.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/lib/motion-kit-ios/helpers/uiview_helpers.rb +10 -2
- data/lib/motion-kit/helpers/tree_layout.rb +2 -2
- data/lib/motion-kit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f25a8221661392838e777d1bc48bed110fd9857
|
4
|
+
data.tar.gz: 17f939c142298c5b5744bf688c1e93dab9f46ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
data/lib/motion-kit/version.rb
CHANGED