sugarcube 0.18.11 → 0.18.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -774,20 +774,29 @@ view.slide(:left, 20) {
774
774
  }
775
775
  ```
776
776
 
777
- But isn't that ugly! Use an animation chain!
777
+ Those be some gnarly callbacks. You can write this as a chain, but we need to
778
+ tell the `slide` method to go ahead and run immediately (don't use an
779
+ animation). When you create an animation chain, the block you pass to each
780
+ iteration is the block that gets passed to `UIView##animateWithDuration(...)`.
781
+ If you try and run animations *within* that block they will not get queued up
782
+ properly.
783
+
784
+ The easiest way to handle this:
785
+
786
+ 1) don't use SugarCube animation methods, e.g. assign the frame manually (yeah, right!)
787
+ 2) use the `duration: 0` option, which runs the animation without setting calling
788
+ `animateWithDuration()`.
789
+ 3) For clarity (and some future-proofing, in case any of this rigamarole changes
790
+ in the future), you can use `chain: true`.
778
791
 
779
792
  ```ruby
780
793
  UIView.animation_chain {
781
- view.slide(:left, 20)
782
- }.and_then {
783
- view.slide(:up, 20)
784
- }.and_then {
785
- view.slide(:right, 20)
794
+ view.slide(:left, duration:0)
786
795
  }.and_then {
787
- view.slide(:down, 20)
796
+ view.slide(:up, chain:true) # sets duration:0, delay:0
788
797
  }.and_then {
789
- view.fade_out
790
- }.start
798
+ view.fade_out # in case you were wondering, the very LAST animation CAN be
799
+ }.start # called normally.
791
800
  ```
792
801
 
793
802
  Chains can also be written like this:
@@ -986,7 +995,7 @@ text_view.on :editing_did_end do
986
995
  end
987
996
 
988
997
  # later... like in `viewWillDisappear`. I'll use the alternative aliases here
989
- text_view.off :change, :end, :begin
998
+ text_view.off :change, :end, :begin
990
999
  ```
991
1000
 
992
1001
  UIBarButtonItem
data/app/app_delegate.rb CHANGED
@@ -1,5 +1,7 @@
1
+ include SugarCube::Adjust
1
2
  include SugarCube::CoreGraphics
2
3
 
4
+
3
5
  class AppDelegate
4
6
  def application(application, didFinishLaunchingWithOptions:launchOptions)
5
7
  return true if RUBYMOTION_ENV == 'test'
@@ -30,6 +30,15 @@ class UIView
30
30
  duration = options[:duration] || 0.3
31
31
  end
32
32
 
33
+ delay = options[:delay] || 0
34
+
35
+ # chain: true is used inside animation_chain blocks to prevent some weird
36
+ # animation errors (nested animations do not delay/queue as you'd expect)
37
+ if options[:chain]
38
+ duration = 0
39
+ delay = 0
40
+ end
41
+
33
42
  after_animations = options[:after]
34
43
  if after_animations
35
44
  if after_animations.arity == 0
@@ -41,7 +50,6 @@ class UIView
41
50
  after_adjusted = nil
42
51
  end
43
52
 
44
- delay = options[:delay] || 0
45
53
  if duration == 0 && delay == 0
46
54
  animations.call
47
55
  after_adjusted.call(true) if after_adjusted
@@ -229,12 +237,14 @@ class UIView
229
237
  }
230
238
  end
231
239
 
232
- def slide(direction, options={}, &after)
240
+ def slide(direction, options={}, more_options=nil, &after)
233
241
  if options.is_a? Numeric
234
- options = {size: options}
242
+ size = options
243
+ options = more_options || {}
244
+ else
245
+ size = options[:size]
235
246
  end
236
247
 
237
- size = options[:size]
238
248
  case direction
239
249
  when :left
240
250
  size ||= self.bounds.size.width
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.18.11'
2
+ Version = '0.18.12'
3
3
  end
@@ -11,18 +11,29 @@ describe "SugarCube::AnimationChain" do
11
11
  @variable_b = nil
12
12
  UIView.animation_chain(duration:0.1){
13
13
  @variable_a = 'a'
14
+ f = controller.view.frame
15
+ f.origin.x -= 20
16
+ controller.view.frame = f
14
17
  }.and_then(duration: 0.1){
15
18
  @variable_b = 'b'
19
+ f = controller.view.frame
20
+ f.origin.x += 20
21
+ controller.view.frame = f
16
22
  }.start
23
+
17
24
  SugarCube::AnimationChain.chains.length.should == 1
18
25
 
19
- wait 0.15 {
26
+ wait 0.05 {
20
27
  @variable_a.should == 'a'
21
28
  @variable_b.should == nil
29
+ SugarCube::AnimationChain.chains.length.should == 1
22
30
  }
23
- wait 0.3 {
31
+ wait 0.15 {
24
32
  @variable_a.should == 'a'
25
33
  @variable_b.should == 'b'
34
+ SugarCube::AnimationChain.chains.length.should == 1
35
+ }
36
+ wait 0.25 {
26
37
  SugarCube::AnimationChain.chains.length.should == 0
27
38
  }
28
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.11
4
+ version: 0.18.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: