motion-kit 0.14.2 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4aef617ad6abab23df20a00836c0189ae5f7d962
4
- data.tar.gz: 5795cf1d58ea7c33a713b0f964dd812bdccc57fc
3
+ metadata.gz: eedf449e832f4fd4ba85cd38676396f3cba7bc85
4
+ data.tar.gz: 5214242fb4dd14ace924f3090a6dd453a8b3b821
5
5
  SHA512:
6
- metadata.gz: 99f22fcf82ab5a2dda61e570725cd0450455512ad99366595d4119cf39c94ed6b59981e5b7adc9579568116a3fc900b2feaf3dd72f3566a88ad857064ada680b
7
- data.tar.gz: 349f157dac34e5b4aa2ef0ce58776a75b6b931d0668de50f1e597747051510af00f15cfe1b846fec04734c5350f4e46047890de6f59b89e327708f5acb525026
6
+ metadata.gz: 42a2537b79984c792ce5bb117f2b739406418326a8e41e6539071524ae44fb14ea7ad4fd5608c3437f20ae15680fca1c192b68d2bcacb296bae3716469ec219c
7
+ data.tar.gz: d8fab44502565556b68c92dc1b0640fce0415b04a6e7281472d71cb211a57818d046a604a50d22bd2187ec8521cc05cc26fad946ef9135105c1c0c3dadcd4fd2
data/README.md CHANGED
@@ -824,12 +824,11 @@ end
824
824
  Instead, you should retain the constraint and make changes to it directly:
825
825
 
826
826
  ```ruby
827
- initial do
828
- constraints do
829
- @label_left_constraint = left 10
830
- end
827
+ constraints do
828
+ @label_left_constraint = left 10
831
829
  end
832
830
 
831
+ # reapply blocks are called via the Layout#reapply! method.
833
832
  reapply do
834
833
  portrait do
835
834
  @label_left_constraint.equals 10
@@ -893,29 +892,34 @@ add UIView, :container do
893
892
  end
894
893
  ```
895
894
 
896
- ### Update views via 'initial', 'reapply', and 'deferred'
895
+ ### Update views via 'always', 'reapply', and 'deferred'
896
+
897
+ In your style methods, you can register blocks that get called during
898
+ "restyling", which is usually triggered by a rotation change (though, if you're
899
+ making good use of autoresizingMask or AutoLayout constraints, you should not
900
+ have to do this, right?).
897
901
 
898
- If you call 'layout.reapply!', your style methods will be called again (but
899
- NOT the `layout` method). You very well might want to control what methods get
900
- called on later invocations, or only on the *initial* layout.
902
+ It's important to note that the style methods are not actually called again. The
903
+ blocks are retained on the view, along with the "context", and calling
904
+ `reapply!` calls all those blocks with the context set as you'd expect.
901
905
 
902
- This is more for being able to initialize values, or to handle orientation, than
903
- anything else. There is not much performance increase/decrease if you just
904
- reapply styles every time, but you might not want to have your frame or colors
905
- reset, if you've done some animation.
906
+ If you have code that you want to be called during initialization *and* during
907
+ reapply, use the `always` helper:
906
908
 
907
909
  ```ruby
908
910
  def login_button_style
909
- # only once, when the `layout` is created
910
- initial do
911
- end
911
+ # only once, when the layout is first being created
912
+ title 'initial title'
912
913
 
913
- # on later invocations
914
+ # only during reapply
914
915
  reapply do
916
+ title 'something happened!'
915
917
  end
916
918
 
917
- # style every time
918
- title 'Press Me'
919
+ # applied every time
920
+ always do
921
+ title 'You win!'
922
+ end
919
923
  end
920
924
  ```
921
925
 
@@ -24,10 +24,10 @@ module MotionKit
24
24
  return intrinsic_size(view).send(dimension) # :left or :right
25
25
  elsif amount.is_a?(String) && amount.include?('%')
26
26
  if not full_view
27
- if view.is_a?(MotionKit.base_view_class)
28
- full_view = view.superview
29
- elsif view.is_a?(CALayer)
27
+ if view.is_a?(CALayer)
30
28
  full_view = view.superlayer
29
+ elsif view.respond_to?(:superview)
30
+ full_view = view.superview
31
31
  end
32
32
 
33
33
  if not full_view
@@ -127,7 +127,8 @@ module MotionKit
127
127
  # after a call to Layout#layout.
128
128
  def deferred(context=nil, &block)
129
129
  context ||= @context
130
- return parent_layout.add_deferred_block(context, &block)
130
+ parent_layout.add_deferred_block(context, &block)
131
+ return self
131
132
  end
132
133
 
133
134
  # Only intended for private use
@@ -140,8 +141,6 @@ module MotionKit
140
141
  raise ArgumentError.new('Block required') unless block
141
142
 
142
143
  self.deferred_blocks << [context, block]
143
-
144
- self
145
144
  end
146
145
 
147
146
  # Only intended for private use
@@ -60,6 +60,7 @@ module MotionKit
60
60
  def initialize(args={})
61
61
  super
62
62
  @child_layouts = []
63
+ @reapply_blocks = []
63
64
  @elements = {}
64
65
  end
65
66
 
@@ -138,12 +139,7 @@ module MotionKit
138
139
  def reapply!
139
140
  root ||= self.view
140
141
  @layout_state = :reapply
141
-
142
- @elements.each do |element_id, elements|
143
- elements.each do |element|
144
- style_and_context(element, element_id)
145
- end
146
- end
142
+ run_reapply_blocks
147
143
 
148
144
  @child_layouts.each do |child_layout|
149
145
  child_layout.reapply!
@@ -158,22 +154,50 @@ module MotionKit
158
154
  @layout_state == :reapply
159
155
  end
160
156
 
161
- # Calls the style method of all objects in the view hierarchy
157
+ # Only intended for private use
158
+ def reapply_blocks
159
+ @reapply_blocks ||= []
160
+ end
161
+
162
+ # Blocks passed to `reapply` are only run when `reapply!` is called.
162
163
  def reapply(&block)
163
164
  raise ArgumentError.new('Block required') unless block
165
+ raise InvalidDeferredError.new('reapply must be run inside of a context') unless @context
164
166
 
165
167
  if reapply?
166
168
  yield
167
169
  end
170
+
171
+ block = block.weak!
172
+ parent_layout.reapply_blocks << [@context, block]
168
173
  return self
169
174
  end
170
175
 
176
+ # Only intended for private use
177
+ def run_reapply_blocks
178
+ self.reapply_blocks.each do |target, block|
179
+ context(target, &block)
180
+ end
181
+ end
182
+
171
183
  def initial?
172
184
  @layout_state == :initial
173
185
  end
174
186
 
187
+ def always(&block)
188
+ raise ArgumentError.new('Block required') unless block
189
+
190
+ if initial?
191
+ yield
192
+ end
193
+ reapply(&block)
194
+
195
+ return self
196
+ end
197
+
175
198
  def initial(&block)
176
199
  raise ArgumentError.new('Block required') unless block
200
+ puts('this method is no longer necessary! all code that *isn\'t in a `reapply` block is now only applied during initial setup.')
177
201
 
178
202
  if initial?
179
203
  yield
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '0.14.2'
2
+ VERSION = '0.15.0'
3
3
  end
@@ -24,6 +24,14 @@ describe 'Child Layouts' do
24
24
  @layout.get(:child_image).get(:image).should.be.kind_of(UIImageView)
25
25
  end
26
26
 
27
+ it 'should have initial styles on :label' do
28
+ @layout.get(:label).text.should == 'root foo'
29
+ end
30
+
31
+ it 'should apply tag on :label' do
32
+ @layout.get(:label).tag.should == 100
33
+ end
34
+
27
35
  describe 'Calling reapply! on parent layout' do
28
36
 
29
37
  before do
@@ -34,6 +42,10 @@ describe 'Child Layouts' do
34
42
  @layout.get(:label).text.should == 'root reapplied'
35
43
  end
36
44
 
45
+ it 'should apply tag on :label' do
46
+ @layout.get(:label).tag.should == 100
47
+ end
48
+
37
49
  it 'should reapply :label on child layout' do
38
50
  @layout.child_layouts[0].get(:label).text.should == 'reapplied'
39
51
  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.14.2
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-24 00:00:00.000000000 Z
12
+ date: 2014-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbt