sugarcube 0.18.11 → 0.18.12
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.
- data/README.md +19 -10
- data/app/app_delegate.rb +2 -0
- data/lib/sugarcube/uiview.rb +14 -4
- data/lib/sugarcube/version.rb +1 -1
- data/spec/uiview_animation_chain_spec.rb +13 -2
- metadata +1 -1
data/README.md
CHANGED
|
@@ -774,20 +774,29 @@ view.slide(:left, 20) {
|
|
|
774
774
|
}
|
|
775
775
|
```
|
|
776
776
|
|
|
777
|
-
|
|
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,
|
|
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(:
|
|
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
data/lib/sugarcube/uiview.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/sugarcube/version.rb
CHANGED
|
@@ -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.
|
|
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.
|
|
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
|